Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/puppet/parser/functions/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ module Puppet::Parser::Functions

type = '..' # Use the simplest type of Range available in Ruby

else # arguments.size == 0
else # arguments.size == 1
value = arguments[0]

if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
start = m[1]
stop = m[3]

type = m[2]

step = 1
elsif value.match(/^.+$/)
raise(Puppet::ParseError, "range(): Unable to compute range " +
"from the value: #{value}")
Expand All @@ -78,7 +78,7 @@ module Puppet::Parser::Functions
when '...' then (start ... stop) # Exclusive of last element
end

result = range.step(step).collect { |i| i }
result = range.step(step).to_a

return result
end
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 @@ -68,6 +68,13 @@
end
end

describe 'with a ruby-like range' do
it "returns a number range" do
result = scope.function_range(["1..4"])
expect(result).to eq [1,2,3,4]
end
end

describe 'with a numeric range' do
it "returns a range of numbers" do
expected = (1..10).to_a
Expand Down