Skip to content

Commit

Permalink
Merge pull request #448 from DavidS/fix_range
Browse files Browse the repository at this point in the history
range(): fix TypeError(can't convert nil into Integer) when using range ...
  • Loading branch information
tphoney committed May 6, 2015
2 parents cf25130 + f49eb6b commit 4f6c6fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit 4f6c6fa

Please sign in to comment.