]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Make the range function work with integers
authorErik Dalén <dalen@spotify.com>
Wed, 12 Nov 2014 15:02:05 +0000 (16:02 +0100)
committerErik Dalén <dalen@spotify.com>
Wed, 12 Nov 2014 15:02:05 +0000 (16:02 +0100)
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').

lib/puppet/parser/functions/range.rb
spec/functions/range_spec.rb

index 06d75d408e9c035be0cc18997362512b5d8575c9..49fba21c803545f10143425c106aa7206f8c0a26 100644 (file)
@@ -66,7 +66,7 @@ Will return: [0,2,4,6,8]
     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
index 9b9ece024f4b3908b1d1bd5eb03908db385d3aad..1446b245cd5f6f9497ac52e18f86227d7c237039 100755 (executable)
@@ -67,4 +67,11 @@ describe "the range function" do
       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