spec/regexp-examples_spec.rb in regexp-examples-0.3.1 vs spec/regexp-examples_spec.rb in regexp-examples-0.3.2

- old
+ new

@@ -27,10 +27,18 @@ expect{regexp.examples}.to raise_error RegexpExamples::UnsupportedSyntaxError end end end + def self.examples_are_empty(*regexps) + regexps.each do |regexp| + it do + expect(regexp.examples).to be_empty + end + end + end + context 'returns matching strings' do context "for basic repeaters" do examples_exist_and_match( /a/, /a*/, @@ -52,10 +60,11 @@ ) end context "for complex char groups (square brackets)" do examples_exist_and_match( + /[abc]/, /[a-c]/, /[abc-e]/, /[^a-zA-Z]/, /[\w]/, @@ -63,11 +72,12 @@ /[\]]/, /[\\]/, /[\\\]]/, /[\n-\r]/, /[\-]/, - /[%-+]/ # This regex is "supposed to" match some surprising things!!! + /[%-+]/, # This regex is "supposed to" match some surprising things!!! + /['-.]/ # Test to ensure no "infinite loop" on character set expansion ) end context "for complex multi groups" do examples_exist_and_match( @@ -116,11 +126,12 @@ /(I(N(C(E(P(T(I(O(N)))))))))*/, /[\w]{1}/, /((a?b*c+)) \1/, /((a?b*c+)?) \1/, /a|b|c|d/, - /a+|b*|c?/ + /a+|b*|c?/, + /one|two|three/ ) end context "for illegal syntax" do examples_raise_illegal_syntax_error( @@ -184,9 +195,24 @@ context "for unicode sequences" do examples_exist_and_match( /\u6829/, /\uabcd/, /\u{42}word/ + ) + end + + context "for empty character sets" do + examples_are_empty( + /[^\d\D]/, + /[^\w\W]/, + /[^\s\S]/, + /[^\h\H]/, + /[^\D0-9]/, + /[^\Wa-zA-Z0-9_]/, + /[^\d\D]*/, + /[^\d\D]+/, + /[^\d\D]{2}/, + /[^\d\D]word/ ) end end end