4 describe "the values_at function" do
6 Puppet::Parser::Functions.autoloader.loadall
10 @scope = Puppet::Parser::Scope.new
14 Puppet::Parser::Functions.function("values_at").should == "function_values_at"
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))
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))
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']))
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']))
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']))
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']))