From e80207bede37e498c32bea6d56c46f1dd709721e Mon Sep 17 00:00:00 2001 From: Uwe Stuehler Date: Tue, 23 Oct 2012 16:43:03 +0200 Subject: Fix number of arguments check in flatten() The function only uses the first argument, so raise an error with too few arguments *and* with too many arguments. --- spec/unit/puppet/parser/functions/flatten_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb index d4dfd20..dba7a6b 100755 --- a/spec/unit/puppet/parser/functions/flatten_spec.rb +++ b/spec/unit/puppet/parser/functions/flatten_spec.rb @@ -11,6 +11,10 @@ describe "the flatten function" do lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) end + it "should raise a ParseError if there is more than 1 argument" do + lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError)) + end + it "should flatten a complex data structure" do result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) result.should(eq(["a","b","c","d","e","f","g"])) -- cgit v1.2.3 From 5a11279cc54e7f9f5d168c75728f990d0bd0b694 Mon Sep 17 00:00:00 2001 From: Uwe Stuehler Date: Tue, 23 Oct 2012 16:43:03 +0200 Subject: Fix number of arguments check in flatten() The function only uses the first argument, so raise an error with too few arguments *and* with too many arguments. --- spec/unit/puppet/parser/functions/flatten_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb index d4dfd20..dba7a6b 100755 --- a/spec/unit/puppet/parser/functions/flatten_spec.rb +++ b/spec/unit/puppet/parser/functions/flatten_spec.rb @@ -11,6 +11,10 @@ describe "the flatten function" do lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) end + it "should raise a ParseError if there is more than 1 argument" do + lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError)) + end + it "should flatten a complex data structure" do result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) result.should(eq(["a","b","c","d","e","f","g"])) -- cgit v1.2.3 From 5d5a4d466ed6530fa8b68162e96bdaaaf35066e1 Mon Sep 17 00:00:00 2001 From: Justin Lambert Date: Mon, 17 Dec 2012 06:22:36 -0700 Subject: str2bool should return a boolean if called with a boolean --- spec/unit/puppet/parser/functions/str2bool_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb index 2782bbe..ef6350f 100644 --- a/spec/unit/puppet/parser/functions/str2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/str2bool_spec.rb @@ -21,4 +21,11 @@ describe "the str2bool function" do result = scope.function_str2bool(["undef"]) result.should(eq(false)) end + + it "should return the boolean it was called with" do + result = scope.function_str2bool([true]) + result.should(eq(true)) + result = scope.function_str2bool([false]) + result.should(eq(false)) + end end -- cgit v1.2.3 From 961dcab15d3cf00eabeb5a496efc9da051169241 Mon Sep 17 00:00:00 2001 From: Eric Shamow Date: Tue, 3 Apr 2012 22:30:46 -0400 Subject: (#13610) Add is_function_available to stdlib This function provides a simple wrapper around Puppet::Parser::Functions.function for access within Puppet manifests. This will allow users to check whether or not a plugin or functionality such as hiera is installed on the server. --- .../parser/functions/is_function_available.rb | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/is_function_available.rb (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/is_function_available.rb b/spec/unit/puppet/parser/functions/is_function_available.rb new file mode 100644 index 0000000..bd40c51 --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_function_available.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_function_available function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return false if a nonexistent function is passed" do + result = @scope.function_is_function_available(['jeff_mccunes_left_sock']) + result.should(eq(false)) + end + + it "should return true if an available function is passed" do + result = @scope.function_is_function_available(['require']) + result.should(eq(true)) + end + +end -- cgit v1.2.3 From 05273419e1c8b34115ede15b1d8a8739f6a0db00 Mon Sep 17 00:00:00 2001 From: Kristof Willaert Date: Tue, 19 Mar 2013 10:00:57 +0100 Subject: Add floor function implementation and unit tests --- spec/unit/puppet/parser/functions/floor_spec.rb | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/floor_spec.rb (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/floor_spec.rb b/spec/unit/puppet/parser/functions/floor_spec.rb new file mode 100644 index 0000000..dbc8c77 --- /dev/null +++ b/spec/unit/puppet/parser/functions/floor_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the floor function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("floor").should == "function_floor" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/)) + end + + it "should should raise a ParseError if input isn't numeric (eg. String)" do + lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) + end + + it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do + lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) + end + + it "should return an integer when a numeric type is passed" do + result = scope.function_floor([12.4]) + result.is_a?(Integer).should(eq(true)) + end + + it "should return the input when an integer is passed" do + result = scope.function_floor([7]) + result.should(eq(7)) + end + + it "should return the largest integer less than or equal to the input" do + result = scope.function_floor([3.8]) + result.should(eq(3)) + end +end + -- cgit v1.2.3 From 88a93ac6cdf38045e1cf29325a70e5e4143016b3 Mon Sep 17 00:00:00 2001 From: Richard Soderberg Date: Tue, 26 Mar 2013 15:45:40 -0700 Subject: add suffix function to accompany the prefix function --- spec/unit/puppet/parser/functions/suffix_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/suffix_spec.rb (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb new file mode 100644 index 0000000..c28f719 --- /dev/null +++ b/spec/unit/puppet/parser/functions/suffix_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the suffix function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("suffix").should == "function_suffix" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a suffixed array" do + result = scope.function_suffix([['a','b','c'], 'p']) + result.should(eq(['ap','bp','cp'])) + end +end -- cgit v1.2.3 From ff5dd5d75adb3723e106ca20bac4e68466395a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 20 Mar 2013 16:36:20 +0100 Subject: Allow comparisons of Numeric and number as String Puppet passes numbers as String to functions, but it makes more sense to compare them as Numeric. But sometimes Puppet passes them as the wrong type, see: https://projects.puppetlabs.com/issues/19812 --- spec/unit/puppet/parser/functions/max_spec.rb | 4 ++++ spec/unit/puppet/parser/functions/min_spec.rb | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/max_spec.rb b/spec/unit/puppet/parser/functions/max_spec.rb index 604927e..ff6f2b3 100755 --- a/spec/unit/puppet/parser/functions/max_spec.rb +++ b/spec/unit/puppet/parser/functions/max_spec.rb @@ -20,4 +20,8 @@ describe "the max function" do it "should be able to compare numbers" do scope.function_max([6,8,4]).should(eq(8)) end + + it "should be able to compare a number with a stringified number" do + scope.function_max([1,"2"]).should(eq("2")) + end end diff --git a/spec/unit/puppet/parser/functions/min_spec.rb b/spec/unit/puppet/parser/functions/min_spec.rb index 781422c..71d593e 100755 --- a/spec/unit/puppet/parser/functions/min_spec.rb +++ b/spec/unit/puppet/parser/functions/min_spec.rb @@ -20,4 +20,8 @@ describe "the min function" do it "should be able to compare numbers" do scope.function_min([6,8,4]).should(eq(4)) end + + it "should be able to compare a number with a stringified number" do + scope.function_min([1,"2"]).should(eq(1)) + end end -- cgit v1.2.3 From e6916f83fd35989db4b86dfb10716c9198994389 Mon Sep 17 00:00:00 2001 From: Steve Huff Date: Fri, 29 Mar 2013 10:04:05 -0400 Subject: Enable num2bool to accept numeric input Also ignore rspec fixtures directory --- spec/unit/puppet/parser/functions/num2bool_spec.rb | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb index 640c689..e51ee45 100644 --- a/spec/unit/puppet/parser/functions/num2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -12,13 +12,33 @@ describe "the num2bool function" do lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) end - it "should return true if 1" do + it "should return true if passed string 1" do result = scope.function_num2bool(["1"]) result.should(be_true) end - it "should return false if 0" do + it "should return true if passed number 1" do + result = scope.function_num2bool([1]) + result.should(be_true) + end + + it "should return false if passed string 0" do result = scope.function_num2bool(["0"]) result.should(be_false) end + + it "should return false if passed number 0" do + result = scope.function_num2bool([0]) + result.should(be_false) + end + + it "should return false if passed string -1" do + result = scope.function_num2bool(["-1"]) + result.should(be_false) + end + + it "should return false if passed number -1" do + result = scope.function_num2bool([-1]) + result.should(be_false) + end end -- cgit v1.2.3 From 4a5218a8af8c3ffaf9ea2348a3900b19d6a95416 Mon Sep 17 00:00:00 2001 From: Steve Huff Date: Fri, 29 Mar 2013 12:03:33 -0400 Subject: Reworked number-handling logic No more coercing to String and regex matching. Instead, we now coerce to Integer at the beginning or raise an error if we cannot coerce to Integer. A consequence of this change is that the function will now accept blatantly non-numeric strings as input, and return false. This seems a bit goofy to me, but it's how String#to_i works. If we really don't like this, then I'm open to suggestions. --- spec/unit/puppet/parser/functions/num2bool_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb index e51ee45..5ce981e 100644 --- a/spec/unit/puppet/parser/functions/num2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -8,10 +8,14 @@ describe "the num2bool function" do Puppet::Parser::Functions.function("num2bool").should == "function_num2bool" end - it "should raise a ParseError if there is less than 1 arguments" do + it "should raise a ParseError if there are no arguments" do lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) end + it "should raise a ParseError if there are more than 1 arguments" do + lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError)) + end + it "should return true if passed string 1" do result = scope.function_num2bool(["1"]) result.should(be_true) @@ -41,4 +45,9 @@ describe "the num2bool function" do result = scope.function_num2bool([-1]) result.should(be_false) end + + it "should return false if passed something non-numeric" do + result = scope.function_num2bool(["xyzzy"]) + result.should(be_false) + end end -- cgit v1.2.3 From 8d217f0012fef332642faf485ad187773a95bcc1 Mon Sep 17 00:00:00 2001 From: Steve Huff Date: Fri, 29 Mar 2013 15:06:36 -0400 Subject: (19864) num2bool match fix This is a bit more heavy-handed than I might like, but it does appear to do the right things: * accepts numeric input appropriately, truncating floats * matches string input against a regex, then coerces number-looking strings to int * makes a best effort to coerce anything else to a string, then subjects it to the same treatment * raises an error in the event of incorrect number of arguments or non-number-looking strings I've also included some additional unit tests. --- spec/unit/puppet/parser/functions/num2bool_spec.rb | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb index 5ce981e..038881f 100644 --- a/spec/unit/puppet/parser/functions/num2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -16,6 +16,10 @@ describe "the num2bool function" do lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError)) end + it "should raise a ParseError if passed something non-numeric" do + lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError)) + end + it "should return true if passed string 1" do result = scope.function_num2bool(["1"]) result.should(be_true) @@ -26,6 +30,16 @@ describe "the num2bool function" do result.should(be_true) end + it "should return true if passed array with string 1" do + result = scope.function_num2bool([["1"]]) + result.should(be_true) + end + + it "should return true if passed array with number 1" do + result = scope.function_num2bool([[1]]) + result.should(be_true) + end + it "should return false if passed string 0" do result = scope.function_num2bool(["0"]) result.should(be_false) @@ -36,6 +50,16 @@ describe "the num2bool function" do result.should(be_false) end + it "should return false if passed array with string 0" do + result = scope.function_num2bool([["0"]]) + result.should(be_false) + end + + it "should return false if passed array with number 0" do + result = scope.function_num2bool([[0]]) + result.should(be_false) + end + it "should return false if passed string -1" do result = scope.function_num2bool(["-1"]) result.should(be_false) @@ -46,8 +70,14 @@ describe "the num2bool function" do result.should(be_false) end - it "should return false if passed something non-numeric" do - result = scope.function_num2bool(["xyzzy"]) + it "should return false if passed array with string -1" do + result = scope.function_num2bool([["-1"]]) result.should(be_false) end + + it "should return false if passed array with number -1" do + result = scope.function_num2bool([[-1]]) + result.should(be_false) + end + end -- cgit v1.2.3 From c372f177708df4c844337e9901646b7b84b86cd8 Mon Sep 17 00:00:00 2001 From: Steve Huff Date: Mon, 1 Apr 2013 11:44:09 -0400 Subject: Cleanup per adrianthebo suggestions * use Float() to process string arguments * get rid of doubly nested arrays * removing needless ternary operator * improving error message handling --- spec/unit/puppet/parser/functions/num2bool_spec.rb | 36 ++++++---------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb index 038881f..b56196d 100644 --- a/spec/unit/puppet/parser/functions/num2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -25,18 +25,13 @@ describe "the num2bool function" do result.should(be_true) end - it "should return true if passed number 1" do - result = scope.function_num2bool([1]) - result.should(be_true) - end - - it "should return true if passed array with string 1" do - result = scope.function_num2bool([["1"]]) + it "should return true if passed string 1.5" do + result = scope.function_num2bool(["1.5"]) result.should(be_true) end - it "should return true if passed array with number 1" do - result = scope.function_num2bool([[1]]) + it "should return true if passed number 1" do + result = scope.function_num2bool([1]) result.should(be_true) end @@ -50,34 +45,23 @@ describe "the num2bool function" do result.should(be_false) end - it "should return false if passed array with string 0" do - result = scope.function_num2bool([["0"]]) - result.should(be_false) - end - - it "should return false if passed array with number 0" do - result = scope.function_num2bool([[0]]) - result.should(be_false) - end - it "should return false if passed string -1" do result = scope.function_num2bool(["-1"]) result.should(be_false) end - it "should return false if passed number -1" do - result = scope.function_num2bool([-1]) + it "should return false if passed string -1.5" do + result = scope.function_num2bool(["-1.5"]) result.should(be_false) end - it "should return false if passed array with string -1" do - result = scope.function_num2bool([["-1"]]) + it "should return false if passed number -1" do + result = scope.function_num2bool([-1]) result.should(be_false) end - it "should return false if passed array with number -1" do - result = scope.function_num2bool([[-1]]) + it "should return false if passed float -1.5" do + result = scope.function_num2bool([-1.5]) result.should(be_false) end - end -- cgit v1.2.3 From 7a2fb80834d3ec4d21efe58e5e8af188e5bdd07c Mon Sep 17 00:00:00 2001 From: Amos Shapira Date: Sun, 31 Mar 2013 23:37:30 +1100 Subject: (#19998) Implement any2array This change is to implement a new function "any2array", which will take any argument or arguments and create an array which contains it. If the argument is a single array then it will be returned as-is. If the argument is a single hash then it will be converted into an array. Otherwise (if there are more than one argument, or the only argument is not an array or a hash) the function will return an array containing all the arguments. --- .../unit/puppet/parser/functions/any2array_spec.rb | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/any2array_spec.rb (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/any2array_spec.rb b/spec/unit/puppet/parser/functions/any2array_spec.rb new file mode 100644 index 0000000..b266e84 --- /dev/null +++ b/spec/unit/puppet/parser/functions/any2array_spec.rb @@ -0,0 +1,55 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the any2array function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("any2array").should == "function_any2array" + end + + it "should return an empty array if there is less than 1 argument" do + result = scope.function_any2array([]) + result.should(eq([])) + end + + it "should convert boolean true to [ true ] " do + result = scope.function_any2array([true]) + result.should(eq([true])) + end + + it "should convert one object to [object]" do + result = scope.function_any2array(['one']) + result.should(eq(['one'])) + end + + it "should convert multiple objects to [objects]" do + result = scope.function_any2array(['one', 'two']) + result.should(eq(['one', 'two'])) + end + + it "should return empty array it was called with" do + result = scope.function_any2array([[]]) + result.should(eq([])) + end + + it "should return one-member array it was called with" do + result = scope.function_any2array([['string']]) + result.should(eq(['string'])) + end + + it "should return multi-member array it was called with" do + result = scope.function_any2array([['one', 'two']]) + result.should(eq(['one', 'two'])) + end + + it "should return members of a hash it was called with" do + result = scope.function_any2array([{ 'key' => 'value' }]) + result.should(eq(['key', 'value'])) + end + + it "should return an empty array if it was called with an empty hash" do + result = scope.function_any2array([{ }]) + result.should(eq([])) + end +end -- cgit v1.2.3 From f28550e78996f908b076cdc9aebcbe584c777cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 10 Apr 2013 14:38:14 +0200 Subject: Add a count function Similar to the ruby count method on arrays. --- spec/unit/puppet/parser/functions/count_spec.rb | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/count_spec.rb (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb new file mode 100644 index 0000000..5e4a8b9 --- /dev/null +++ b/spec/unit/puppet/parser/functions/count_spec.rb @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the count function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("count").should == "function_count" + end + + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) + end + + it "should be able to count arrays" do + scope.function_count([["1","2","3"]]).should(eq(3)) + end + + it "should be able to count matching elements in arrays" do + scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) + end + + it "should not count :undef, nil or empty strings" do + scope.function_count([["foo","bar",:undef,nil,""]]).should(eq(2)) + end +end -- cgit v1.2.3 From 435226abfdf001bf2475be56d77027c638e93b70 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Wed, 10 Apr 2013 14:33:08 -0700 Subject: (maint) Add the behavior for count() with arrays and hashes Without this patch the expected behavior of the count() function when dealing with an out of bound array index and with a hash key that does not exist is implicitly encoded in the spec examples. This is a problem because the expected behavior is not clear for something similar to the following example: node default { $ary = [ 1, 2, 3 ] $ary_undef = $ary[100] $hsh = { 'one' => 1 } $hsh_undef = $hsh['dne'] $count = count(['hi', $ary_undef, $hsh_undef]) notice "Count is ${count}" } This patch addresses the problem by making the expected behavior explicit in the examples. --- spec/unit/puppet/parser/functions/count_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet/parser/functions') diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb index 5e4a8b9..2453815 100644 --- a/spec/unit/puppet/parser/functions/count_spec.rb +++ b/spec/unit/puppet/parser/functions/count_spec.rb @@ -21,7 +21,11 @@ describe "the count function" do scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) end - it "should not count :undef, nil or empty strings" do - scope.function_count([["foo","bar",:undef,nil,""]]).should(eq(2)) + it "should not count nil or empty strings" do + scope.function_count([["foo","bar",nil,""]]).should(eq(2)) + end + + it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do + expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) end end -- cgit v1.2.3