]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#2) fix is_string finally so it also makes sure numbers return false.
authorKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 19:11:47 +0000 (20:11 +0100)
committerKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 19:11:47 +0000 (20:11 +0100)
lib/puppet/parser/functions/is_string.rb
spec/unit/parser/functions/is_string_spec.rb

index 61037e30e6e2c041b813f6f02325b1464592b6a9..8a02a1003e4c957ad3378624c84a529bf2b145b3 100644 (file)
@@ -14,6 +14,10 @@ module Puppet::Parser::Functions
 
     result = type.is_a?(String)
 
+    if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
+      return false
+    end
+
     return result
   end
 end
index 8c0061ea129cfa0ee7e8771d4784e754fcc0d3bd..4f3f5fd2448d8b0a3f1762b230a74085aa21ef32 100644 (file)
@@ -18,4 +18,24 @@ describe "the is_string function" do
     lambda { @scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
   end
 
+  it "should return true if a string" do
+    result = @scope.function_is_string(["asdf"])
+    result.should(eq(true))
+  end
+
+  it "should return false if an integer" do
+    result = @scope.function_is_string(["3"])
+    result.should(eq(false))
+  end
+
+  it "should return false if a float" do
+    result = @scope.function_is_string(["3.23"])
+    result.should(eq(false))
+  end
+
+  it "should return false if an array" do
+    result = @scope.function_is_string([["a","b","c"]])
+    result.should(eq(false))
+  end
+
 end