File tree Expand file tree Collapse file tree 2 files changed +29
-13
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -65,21 +65,21 @@ module Puppet::Parser::Functions
6565 end
6666 end
6767
68- # Check whether we have integer value if so then make it so ...
69- if start . match ( /^\d +$/ )
70- start = start . to_i
71- stop = stop . to_i
72- else
73- start = start . to_s
74- stop = stop . to_s
75- end
68+ # Check whether we have integer value if so then make it so ...
69+ if start . to_s . match ( /^\d +$/ )
70+ start = start . to_i
71+ stop = stop . to_i
72+ else
73+ start = start . to_s
74+ stop = stop . to_s
75+ end
7676
77- range = case type
78- when /^(\. \. |\- )$/ then ( start .. stop )
79- when /^(\. \. \. )$/ then ( start ... stop ) # Exclusive of last element ...
80- end
77+ range = case type
78+ when /^(\. \. |\- )$/ then ( start .. stop )
79+ when /^(\. \. \. )$/ then ( start ... stop ) # Exclusive of last element ...
80+ end
8181
82- result = range . step ( step ) . collect { |i | i } # Get them all ... Pokemon ...
82+ result = range . step ( step ) . collect { |i | i } # Get them all ... Pokemon ...
8383
8484 return result
8585 end
Original file line number Diff line number Diff line change 6767 expect ( scope . function_range ( [ "00" , "10" ] ) ) . to eq expected
6868 end
6969 end
70+
71+ describe 'with a numeric range' do
72+ it "returns a range of numbers" do
73+ expected = ( 1 ..10 ) . to_a
74+ expect ( scope . function_range ( [ 1 , 10 ] ) ) . to eq expected
75+ end
76+ it "returns a range of numbers with step parameter" do
77+ expected = ( 1 ..10 ) . step ( 2 ) . to_a
78+ expect ( scope . function_range ( [ 1 , 10 , 2 ] ) ) . to eq expected
79+ end
80+ it "works with mixed numeric like strings and numeric arguments" do
81+ expected = ( 1 ..10 ) . to_a
82+ expect ( scope . function_range ( [ '1' , 10 ] ) ) . to eq expected
83+ expect ( scope . function_range ( [ 1 , '10' ] ) ) . to eq expected
84+ end
85+ end
7086end
You can’t perform that action at this time.
0 commit comments