summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Barber <ken@bob.sh>2011-07-29 20:11:47 +0100
committerKen Barber <ken@bob.sh>2011-07-29 20:11:47 +0100
commit18e5302614bce168ac07e35dc23b058064e9e41c (patch)
treeb45471bdb3846efa835ed394dd1e891620b86e54
parent56a402e6542105ec63c5071e685d5af93fd4d0f3 (diff)
(#2) fix is_string finally so it also makes sure numbers return false.
-rw-r--r--lib/puppet/parser/functions/is_string.rb4
-rw-r--r--spec/unit/parser/functions/is_string_spec.rb20
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb
index 61037e3..8a02a10 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -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
diff --git a/spec/unit/parser/functions/is_string_spec.rb b/spec/unit/parser/functions/is_string_spec.rb
index 8c0061e..4f3f5fd 100644
--- a/spec/unit/parser/functions/is_string_spec.rb
+++ b/spec/unit/parser/functions/is_string_spec.rb
@@ -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