]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#2) unstub is_numeric function.
authorKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 20:03:33 +0000 (21:03 +0100)
committerKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 20:03:33 +0000 (21:03 +0100)
lib/puppet/parser/functions/is_numeric.rb
spec/unit/parser/functions/is_numeric_spec.rb

index 96e867469b35b07b0631f60f0c4fc46b3acfa46e..c2c0fb51f2b4ff9e293f9ec6860be6130e016ece 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 or value == value.to_i.to_s then
+      return true
+    else
+      return false
+    end
+
   end
 end
 
index 3a49f5d81cd474889a22852fe5c188773b581692..2191b7bd086f770f088bcf9fcee48c8e8e1c3d22 100644 (file)
@@ -14,8 +14,23 @@ describe "the is_numeric function" do
     Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
   end
 
-  it "should raise a ParseError if there is less than 1 arguments" do
+  it "should raise a ParseError if there is less than 1 argument" do
     lambda { @scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
   end
 
+  it "should return true if an integer" do
+    result = @scope.function_is_numeric(["3"])
+    result.should(eq(true))
+  end
+
+  it "should return true if a float" do
+    result = @scope.function_is_numeric(["3.2"])
+    result.should(eq(true))
+  end
+
+  it "should return false if a string" do
+    result = @scope.function_is_numeric(["asdf"])
+    result.should(eq(false))
+  end
+
 end