lib/regexp-examples/repeaters.rb in regexp-examples-0.3.1 vs lib/regexp-examples/repeaters.rb in regexp-examples-0.3.2

- old
+ new

@@ -31,21 +31,21 @@ def initialize(group) super end def result - super(0, TIMES) + super(0, MaxRepeaterVariance) end end class PlusRepeater < BaseRepeater def initialize(group) super end def result - super(1, TIMES) + super(1, MaxRepeaterVariance + 1) end end class QuestionMarkRepeater < BaseRepeater def initialize(group) @@ -60,19 +60,25 @@ class RangeRepeater < BaseRepeater def initialize(group, min, has_comma, max) super(group) @min = min || 0 if max - @max = max + # Prevent huge number of results in case of e.g. /.{1,100}/.examples + @max = smallest(max, @min + MaxRepeaterVariance) elsif has_comma - @max = min + TIMES + @max = @min + MaxRepeaterVariance else - @max = min + @max = @min end end def result super(@min, @max) + end + + private + def smallest(x, y) + (x < y) ? x : y end end end