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

- old
+ new

@@ -4,18 +4,22 @@ def initialize(group) @group = group end def result(min_repeats, max_repeats) - group_results = @group.result[0 .. MaxGroupResults-1] + group_results = @group.result[0 .. RegexpExamples.MaxGroupResults-1] results = [] min_repeats.upto(max_repeats) do |repeats| - group_results.each do |group_result| - results << group_result * repeats + if repeats.zero? + results << [ GroupResult.new('') ] + else + results << RegexpExamples.permutations_of_strings( + [group_results] * repeats + ) end end - results.uniq + results.flatten.uniq end end class OneTimeRepeater < BaseRepeater def initialize(group) @@ -31,21 +35,21 @@ def initialize(group) super end def result - super(0, MaxRepeaterVariance) + super(0, RegexpExamples.MaxRepeaterVariance) end end class PlusRepeater < BaseRepeater def initialize(group) super end def result - super(1, MaxRepeaterVariance + 1) + super(1, RegexpExamples.MaxRepeaterVariance + 1) end end class QuestionMarkRepeater < BaseRepeater def initialize(group) @@ -61,12 +65,12 @@ def initialize(group, min, has_comma, max) super(group) @min = min || 0 if max # Prevent huge number of results in case of e.g. /.{1,100}/.examples - @max = smallest(max, @min + MaxRepeaterVariance) + @max = smallest(max, @min + RegexpExamples.MaxRepeaterVariance) elsif has_comma - @max = @min + MaxRepeaterVariance + @max = @min + RegexpExamples.MaxRepeaterVariance else @max = @min end end