spec/regexp-examples_spec.rb in regexp-examples-1.1.4 vs spec/regexp-examples_spec.rb in regexp-examples-1.2.0
- old
+ new
@@ -367,8 +367,43 @@
it { expect(/a(?i:b)c/.examples).to match_array %w(abc aBc) }
it { expect(/a(?i:b(?-i:c))/.examples).to match_array %w(abc aBc) }
it { expect(/a(?-i:b)c/i.examples).to match_array %w(abc abC Abc AbC) }
end
end
+ end # context 'exact examples match'
+ end # context 'returns matching strings'
+
+ context 'max_results_limit config option' do
+ it 'with low limit' do
+ expect(/[A-Z]/.examples(max_results_limit: 5))
+ .to match_array %w(A B C D E)
+ end
+ it 'with (default) high limit' do
+ expect(/[ab]{14}/.examples.length)
+ .to be <= 10000 # NOT 2**14 == 16384, because it's been limited
+ end
+ it 'with (custom) high limit' do
+ expect(/[ab]{14}/.examples(max_results_limit: 20000).length)
+ .to eq 16384 # NOT 10000, because it's below the limit
+ end
+ it 'for boolean or groups' do
+ expect(/[ab]{3}|[cd]{3}/.examples(max_results_limit: 10).length)
+ .to eq 10
+ end
+ it 'for case insensitive examples' do
+ expect(/[ab]{3}/i.examples(max_results_limit: 10).length)
+ .to be <= 10
+ end
+ it 'for range repeaters' do
+ expect(/[ab]{2,3}/.examples(max_results_limit: 10).length)
+ .to be <= 10 # NOT 4 + 8 = 12
+ end
+ it 'for backreferences' do
+ expect(/([ab]{3})\1?/.examples(max_results_limit: 10).length)
+ .to be <= 10 # NOT 8 * 2 = 16
+ end
+ it 'for a complex pattern' do
+ expect(/(a|[bc]{2})\1{1,3}/.examples(max_results_limit: 14).length)
+ .to be <= 14 # NOT (1 + 4) * 3 = 15
end
end
end