mutant 0.11.17 → 0.11.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mutant/bootstrap.rb +1 -1
- data/lib/mutant/cli/command/environment/run.rb +1 -1
- data/lib/mutant/mutator/node/literal/regex.rb +8 -8
- data/lib/mutant/mutator/node/send.rb +27 -17
- data/lib/mutant/mutator/regexp.rb +211 -0
- data/lib/mutant/version.rb +1 -1
- data/lib/mutant.rb +1 -18
- metadata +10 -33
- data/lib/mutant/ast/regexp/transformer/direct.rb +0 -145
- data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -50
- data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -68
- data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -92
- data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -56
- data/lib/mutant/ast/regexp/transformer/root.rb +0 -28
- data/lib/mutant/ast/regexp/transformer/text.rb +0 -58
- data/lib/mutant/ast/regexp/transformer.rb +0 -152
- data/lib/mutant/ast/regexp.rb +0 -54
- data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -20
- data/lib/mutant/mutator/node/regexp/beginning_of_line_anchor.rb +0 -20
- data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -23
- data/lib/mutant/mutator/node/regexp/character_type.rb +0 -31
- data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -20
- data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -20
- data/lib/mutant/mutator/node/regexp/named_group.rb +0 -39
- data/lib/mutant/mutator/node/regexp/zero_or_more.rb +0 -34
- data/lib/mutant/mutator/node/regexp.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327c0520e73601c447d4081b428de0111e59627961c82a955e86b2015fef7ce7
|
4
|
+
data.tar.gz: 93dd7338a29a416bce5025d8c95a39cb88cc5e96932435797b60102689726e3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 433b57a38e8b5d68f579d26cb5352cabc222137eb875183364dcd1f39ff8852c8a7f2a95b7ee64a3258ed87f9620670160d8d98df6b0a4513e174ff4b8775a6d
|
7
|
+
data.tar.gz: 84b5b86c80958651592da077cfbd5e965587ce02b05c9b27fc9cf86506a80f963351011cf4ebfe23e084ab211a2f9ea2ac6e89f0efcfeb90cc019a28ab42a0b1
|
data/lib/mutant/bootstrap.rb
CHANGED
@@ -113,7 +113,7 @@ module Mutant
|
|
113
113
|
env.record(__method__) do
|
114
114
|
config = env.config
|
115
115
|
|
116
|
-
scopes = env.world.object_space.each_object(Module).
|
116
|
+
scopes = env.world.object_space.each_object(Module).with_object([]) do |scope, aggregate|
|
117
117
|
expression = expression(config.reporter, config.expression_parser, scope) || next
|
118
118
|
aggregate << Scope.new(scope, expression)
|
119
119
|
end
|
@@ -29,17 +29,17 @@ module Mutant
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def mutate_body
|
32
|
-
|
33
|
-
# Regular expressions with interpolation are skipped.
|
34
|
-
return unless (body_ast = AST::Regexp.expand_regexp_ast(input))
|
32
|
+
string = Regexp.regexp_body(input) or return
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
34
|
+
Regexp
|
35
|
+
.mutate(::Regexp::Parser.parse(string))
|
36
|
+
.each(&method(:emit_regexp_body))
|
40
37
|
end
|
41
38
|
|
42
|
-
|
39
|
+
def emit_regexp_body(expression)
|
40
|
+
emit_type(s(:str, expression.to_str), options)
|
41
|
+
end
|
42
|
+
end # Regexp
|
43
43
|
end # Literal
|
44
44
|
end # Node
|
45
45
|
end # Mutator
|
@@ -50,9 +50,19 @@ module Mutant
|
|
50
50
|
}.freeze
|
51
51
|
}.freeze
|
52
52
|
|
53
|
-
REGEXP_MATCH_METHODS
|
54
|
-
|
55
|
-
|
53
|
+
REGEXP_MATCH_METHODS = %i[=~ match match?].freeze
|
54
|
+
|
55
|
+
REGEXP_START_WITH_NODES =
|
56
|
+
[
|
57
|
+
::Regexp::Expression::Anchor::BeginningOfString,
|
58
|
+
::Regexp::Expression::Literal
|
59
|
+
].freeze
|
60
|
+
|
61
|
+
REGEXP_END_WITH_NODES =
|
62
|
+
[
|
63
|
+
::Regexp::Expression::Literal,
|
64
|
+
::Regexp::Expression::Anchor::EndOfString
|
65
|
+
].freeze
|
56
66
|
|
57
67
|
private
|
58
68
|
|
@@ -114,33 +124,33 @@ module Mutant
|
|
114
124
|
end
|
115
125
|
end
|
116
126
|
|
117
|
-
|
127
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
128
|
+
# rubocop:disable Metrics/MethodLength
|
129
|
+
def emit_start_end_with_mutations
|
118
130
|
return unless REGEXP_MATCH_METHODS.include?(selector) && arguments.one?
|
119
131
|
|
120
132
|
argument = Mutant::Util.one(arguments)
|
121
133
|
|
122
|
-
return unless argument.type.equal?(:regexp)
|
123
|
-
|
124
|
-
)
|
134
|
+
return unless argument.type.equal?(:regexp)
|
135
|
+
|
136
|
+
string = Regexp.regexp_body(argument) or return
|
125
137
|
|
126
|
-
|
138
|
+
expressions = ::Regexp::Parser.parse(string)
|
127
139
|
|
128
|
-
case
|
140
|
+
case expressions.map(&:class)
|
129
141
|
when REGEXP_START_WITH_NODES
|
130
|
-
emit_start_with(
|
142
|
+
emit_start_with(expressions.last.text)
|
131
143
|
when REGEXP_END_WITH_NODES
|
132
|
-
emit_end_with(
|
144
|
+
emit_end_with(expressions.first.text)
|
133
145
|
end
|
134
146
|
end
|
135
147
|
|
136
|
-
def emit_start_with(
|
137
|
-
|
138
|
-
emit_type(receiver, :start_with?, s(:str, literal))
|
148
|
+
def emit_start_with(string)
|
149
|
+
emit_type(receiver, :start_with?, s(:str, string))
|
139
150
|
end
|
140
151
|
|
141
|
-
def emit_end_with(
|
142
|
-
|
143
|
-
emit_type(receiver, :end_with?, s(:str, literal))
|
152
|
+
def emit_end_with(string)
|
153
|
+
emit_type(receiver, :end_with?, s(:str, string))
|
144
154
|
end
|
145
155
|
|
146
156
|
def emit_predicate_mutations
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mutant
|
4
|
+
class Mutator
|
5
|
+
class Regexp < self
|
6
|
+
def self.regexp_body(node)
|
7
|
+
*body, _options = node.children
|
8
|
+
|
9
|
+
body.map do |child|
|
10
|
+
return unless child.type.equal?(:str)
|
11
|
+
child.children
|
12
|
+
end.join
|
13
|
+
end
|
14
|
+
|
15
|
+
class Registry
|
16
|
+
include Concord.new(:contents)
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super({})
|
20
|
+
end
|
21
|
+
|
22
|
+
def register(expression_class, mutator_class)
|
23
|
+
(contents[expression_class] ||= []) << mutator_class
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def lookup(expression_class)
|
28
|
+
contents.fetch(expression_class, []).push(Quantifier)
|
29
|
+
end
|
30
|
+
end # Registry
|
31
|
+
|
32
|
+
REGISTRY = Registry.new
|
33
|
+
|
34
|
+
# mutant:disable - boot time code
|
35
|
+
def self.handle(*types)
|
36
|
+
types.each do |type|
|
37
|
+
self::REGISTRY.register(type, self)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private_class_method :handle
|
42
|
+
|
43
|
+
def self.mutate(expression)
|
44
|
+
REGISTRY
|
45
|
+
.lookup(expression.class)
|
46
|
+
.map { |mutator| mutator.call(input: expression, parent: nil) }
|
47
|
+
.reduce(&:merge)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def subexpressions
|
53
|
+
input.expressions
|
54
|
+
end
|
55
|
+
|
56
|
+
def mk_dup
|
57
|
+
Marshal.load(Marshal.dump(input))
|
58
|
+
end
|
59
|
+
|
60
|
+
def emit_expression(klass:, text:)
|
61
|
+
emit(
|
62
|
+
klass.construct(text: text).tap do |new|
|
63
|
+
subexpressions.each do |expression|
|
64
|
+
new << Marshal.load(Marshal.dump(expression))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def emit_passive_group
|
71
|
+
emit_expression(
|
72
|
+
klass: ::Regexp::Expression::Group::Passive,
|
73
|
+
text: '(?:'
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
class Alternation < self
|
78
|
+
handle(::Regexp::Expression::Alternation)
|
79
|
+
|
80
|
+
def dispatch
|
81
|
+
subexpressions.each_index do |index|
|
82
|
+
emit(mk_dup.tap { |new| new.expressions.delete_at(index) })
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Quantifier < self
|
88
|
+
MAP = {
|
89
|
+
'*' => '+',
|
90
|
+
'*+' => '++',
|
91
|
+
'*?' => '+?'
|
92
|
+
}.freeze
|
93
|
+
|
94
|
+
def dispatch
|
95
|
+
return unless input.quantifier
|
96
|
+
|
97
|
+
emit_removal
|
98
|
+
emit_replacement
|
99
|
+
end
|
100
|
+
|
101
|
+
def emit_removal
|
102
|
+
emit(mk_dup.tap { |new| new.quantifier = nil })
|
103
|
+
end
|
104
|
+
|
105
|
+
def emit_replacement
|
106
|
+
new_text = MAP[input.quantifier.text]
|
107
|
+
|
108
|
+
emit(mk_dup.tap { |new| new.quantifier.text = new_text })
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Replacement < self
|
113
|
+
ns = ::Regexp::Expression
|
114
|
+
|
115
|
+
dual_table =
|
116
|
+
[
|
117
|
+
[ns::Anchor::WordBoundary, '\\b', ns::Anchor::NonWordBoundary, '\\B'],
|
118
|
+
[ns::CharacterType::Digit, '\\d', ns::CharacterType::NonDigit, '\\D'],
|
119
|
+
[ns::CharacterType::ExtendedGrapheme, '\\X', ns::CharacterType::Linebreak, '\\R'],
|
120
|
+
[ns::CharacterType::Hex, '\\h', ns::CharacterType::NonHex, '\\H'],
|
121
|
+
[ns::CharacterType::Space, '\\s', ns::CharacterType::NonSpace, '\\S'],
|
122
|
+
[ns::CharacterType::Word, '\\w', ns::CharacterType::NonWord, '\\W']
|
123
|
+
]
|
124
|
+
|
125
|
+
MAP = dual_table.flat_map do |(left_key, left_text, right_key, right_text)|
|
126
|
+
[
|
127
|
+
[left_key, [right_key, right_text]],
|
128
|
+
[right_key, [left_key, left_text]]
|
129
|
+
]
|
130
|
+
end.to_h
|
131
|
+
|
132
|
+
MAP[ns::Anchor::BeginningOfLine] = [ns::Anchor::BeginningOfString, '\\A']
|
133
|
+
MAP[ns::Anchor::EndOfLine] = [ns::Anchor::EndOfString, '\\z']
|
134
|
+
MAP[ns::Anchor::EndOfStringOrBeforeEndOfLine] = [ns::Anchor::EndOfString, '\\z']
|
135
|
+
|
136
|
+
MAP.freeze
|
137
|
+
|
138
|
+
handle(*MAP.keys)
|
139
|
+
|
140
|
+
def dispatch
|
141
|
+
klass, text = MAP.fetch(input.class)
|
142
|
+
|
143
|
+
emit(klass.construct(text: text).tap { |new| new.quantifier = input.quantifier })
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class GroupCapturePositional < self
|
148
|
+
handle(::Regexp::Expression::Group::Capture)
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def dispatch
|
153
|
+
emit_passive_group unless subexpressions.empty?
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class GroupCaptureNamed < self
|
158
|
+
handle(::Regexp::Expression::Group::Named)
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def dispatch
|
163
|
+
return if input.name.start_with?('_') || subexpressions.empty?
|
164
|
+
|
165
|
+
emit_passive_group
|
166
|
+
|
167
|
+
emit_expression(
|
168
|
+
klass: ::Regexp::Expression::Group::Named,
|
169
|
+
text: "(?<_#{input.name}>"
|
170
|
+
)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class Recurse < self
|
175
|
+
ns = ::Regexp::Expression
|
176
|
+
|
177
|
+
# This list of nodes with subexessions is not yet complete.
|
178
|
+
handle(ns::Assertion::Base)
|
179
|
+
handle(ns::Assertion::Lookahead)
|
180
|
+
handle(ns::Assertion::Lookbehind)
|
181
|
+
handle(ns::Assertion::NegativeLookahead)
|
182
|
+
handle(ns::Assertion::NegativeLookbehind)
|
183
|
+
handle(ns::Alternative)
|
184
|
+
handle(ns::Alternation)
|
185
|
+
handle(ns::Sequence)
|
186
|
+
handle(ns::CharacterSet)
|
187
|
+
handle(ns::CharacterSet::Range)
|
188
|
+
handle(ns::Conditional::Branch)
|
189
|
+
handle(ns::Conditional::Expression)
|
190
|
+
handle(ns::Group::Absence)
|
191
|
+
handle(ns::Group::Atomic)
|
192
|
+
handle(ns::Group::Capture)
|
193
|
+
handle(ns::Group::Comment)
|
194
|
+
handle(ns::Group::Named)
|
195
|
+
handle(ns::Group::Options)
|
196
|
+
handle(ns::Group::Passive)
|
197
|
+
handle(ns::Root)
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
def dispatch
|
202
|
+
subexpressions.each_with_index do |expression, index|
|
203
|
+
self.class.mutate(expression).each do |new_expression|
|
204
|
+
emit(mk_dup.tap { |new| new.expressions[index] = new_expression })
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end # Regexp
|
210
|
+
end # Mutator
|
211
|
+
end # Mutant
|
data/lib/mutant/version.rb
CHANGED
data/lib/mutant.rb
CHANGED
@@ -84,15 +84,6 @@ module Mutant
|
|
84
84
|
require 'mutant/ast/named_children'
|
85
85
|
require 'mutant/ast/node_predicates'
|
86
86
|
require 'mutant/ast/find_metaclass_containing'
|
87
|
-
require 'mutant/ast/regexp'
|
88
|
-
require 'mutant/ast/regexp/transformer'
|
89
|
-
require 'mutant/ast/regexp/transformer/direct'
|
90
|
-
require 'mutant/ast/regexp/transformer/named_group'
|
91
|
-
require 'mutant/ast/regexp/transformer/options_group'
|
92
|
-
require 'mutant/ast/regexp/transformer/quantifier'
|
93
|
-
require 'mutant/ast/regexp/transformer/recursive'
|
94
|
-
require 'mutant/ast/regexp/transformer/root'
|
95
|
-
require 'mutant/ast/regexp/transformer/text'
|
96
87
|
require 'mutant/ast/meta'
|
97
88
|
require 'mutant/ast/meta/send'
|
98
89
|
require 'mutant/ast/meta/const'
|
@@ -123,15 +114,6 @@ module Mutant
|
|
123
114
|
require 'mutant/mutator/util/symbol'
|
124
115
|
require 'mutant/mutator/node'
|
125
116
|
require 'mutant/mutator/node/generic'
|
126
|
-
require 'mutant/mutator/node/regexp'
|
127
|
-
require 'mutant/mutator/node/regexp/alternation_meta'
|
128
|
-
require 'mutant/mutator/node/regexp/beginning_of_line_anchor'
|
129
|
-
require 'mutant/mutator/node/regexp/capture_group'
|
130
|
-
require 'mutant/mutator/node/regexp/named_group'
|
131
|
-
require 'mutant/mutator/node/regexp/character_type'
|
132
|
-
require 'mutant/mutator/node/regexp/end_of_line_anchor'
|
133
|
-
require 'mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor'
|
134
|
-
require 'mutant/mutator/node/regexp/zero_or_more'
|
135
117
|
require 'mutant/mutator/node/literal'
|
136
118
|
require 'mutant/mutator/node/literal/boolean'
|
137
119
|
require 'mutant/mutator/node/literal/range'
|
@@ -190,6 +172,7 @@ module Mutant
|
|
190
172
|
require 'mutant/mutator/node/procarg_zero'
|
191
173
|
require 'mutant/mutator/node/kwargs'
|
192
174
|
require 'mutant/mutator/node/numblock'
|
175
|
+
require 'mutant/mutator/regexp'
|
193
176
|
require 'mutant/loader'
|
194
177
|
require 'mutant/context'
|
195
178
|
require 'mutant/scope'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diff-lcs
|
@@ -30,34 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: regexp_parser
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 2.3.1
|
47
|
+
version: 2.6.1
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - "~>"
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 2.3.1
|
54
|
+
version: 2.6.1
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: sorbet-runtime
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +72,14 @@ dependencies:
|
|
78
72
|
requirements:
|
79
73
|
- - "~>"
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.6.
|
75
|
+
version: 0.6.6
|
82
76
|
type: :runtime
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.6.
|
82
|
+
version: 0.6.6
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: parallel
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,15 +178,6 @@ files:
|
|
184
178
|
- lib/mutant/ast/pattern/parser.rb
|
185
179
|
- lib/mutant/ast/pattern/source.rb
|
186
180
|
- lib/mutant/ast/pattern/token.rb
|
187
|
-
- lib/mutant/ast/regexp.rb
|
188
|
-
- lib/mutant/ast/regexp/transformer.rb
|
189
|
-
- lib/mutant/ast/regexp/transformer/direct.rb
|
190
|
-
- lib/mutant/ast/regexp/transformer/named_group.rb
|
191
|
-
- lib/mutant/ast/regexp/transformer/options_group.rb
|
192
|
-
- lib/mutant/ast/regexp/transformer/quantifier.rb
|
193
|
-
- lib/mutant/ast/regexp/transformer/recursive.rb
|
194
|
-
- lib/mutant/ast/regexp/transformer/root.rb
|
195
|
-
- lib/mutant/ast/regexp/transformer/text.rb
|
196
181
|
- lib/mutant/ast/sexp.rb
|
197
182
|
- lib/mutant/ast/structure.rb
|
198
183
|
- lib/mutant/ast/types.rb
|
@@ -297,15 +282,6 @@ files:
|
|
297
282
|
- lib/mutant/mutator/node/op_asgn.rb
|
298
283
|
- lib/mutant/mutator/node/or_asgn.rb
|
299
284
|
- lib/mutant/mutator/node/procarg_zero.rb
|
300
|
-
- lib/mutant/mutator/node/regexp.rb
|
301
|
-
- lib/mutant/mutator/node/regexp/alternation_meta.rb
|
302
|
-
- lib/mutant/mutator/node/regexp/beginning_of_line_anchor.rb
|
303
|
-
- lib/mutant/mutator/node/regexp/capture_group.rb
|
304
|
-
- lib/mutant/mutator/node/regexp/character_type.rb
|
305
|
-
- lib/mutant/mutator/node/regexp/end_of_line_anchor.rb
|
306
|
-
- lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb
|
307
|
-
- lib/mutant/mutator/node/regexp/named_group.rb
|
308
|
-
- lib/mutant/mutator/node/regexp/zero_or_more.rb
|
309
285
|
- lib/mutant/mutator/node/regopt.rb
|
310
286
|
- lib/mutant/mutator/node/resbody.rb
|
311
287
|
- lib/mutant/mutator/node/rescue.rb
|
@@ -320,6 +296,7 @@ files:
|
|
320
296
|
- lib/mutant/mutator/node/when.rb
|
321
297
|
- lib/mutant/mutator/node/yield.rb
|
322
298
|
- lib/mutant/mutator/node/zsuper.rb
|
299
|
+
- lib/mutant/mutator/regexp.rb
|
323
300
|
- lib/mutant/mutator/util.rb
|
324
301
|
- lib/mutant/mutator/util/array.rb
|
325
302
|
- lib/mutant/mutator/util/symbol.rb
|
@@ -395,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
395
372
|
- !ruby/object:Gem::Version
|
396
373
|
version: '0'
|
397
374
|
requirements: []
|
398
|
-
rubygems_version: 3.3.
|
375
|
+
rubygems_version: 3.3.26
|
399
376
|
signing_key:
|
400
377
|
specification_version: 4
|
401
378
|
summary: ''
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mutant
|
4
|
-
class AST
|
5
|
-
module Regexp
|
6
|
-
class Transformer
|
7
|
-
# Transformer for nodes which map directly to other domain
|
8
|
-
#
|
9
|
-
# A node maps "directly" to another domain if the node never
|
10
|
-
# has children or text which needs to be preserved for a mapping
|
11
|
-
#
|
12
|
-
# @example direct mapping
|
13
|
-
#
|
14
|
-
# input = /\d/
|
15
|
-
# expression = Regexp::Parser.parse(input).first
|
16
|
-
# node = Transformer::Direct.to_ast(expression)
|
17
|
-
#
|
18
|
-
# # the digit type always has the same text and no children
|
19
|
-
# expression.text # => "\\d"
|
20
|
-
# expression.terminal? # => true
|
21
|
-
#
|
22
|
-
# # therefore the `Parser::AST::Node` is always the same
|
23
|
-
# node # => s(:regexp_digit_type)
|
24
|
-
class Direct < self
|
25
|
-
# Mapper from `Regexp::Expression` to `Parser::AST::Node`
|
26
|
-
class ExpressionToAST < Transformer::ExpressionToAST
|
27
|
-
# Transform expression into node
|
28
|
-
#
|
29
|
-
# @return [Parser::AST::Node]
|
30
|
-
def call
|
31
|
-
quantify(ast)
|
32
|
-
end
|
33
|
-
end # ExpressionToAST
|
34
|
-
|
35
|
-
# Mapper from `Parser::AST::Node` to `Regexp::Expression`
|
36
|
-
class ASTToExpression < Transformer::ASTToExpression
|
37
|
-
include LookupTable
|
38
|
-
|
39
|
-
properties = ::Regexp::Syntax
|
40
|
-
.version_class("ruby/#{RUBY_VERSION}")
|
41
|
-
.features.fetch(:property)
|
42
|
-
.flat_map do |property|
|
43
|
-
property_specifier = "\\p{#{property}}"
|
44
|
-
non_property_specifier = "\\P{#{property}}"
|
45
|
-
|
46
|
-
property_regex = /#{property_specifier}/
|
47
|
-
non_property_regex = /#{non_property_specifier}/
|
48
|
-
|
49
|
-
[
|
50
|
-
[
|
51
|
-
:"regexp_#{property}_property",
|
52
|
-
[
|
53
|
-
:property,
|
54
|
-
property.to_sym,
|
55
|
-
property_specifier
|
56
|
-
],
|
57
|
-
::Regexp::Parser.parse(property_regex).expressions.first.class
|
58
|
-
],
|
59
|
-
[
|
60
|
-
:"regexp_#{property}_nonproperty",
|
61
|
-
[
|
62
|
-
:nonproperty,
|
63
|
-
property.to_sym,
|
64
|
-
non_property_specifier
|
65
|
-
],
|
66
|
-
::Regexp::Parser.parse(non_property_regex).expressions.first.class
|
67
|
-
]
|
68
|
-
]
|
69
|
-
end
|
70
|
-
|
71
|
-
# rubocop:disable Layout/LineLength
|
72
|
-
TABLE = Table.create(
|
73
|
-
*properties,
|
74
|
-
[:regexp_alnum_posixclass, [:posixclass, :alnum, '[:alnum:]'], ::Regexp::Expression::PosixClass],
|
75
|
-
[:regexp_alpha_posixclass, [:posixclass, :alpha, '[:alpha:]'], ::Regexp::Expression::PosixClass],
|
76
|
-
[:regexp_alternation_escape, [:escape, :alternation, '\|'], ::Regexp::Expression::EscapeSequence::Literal],
|
77
|
-
[:regexp_ascii_posixclass, [:posixclass, :ascii, '[:ascii:]'], ::Regexp::Expression::PosixClass],
|
78
|
-
[:regexp_backspace_escape, [:escape, :backspace, '\b'], ::Regexp::Expression::EscapeSequence::Backspace],
|
79
|
-
[:regexp_bell_escape, [:escape, :bell, '\a'], ::Regexp::Expression::EscapeSequence::Literal],
|
80
|
-
[:regexp_blank_posixclass, [:posixclass, :blank, '[:blank:]'], ::Regexp::Expression::PosixClass],
|
81
|
-
[:regexp_bol_anchor, [:anchor, :bol, '^'], ::Regexp::Expression::Anchor::BeginningOfLine],
|
82
|
-
[:regexp_bol_escape, [:escape, :bol, '\^'], ::Regexp::Expression::EscapeSequence::Literal],
|
83
|
-
[:regexp_bos_anchor, [:anchor, :bos, '\\A'], ::Regexp::Expression::Anchor::BeginningOfString],
|
84
|
-
[:regexp_carriage_escape, [:escape, :carriage, '\r'], ::Regexp::Expression::EscapeSequence::Literal],
|
85
|
-
[:regexp_cntrl_posixclass, [:posixclass, :cntrl, '[:cntrl:]'], ::Regexp::Expression::PosixClass],
|
86
|
-
[:regexp_digit_posixclass, [:posixclass, :digit, '[:digit:]'], ::Regexp::Expression::PosixClass],
|
87
|
-
[:regexp_digit_type, [:type, :digit, '\d'], ::Regexp::Expression::CharacterType::Digit],
|
88
|
-
[:regexp_dot_escape, [:escape, :dot, '\.'], ::Regexp::Expression::EscapeSequence::Literal],
|
89
|
-
[:regexp_dot_meta, [:meta, :dot, '.'], ::Regexp::Expression::CharacterType::Any],
|
90
|
-
[:regexp_eol_anchor, [:anchor, :eol, '$'], ::Regexp::Expression::Anchor::EndOfLine],
|
91
|
-
[:regexp_eol_escape, [:escape, :eol, '\$'], ::Regexp::Expression::EscapeSequence::Literal],
|
92
|
-
[:regexp_eos_anchor, [:anchor, :eos, '\\z'], ::Regexp::Expression::Anchor::EndOfString],
|
93
|
-
[:regexp_eos_ob_eol_anchor, [:anchor, :eos_ob_eol, '\\Z'], ::Regexp::Expression::Anchor::EndOfStringOrBeforeEndOfLine],
|
94
|
-
[:regexp_escape_escape, [:escape, :escape, '\e'], ::Regexp::Expression::EscapeSequence::AsciiEscape],
|
95
|
-
[:regexp_form_feed_escape, [:escape, :form_feed, '\f'], ::Regexp::Expression::EscapeSequence::FormFeed],
|
96
|
-
[:regexp_graph_posixclass, [:posixclass, :graph, '[:graph:]'], ::Regexp::Expression::PosixClass],
|
97
|
-
[:regexp_group_close_escape, [:escape, :group_close, '\)'], ::Regexp::Expression::EscapeSequence::Literal],
|
98
|
-
[:regexp_group_open_escape, [:escape, :group_open, '\('], ::Regexp::Expression::EscapeSequence::Literal],
|
99
|
-
[:regexp_hex_type, [:type, :hex, '\h'], ::Regexp::Expression::CharacterType::Hex],
|
100
|
-
[:regexp_interval_close_escape, [:escape, :interval_close, '\}'], ::Regexp::Expression::EscapeSequence::Literal],
|
101
|
-
[:regexp_interval_open_escape, [:escape, :interval_open, '\{'], ::Regexp::Expression::EscapeSequence::Literal],
|
102
|
-
[:regexp_linebreak_type, [:type, :linebreak, '\R'], ::Regexp::Expression::CharacterType::Linebreak],
|
103
|
-
[:regexp_lower_posixclass, [:posixclass, :lower, '[:lower:]'], ::Regexp::Expression::PosixClass],
|
104
|
-
[:regexp_mark_keep, [:keep, :mark, '\K'], ::Regexp::Expression::Keep::Mark],
|
105
|
-
[:regexp_match_start_anchor, [:anchor, :match_start, '\\G'], ::Regexp::Expression::Anchor::MatchStart],
|
106
|
-
[:regexp_newline_escape, [:escape, :newline, '\n'], ::Regexp::Expression::EscapeSequence::Literal],
|
107
|
-
[:regexp_nondigit_type, [:type, :nondigit, '\D'], ::Regexp::Expression::CharacterType::NonDigit],
|
108
|
-
[:regexp_nonhex_type, [:type, :nonhex, '\H'], ::Regexp::Expression::CharacterType::NonHex],
|
109
|
-
[:regexp_nonspace_type, [:type, :nonspace, '\S'], ::Regexp::Expression::CharacterType::NonSpace],
|
110
|
-
[:regexp_nonword_boundary_anchor, [:anchor, :nonword_boundary, '\\B'], ::Regexp::Expression::Anchor::NonWordBoundary],
|
111
|
-
[:regexp_nonword_type, [:type, :nonword, '\W'], ::Regexp::Expression::CharacterType::NonWord],
|
112
|
-
[:regexp_one_or_more_escape, [:escape, :one_or_more, '\+'], ::Regexp::Expression::EscapeSequence::Literal],
|
113
|
-
[:regexp_print_nonposixclass, [:nonposixclass, :print, '[:^print:]'], ::Regexp::Expression::PosixClass],
|
114
|
-
[:regexp_print_posixclass, [:posixclass, :print, '[:print:]'], ::Regexp::Expression::PosixClass],
|
115
|
-
[:regexp_print_posixclass, [:posixclass, :print, '[:print:]'], ::Regexp::Expression::PosixClass],
|
116
|
-
[:regexp_punct_posixclass, [:posixclass, :punct, '[:punct:]'], ::Regexp::Expression::PosixClass],
|
117
|
-
[:regexp_set_close_escape, [:escape, :set_close, '\]'], ::Regexp::Expression::EscapeSequence::Literal],
|
118
|
-
[:regexp_set_open_escape, [:escape, :set_open, '\['], ::Regexp::Expression::EscapeSequence::Literal],
|
119
|
-
[:regexp_space_posixclass, [:posixclass, :space, '[:space:]'], ::Regexp::Expression::PosixClass],
|
120
|
-
[:regexp_space_type, [:type, :space, '\s'], ::Regexp::Expression::CharacterType::Space],
|
121
|
-
[:regexp_upper_posixclass, [:posixclass, :upper, '[:upper:]'], ::Regexp::Expression::PosixClass],
|
122
|
-
[:regexp_vertical_tab_escape, [:escape, :vertical_tab, '\v'], ::Regexp::Expression::EscapeSequence::VerticalTab],
|
123
|
-
[:regexp_word_boundary_anchor, [:anchor, :word_boundary, '\b'], ::Regexp::Expression::Anchor::WordBoundary],
|
124
|
-
[:regexp_word_posixclass, [:posixclass, :word, '[:word:]'], ::Regexp::Expression::PosixClass],
|
125
|
-
[:regexp_word_type, [:type, :word, '\w'], ::Regexp::Expression::CharacterType::Word],
|
126
|
-
[:regexp_xdigit_posixclass, [:posixclass, :xdigit, '[:xdigit:]'], ::Regexp::Expression::PosixClass],
|
127
|
-
[:regexp_xgrapheme_type, [:type, :xgrapheme, '\X'], ::Regexp::Expression::CharacterType::ExtendedGrapheme],
|
128
|
-
[:regexp_zero_or_more_escape, [:escape, :zero_or_more, '\*'], ::Regexp::Expression::EscapeSequence::Literal],
|
129
|
-
[:regexp_zero_or_one_escape, [:escape, :zero_or_one, '\?'], ::Regexp::Expression::EscapeSequence::Literal]
|
130
|
-
)
|
131
|
-
# rubocop:enable Layout/LineLength
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def transform
|
136
|
-
expression_class.new(expression_token)
|
137
|
-
end
|
138
|
-
end # ASTToExpression
|
139
|
-
|
140
|
-
ASTToExpression::TABLE.types.each(&method(:register))
|
141
|
-
end # Direct
|
142
|
-
end # Transformer
|
143
|
-
end # Regexp
|
144
|
-
end # AST
|
145
|
-
end # Mutant
|