From 18e5302614bce168ac07e35dc23b058064e9e41c Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 20:11:47 +0100 Subject: (#2) fix is_string finally so it also makes sure numbers return false. --- lib/puppet/parser/functions/is_string.rb | 4 ++++ spec/unit/parser/functions/is_string_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) 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 -- cgit v1.2.3