spec/regexp-examples_spec.rb in regexp-examples-0.4.1 vs spec/regexp-examples_spec.rb in regexp-examples-0.4.2

- old
+ new

@@ -38,20 +38,32 @@ end context 'returns matching strings' do context "for basic repeaters" do examples_exist_and_match( - /a/, - /a*/, - /a*?/, + /a/, # "one-time repeater" + /a*/, # greedy + /a*?/, # reluctant (non-greedy) + /a*+/, # possesive /a+/, /a+?/, + /a*+/, /a?/, + /a??/, + /a?+/, /a{1}/, + /a{1}?/, + /a{1}+/, /a{1,}/, + /a{1,}?/, + /a{1,}+/, /a{,2}/, - /a{1,2}/ + /a{,2}?/, + /a{,2}+/, + /a{1,2}/, + /a{1,2}?/, + /a{1,2}+/ ) end context "for basic groups" do examples_exist_and_match( @@ -117,11 +129,12 @@ /((ref2)ref1) \1 \2/, /((ref1and2)) \1 \2/, /(one)(two)(three)(four)(five)(six)(seven)(eight)(nine)(ten) \10\9\8\7\6\5\4\3\2\1/, /(a?(b?(c?(d?(e?)))))/, /(a)? \1/, - /(a|(b)) \2/ + /(a|(b)) \2/, + /([ab]){2} \1/ # \1 should always be the LAST result of the capture group ) end context "for complex patterns" do # Longer combinations of the above @@ -219,12 +232,16 @@ end context "exact examples match" do # More rigorous tests to assert that ALL examples are being listed context "default options" do + # Simple examples it { expect(/[ab]{2}/.examples).to eq ["aa", "ab", "ba", "bb"] } it { expect(/(a|b){2}/.examples).to eq ["aa", "ab", "ba", "bb"] } it { expect(/a+|b?/.examples).to eq ["a", "aa", "aaa", "", "b"] } + + # a{1}? should be equivalent to (?:a{1})?, i.e. NOT a "non-greedy quantifier" + it { expect(/a{1}?/.examples).to eq ["", "a"] } end context "max_repeater_variance option" do it do expect(/a+/.examples(max_repeater_variance: 5)) .to eq %w(a aa aaa aaaa aaaaa aaaaaa)