Add capture group -> non capture group mutation
- Mutates regexps like (foo) to (?:foo).
This commit is contained in:
parent
a45313d2f2
commit
69bf42a51d
6 changed files with 47 additions and 1 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 16
|
||||
total_score: 1306
|
||||
total_score: 1300
|
||||
|
|
|
@ -92,6 +92,7 @@ require 'mutant/mutator/node'
|
|||
require 'mutant/mutator/node/generic'
|
||||
require 'mutant/mutator/node/regexp'
|
||||
require 'mutant/mutator/node/regexp/alternation_meta'
|
||||
require 'mutant/mutator/node/regexp/capture_group'
|
||||
require 'mutant/mutator/node/regexp/character_type'
|
||||
require 'mutant/mutator/node/regexp/end_of_line_anchor'
|
||||
require 'mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor'
|
||||
|
|
|
@ -39,6 +39,7 @@ module Mutant
|
|||
unsupported_regexp_nodes = AST::Types::REGEXP.to_a - %i[
|
||||
regexp_alternation_meta
|
||||
regexp_bol_anchor
|
||||
regexp_capture_group
|
||||
regexp_digit_type
|
||||
regexp_eol_anchor
|
||||
regexp_eos_ob_eol_anchor
|
||||
|
|
26
lib/mutant/mutator/node/regexp/capture_group.rb
Normal file
26
lib/mutant/mutator/node/regexp/capture_group.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
class Node
|
||||
module Regexp
|
||||
# Mutator for regexp capture groups, such as `/(foo)/`
|
||||
class CaptureGroup < Node
|
||||
handle(:regexp_capture_group)
|
||||
|
||||
children :group
|
||||
|
||||
# Emit mutations
|
||||
#
|
||||
# Replace `(captured_group)` with `(?:non_captured_group)`
|
||||
#
|
||||
# @return [undefined]
|
||||
def dispatch
|
||||
return unless group
|
||||
|
||||
emit(s(:regexp_passive_group, group))
|
||||
emit_group_mutations
|
||||
end
|
||||
end # EndOfLineAnchor
|
||||
end # Regexp
|
||||
end # Node
|
||||
end # Mutator
|
||||
end # Mutant
|
|
@ -7,4 +7,5 @@ Mutant::Meta::Example.add :regexp_alternation_meta do
|
|||
mutation '/\A(foo|bar)\z/'
|
||||
mutation '/\A(foo|baz)\z/'
|
||||
mutation '/\A(bar|baz)\z/'
|
||||
mutation '/\A(?:foo|bar|baz)\z/'
|
||||
end
|
||||
|
|
17
meta/regexp/regexp_capture_group.rb
Normal file
17
meta/regexp/regexp_capture_group.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
Mutant::Meta::Example.add :regexp_capture_group do
|
||||
source '/()/'
|
||||
|
||||
singleton_mutations
|
||||
regexp_mutations
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add :regexp_capture_group do
|
||||
source '/(foo|bar)/'
|
||||
|
||||
singleton_mutations
|
||||
regexp_mutations
|
||||
|
||||
mutation '/(?:foo|bar)/'
|
||||
mutation '/(foo)/'
|
||||
mutation '/(bar)/'
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue