]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#2) - Added is_float and is_integer functionality.
authorKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 14:38:19 +0000 (15:38 +0100)
committerKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 14:38:19 +0000 (15:38 +0100)
lib/puppet/parser/functions/is_float.rb
lib/puppet/parser/functions/is_integer.rb
spec/unit/parser/functions/is_float_spec.rb
spec/unit/parser/functions/is_integer_spec.rb

index 39d097f8e8f94c9e3fe51a7ac245558c08e05a8e..8aed8487ea507eee2bf2b9ce215e957d3dbc5a33 100644 (file)
@@ -12,6 +12,14 @@ module Puppet::Parser::Functions
         "given #{arguments.size} for 1")
     end
 
+    value = arguments[0]
+
+    if value != value.to_f.to_s then
+      return false
+    else
+      return true
+    end
+
   end
 end
 
index 9813cf19aac6a762d4ffa1ac9f97383fafec9991..9dd1ceee3c42c018199d1847d4e546063e23f87b 100644 (file)
@@ -12,6 +12,14 @@ module Puppet::Parser::Functions
         "given #{arguments.size} for 1")
     end
 
+    value = arguments[0]
+
+    if value != value.to_i.to_s then
+      return false
+    else
+      return true
+    end
+
   end
 end
 
index 3d5801755a522fd5140c9be9eb49c6a37c2bf0ae..35c0dd6af836d6557403a4020bb00a4c8e43d908 100644 (file)
@@ -19,7 +19,7 @@ describe "the is_float function" do
   end
 
   it "should return true if a float" do
-    result = @scope.function_is_float([0.12])
+    result = @scope.function_is_float(["0.12"])
     result.should(eq(true))
   end
 
@@ -29,7 +29,7 @@ describe "the is_float function" do
   end
 
   it "should return false if not an integer" do
-    result = @scope.function_is_float([3])
+    result = @scope.function_is_float(["3"])
     result.should(eq(false))
   end
 
index 596bd33082ced834113240ade711530005fa6445..faf6f2d5680f175b2720784c4d2478a771597a3b 100644 (file)
@@ -19,12 +19,12 @@ describe "the is_integer function" do
   end
 
   it "should return true if an integer" do
-    result = @scope.function_is_integer([3])
+    result = @scope.function_is_integer(["3"])
     result.should(eq(true))
   end
 
   it "should return false if a float" do
-    result = @scope.function_is_integer([3.2])
+    result = @scope.function_is_integer(["3.2"])
     result.should(eq(false))
   end