diff options
author | Steve Huff <shuff@vecna.org> | 2013-03-29 12:03:33 -0400 |
---|---|---|
committer | Steve Huff <shuff@vecna.org> | 2013-03-29 12:54:37 -0400 |
commit | 4a5218a8af8c3ffaf9ea2348a3900b19d6a95416 (patch) | |
tree | a3d965b79112bfc025258831afb2467ecbb1c9bd /spec/unit/puppet/parser | |
parent | e6916f83fd35989db4b86dfb10716c9198994389 (diff) | |
download | puppet-stdlib-4a5218a8af8c3ffaf9ea2348a3900b19d6a95416.tar.gz puppet-stdlib-4a5218a8af8c3ffaf9ea2348a3900b19d6a95416.tar.bz2 |
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.
Diffstat (limited to 'spec/unit/puppet/parser')
-rw-r--r-- | spec/unit/puppet/parser/functions/num2bool_spec.rb | 11 |
1 files changed, 10 insertions, 1 deletions
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 |