From a55930368afe2e8177608472653c4696eccec92f Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 15:38:19 +0100 Subject: (#2) - Added is_float and is_integer functionality. --- lib/puppet/parser/functions/is_float.rb | 8 ++++++++ lib/puppet/parser/functions/is_integer.rb | 8 ++++++++ spec/unit/parser/functions/is_float_spec.rb | 4 ++-- spec/unit/parser/functions/is_integer_spec.rb | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb index 39d097f..8aed848 100644 --- a/lib/puppet/parser/functions/is_float.rb +++ b/lib/puppet/parser/functions/is_float.rb @@ -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 diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb index 9813cf1..9dd1cee 100644 --- a/lib/puppet/parser/functions/is_integer.rb +++ b/lib/puppet/parser/functions/is_integer.rb @@ -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 diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb index 3d58017..35c0dd6 100644 --- a/spec/unit/parser/functions/is_float_spec.rb +++ b/spec/unit/parser/functions/is_float_spec.rb @@ -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 diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/parser/functions/is_integer_spec.rb index 596bd33..faf6f2d 100644 --- a/spec/unit/parser/functions/is_integer_spec.rb +++ b/spec/unit/parser/functions/is_integer_spec.rb @@ -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 -- cgit v1.2.3