]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / modules / stdlib / spec / unit / puppet / parser / functions / values_at_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe "the values_at function" do
5   before :all do
6     Puppet::Parser::Functions.autoloader.loadall
7   end
8
9   before :each do
10     @scope = Puppet::Parser::Scope.new
11   end
12
13   it "should exist" do
14     Puppet::Parser::Functions.function("values_at").should == "function_values_at"
15   end
16
17   it "should raise a ParseError if there is less than 1 arguments" do
18     lambda { @scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
19   end
20
21   it "should raise a ParseError if you try to use a range where stop is greater then start" do
22     lambda { @scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
23   end
24
25   it "should return a value at from an array" do
26     result = @scope.function_values_at([['a','b','c'],"1"])
27     result.should(eq(['b']))
28   end
29
30   it "should return a value at from an array when passed a range" do
31     result = @scope.function_values_at([['a','b','c'],"0-1"])
32     result.should(eq(['a','b']))
33   end
34
35   it "should return chosen values from an array when passed number of indexes" do
36     result = @scope.function_values_at([['a','b','c'],["0","2"]])
37     result.should(eq(['a','c']))
38   end
39
40   it "should return chosen values from an array when passed ranges and multiple indexes" do
41     result = @scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
42     result.should(eq(['a','c','e','f']))
43   end
44
45 end