From 190b9438c58eab2322bdf216be1aaae109d14072 Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 3 Jan 2013 13:53:03 +0000 Subject: Add test/validation for is_numeric if created from an arithmetical operation --- lib/puppet/parser/functions/is_numeric.rb | 2 +- spec/unit/puppet/parser/functions/is_numeric_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb index ce13ece..abf0321 100644 --- a/lib/puppet/parser/functions/is_numeric.rb +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -15,7 +15,7 @@ Returns true if the variable passed to this function is a number. value = arguments[0] - if value == value.to_f.to_s or value == value.to_i.to_s then + if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then return true else return false diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb index 4078b37..d7440fb 100644 --- a/spec/unit/puppet/parser/functions/is_numeric_spec.rb +++ b/spec/unit/puppet/parser/functions/is_numeric_spec.rb @@ -22,6 +22,16 @@ describe "the is_numeric function" do result.should(eq(true)) end + it "should return true if an integer is created from an arithmetical operation" do + result = scope.function_is_numeric([3*2]) + result.should(eq(true)) + end + + it "should return true if a float is created from an arithmetical operation" do + result = scope.function_is_numeric([3.2*2]) + result.should(eq(true)) + end + it "should return false if a string" do result = scope.function_is_numeric(["asdf"]) result.should(eq(false)) -- cgit v1.2.3