Skip to content

Commit a559303

Browse files
committed
(puppetlabs#2) - Added is_float and is_integer functionality.
1 parent fde64f3 commit a559303

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

lib/puppet/parser/functions/is_float.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ module Puppet::Parser::Functions
1212
"given #{arguments.size} for 1")
1313
end
1414

15+
value = arguments[0]
16+
17+
if value != value.to_f.to_s then
18+
return false
19+
else
20+
return true
21+
end
22+
1523
end
1624
end
1725

lib/puppet/parser/functions/is_integer.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ module Puppet::Parser::Functions
1212
"given #{arguments.size} for 1")
1313
end
1414

15+
value = arguments[0]
16+
17+
if value != value.to_i.to_s then
18+
return false
19+
else
20+
return true
21+
end
22+
1523
end
1624
end
1725

spec/unit/parser/functions/is_float_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
end
2020

2121
it "should return true if a float" do
22-
result = @scope.function_is_float([0.12])
22+
result = @scope.function_is_float(["0.12"])
2323
result.should(eq(true))
2424
end
2525

@@ -29,7 +29,7 @@
2929
end
3030

3131
it "should return false if not an integer" do
32-
result = @scope.function_is_float([3])
32+
result = @scope.function_is_float(["3"])
3333
result.should(eq(false))
3434
end
3535

spec/unit/parser/functions/is_integer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
end
2020

2121
it "should return true if an integer" do
22-
result = @scope.function_is_integer([3])
22+
result = @scope.function_is_integer(["3"])
2323
result.should(eq(true))
2424
end
2525

2626
it "should return false if a float" do
27-
result = @scope.function_is_integer([3.2])
27+
result = @scope.function_is_integer(["3.2"])
2828
result.should(eq(false))
2929
end
3030

0 commit comments

Comments
 (0)