Skip to content

Commit

Permalink
Fix capture group mutations
Browse files Browse the repository at this point in the history
- Fix incomplete mutations for regexp capture groups. As an example, `/(\w\d)/` now gets mutated to `/(\W\d)/` and `/(\w\D)/` instead of just the former case.
- Likewise, fix capture group -> passive group mutations which would not get properly generated in many cases. As an example, `/(\w\d)/` would get mutated to `/(?:\w)/` instead of `/(?:\w\d)/` like it will now.
- Closely related to #1328
  • Loading branch information
dgollahon committed May 2, 2022
1 parent 0ab8766 commit 45b7964
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Unreleased

* [#1332](https://github.com/mbj/mutant/pull/1332)

Fix incomplete mutations for regexp capture groups. As an example, `/(\w\d)/` now gets mutated to `/(\W\d)/` and `/(\w\D)/` instead of just the former case.

Fix capture group -> passive group mutations which would not get properly generated in many cases. As an example, `/(\w\d)/` would get mutated to `/(?:\w)/` instead of `/(?:\w\d)/` like it will now.

# v0.11.10 2022-05-02

* [#1328](https://github.com/mbj/mutant/pull/1328)
Expand Down
8 changes: 3 additions & 5 deletions lib/mutant/mutator/node/regexp/capture_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ module Regexp
class CaptureGroup < Node
handle(:regexp_capture_group)

children :group

private

def dispatch
return unless group
return if children.empty?

emit(s(:regexp_passive_group, group))
emit_group_mutations
emit(s(:regexp_passive_group, *children))
children.each_index(&method(:mutate_child))
end
end # EndOfLineAnchor
end # Regexp
Expand Down
11 changes: 11 additions & 0 deletions meta/regexp/regexp_capture_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@
mutation '/(foo)/'
mutation '/(bar)/'
end

Mutant::Meta::Example.add :regexp_capture_group do
source '/(\w\d)/'

singleton_mutations
regexp_mutations

mutation '/(?:\w\d)/'
mutation '/(\W\d)/'
mutation '/(\w\D)/'
end

0 comments on commit 45b7964

Please sign in to comment.