-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add named capture to non-capturing group mutation
- Mutate named capture groups to passive groups: `/(?<foo>bar)/` -> `/(?:bar)/`.
- Loading branch information
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
class Mutator | ||
class Node | ||
module Regexp | ||
# Mutator for regexp named capture groups, such as `/(?<foo>bar)/` | ||
class NamedGroup < Node | ||
handle(:regexp_named_group) | ||
|
||
children :name, :group | ||
|
||
private | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ | |
singleton_mutations | ||
mutation '//' | ||
mutation '/nomatch\A/' | ||
mutation '/(?:.)/' | ||
end | ||
|
||
Pathname | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
Mutant::Meta::Example.add :regexp_named_group do | ||
source '/(?<foo>)/' | ||
|
||
singleton_mutations | ||
regexp_mutations | ||
end | ||
|
||
Mutant::Meta::Example.add :regexp_named_group do | ||
source '/(?<foo>\w)/' | ||
|
||
singleton_mutations | ||
regexp_mutations | ||
|
||
mutation '/(?:\w)/' | ||
mutation '/(?<foo>\W)/' | ||
end |