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') 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