Skip to content

Commit

Permalink
Make the range function work with integers
Browse files Browse the repository at this point in the history
This is needed for the future parser which actually treats numbers as
numbers and strings as strings. With this patch you can use range(1,5)
instead of having to quote them like range('1','5').
  • Loading branch information
Erik Dalén committed Nov 12, 2014
1 parent e61f402 commit ce995e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Puppet::Parser::Functions
end

# Check whether we have integer value if so then make it so ...
if start.match(/^\d+$/)
if start.to_s.match(/^\d+$/)
start = start.to_i
stop = stop.to_i
else
Expand Down
7 changes: 7 additions & 0 deletions spec/functions/range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@
expect(scope.function_range(["00", "10"])).to eq expected
end
end

describe 'with a numeric range' do
it "returns a range of numbers" do
expected = (1..10).to_a
expect(scope.function_range([1,10])).to eq expected
end
end
end

0 comments on commit ce995e1

Please sign in to comment.