diff --git a/lib/mutant/ast/regexp.rb b/lib/mutant/ast/regexp.rb index ad535afc2..328ab1765 100644 --- a/lib/mutant/ast/regexp.rb +++ b/lib/mutant/ast/regexp.rb @@ -15,7 +15,9 @@ def self.parse(regexp) ::Regexp::Parser.parse(regexp) # `regexp_parser` is more strict than MRI # See: https://github.com/ammar/regexp_parser/issues/75 - rescue ::Regexp::Scanner::PrematureEndError + # Also: https://github.com/ammar/regexp_parser/issues/76 + rescue ::Regexp::Scanner::PrematureEndError, + ::Regexp::Scanner::InvalidGroupOption end # rubocop:enable Lint/SuppressedException diff --git a/meta/regexp.rb b/meta/regexp.rb index 168354f23..31e8fcd7c 100644 --- a/meta/regexp.rb +++ b/meta/regexp.rb @@ -75,7 +75,8 @@ mutation '/(?(1)(foo)(?:bar))/' end -# Case where MRI would accept an expression but regexp_parser not. +# MRI accepts this regex but `regexp_parser` does not. +# See: https://github.com/ammar/regexp_parser/issues/75 Mutant::Meta::Example.add :regexp do source '/\xA/' @@ -84,6 +85,16 @@ mutation '/nomatch\A/' end +# MRI accepts this regex but `regexp_parser` does not. +# See: https://github.com/ammar/regexp_parser/issues/76 +Mutant::Meta::Example.add :regexp do + source '/(?<æ>.)/' + + singleton_mutations + mutation '//' + mutation '/nomatch\A/' +end + Pathname .glob(Pathname.new(__dir__).join('regexp', '*.rb')) .sort diff --git a/spec/unit/mutant/ast/regexp/parse_spec.rb b/spec/unit/mutant/ast/regexp/parse_spec.rb index e79d8bc0b..ed5b1ca66 100644 --- a/spec/unit/mutant/ast/regexp/parse_spec.rb +++ b/spec/unit/mutant/ast/regexp/parse_spec.rb @@ -11,9 +11,15 @@ def apply(input) end end - context 'on regexp regexp_parser does not accept' do + context 'when given a hex escape `regexp_parser` does not support' do it 'returns nil' do expect(apply(/\xA/)).to be(nil) end end + + context 'when given a capture group `regexp_parser` does not support' do + it 'returns nil' do + expect(apply(/(?<æ>.)/)).to be(nil) + end + end end