]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Add test/validation for is_numeric if created from an arithmetical operation
authorstephen <stephen@puppetlabs.com>
Thu, 3 Jan 2013 13:53:03 +0000 (13:53 +0000)
committerJeff McCune <jeff@puppetlabs.com>
Thu, 3 Jan 2013 21:37:55 +0000 (13:37 -0800)
lib/puppet/parser/functions/is_numeric.rb
spec/unit/puppet/parser/functions/is_numeric_spec.rb

index ce13eceaa62493c4e35c565d0c5d4e53d15aab8a..abf03213c67726a314b19c4c32f51cdc7731a23c 100644 (file)
@@ -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
index 4078b37f2d37576b56b50dad8481dd7f48493368..d7440fb0a92be5264ea597c21d9499ad248993a8 100644 (file)
@@ -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))