mutant 0.8.24 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/Changelog.md +14 -654
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +59 -64
  6. data/LICENSE +271 -20
  7. data/README.md +73 -140
  8. data/Rakefile +0 -21
  9. data/bin/mutant +7 -2
  10. data/config/reek.yml +2 -1
  11. data/config/rubocop.yml +5 -9
  12. data/docs/incremental.md +76 -0
  13. data/docs/known-problems.md +0 -14
  14. data/docs/mutant-minitest.md +1 -1
  15. data/docs/mutant-rspec.md +2 -24
  16. data/lib/mutant.rb +45 -53
  17. data/lib/mutant/ast/nodes.rb +0 -2
  18. data/lib/mutant/ast/types.rb +1 -117
  19. data/lib/mutant/base.rb +192 -0
  20. data/lib/mutant/bootstrap.rb +145 -0
  21. data/lib/mutant/cli.rb +68 -54
  22. data/lib/mutant/config.rb +119 -6
  23. data/lib/mutant/env.rb +94 -8
  24. data/lib/mutant/expression.rb +6 -1
  25. data/lib/mutant/expression/parser.rb +9 -31
  26. data/lib/mutant/integration.rb +64 -36
  27. data/lib/mutant/isolation.rb +16 -1
  28. data/lib/mutant/isolation/fork.rb +105 -40
  29. data/lib/mutant/license.rb +34 -0
  30. data/lib/mutant/license/subscription.rb +47 -0
  31. data/lib/mutant/license/subscription/commercial.rb +57 -0
  32. data/lib/mutant/license/subscription/opensource.rb +77 -0
  33. data/lib/mutant/loader.rb +27 -4
  34. data/lib/mutant/matcher.rb +48 -1
  35. data/lib/mutant/matcher/chain.rb +1 -1
  36. data/lib/mutant/matcher/config.rb +0 -2
  37. data/lib/mutant/matcher/filter.rb +1 -1
  38. data/lib/mutant/matcher/method.rb +11 -7
  39. data/lib/mutant/matcher/methods.rb +1 -1
  40. data/lib/mutant/matcher/namespace.rb +1 -1
  41. data/lib/mutant/matcher/null.rb +1 -1
  42. data/lib/mutant/matcher/scope.rb +1 -1
  43. data/lib/mutant/meta/example/dsl.rb +0 -8
  44. data/lib/mutant/mutation.rb +1 -2
  45. data/lib/mutant/mutator/node.rb +2 -9
  46. data/lib/mutant/mutator/node/arguments.rb +1 -1
  47. data/lib/mutant/mutator/node/class.rb +0 -8
  48. data/lib/mutant/mutator/node/define.rb +0 -12
  49. data/lib/mutant/mutator/node/generic.rb +30 -44
  50. data/lib/mutant/mutator/node/index.rb +4 -4
  51. data/lib/mutant/mutator/node/literal/regex.rb +0 -39
  52. data/lib/mutant/mutator/node/send.rb +13 -12
  53. data/lib/mutant/parallel.rb +61 -40
  54. data/lib/mutant/parallel/driver.rb +59 -0
  55. data/lib/mutant/parallel/source.rb +6 -2
  56. data/lib/mutant/parallel/worker.rb +63 -45
  57. data/lib/mutant/range.rb +15 -0
  58. data/lib/mutant/reporter/cli.rb +5 -11
  59. data/lib/mutant/reporter/cli/format.rb +3 -46
  60. data/lib/mutant/reporter/cli/printer/config.rb +5 -6
  61. data/lib/mutant/reporter/cli/printer/env.rb +40 -0
  62. data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
  63. data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
  64. data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
  65. data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
  66. data/lib/mutant/repository.rb +0 -65
  67. data/lib/mutant/repository/diff.rb +104 -0
  68. data/lib/mutant/repository/diff/ranges.rb +52 -0
  69. data/lib/mutant/result.rb +16 -7
  70. data/lib/mutant/runner.rb +38 -47
  71. data/lib/mutant/runner/sink.rb +1 -1
  72. data/lib/mutant/selector/null.rb +19 -0
  73. data/lib/mutant/subject.rb +3 -1
  74. data/lib/mutant/subject/method/instance.rb +3 -1
  75. data/lib/mutant/transform.rb +511 -0
  76. data/lib/mutant/variable.rb +282 -0
  77. data/lib/mutant/version.rb +1 -1
  78. data/lib/mutant/warnings.rb +113 -0
  79. data/meta/case.rb +1 -0
  80. data/meta/class.rb +0 -9
  81. data/meta/def.rb +1 -26
  82. data/meta/regexp.rb +10 -20
  83. data/meta/send.rb +14 -46
  84. data/mutant-minitest.gemspec +1 -1
  85. data/mutant-rspec.gemspec +2 -2
  86. data/mutant.gemspec +15 -16
  87. data/mutant.yml +6 -0
  88. data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
  89. data/spec/integration/mutant/minitest_spec.rb +3 -2
  90. data/spec/integration/mutant/rspec_spec.rb +4 -3
  91. data/spec/integrations.yml +16 -13
  92. data/spec/shared/base_behavior.rb +45 -0
  93. data/spec/shared/framework_integration_behavior.rb +43 -14
  94. data/spec/spec_helper.rb +21 -17
  95. data/spec/support/corpus.rb +56 -95
  96. data/spec/support/shared_context.rb +37 -14
  97. data/spec/support/xspec.rb +7 -3
  98. data/spec/unit/mutant/bootstrap_spec.rb +216 -0
  99. data/spec/unit/mutant/cli_spec.rb +173 -117
  100. data/spec/unit/mutant/config_spec.rb +126 -0
  101. data/spec/unit/mutant/either_spec.rb +247 -0
  102. data/spec/unit/mutant/env_spec.rb +162 -40
  103. data/spec/unit/mutant/expression/method_spec.rb +16 -0
  104. data/spec/unit/mutant/expression/parser_spec.rb +29 -33
  105. data/spec/unit/mutant/expression_spec.rb +5 -7
  106. data/spec/unit/mutant/integration_spec.rb +100 -9
  107. data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
  108. data/spec/unit/mutant/isolation/result_spec.rb +33 -1
  109. data/spec/unit/mutant/license_spec.rb +257 -0
  110. data/spec/unit/mutant/loader_spec.rb +50 -11
  111. data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
  112. data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
  113. data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
  114. data/spec/unit/mutant/matcher_spec.rb +102 -0
  115. data/spec/unit/mutant/maybe_spec.rb +60 -0
  116. data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
  117. data/spec/unit/mutant/mutation_spec.rb +13 -6
  118. data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
  119. data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
  120. data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
  121. data/spec/unit/mutant/parallel_spec.rb +105 -8
  122. data/spec/unit/mutant/range_spec.rb +141 -0
  123. data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
  124. data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
  125. data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
  126. data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
  127. data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
  128. data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
  129. data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
  130. data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
  131. data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
  132. data/spec/unit/mutant/repository/diff_spec.rb +84 -71
  133. data/spec/unit/mutant/require_highjack_spec.rb +1 -1
  134. data/spec/unit/mutant/result/env_spec.rb +39 -9
  135. data/spec/unit/mutant/result/test_spec.rb +14 -0
  136. data/spec/unit/mutant/runner_spec.rb +88 -41
  137. data/spec/unit/mutant/selector/expression_spec.rb +11 -10
  138. data/spec/unit/mutant/selector/null_spec.rb +17 -0
  139. data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
  140. data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
  141. data/spec/unit/mutant/subject_spec.rb +9 -1
  142. data/spec/unit/mutant/transform/array_spec.rb +92 -0
  143. data/spec/unit/mutant/transform/bool_spec.rb +63 -0
  144. data/spec/unit/mutant/transform/error_spec.rb +132 -0
  145. data/spec/unit/mutant/transform/exception_spec.rb +44 -0
  146. data/spec/unit/mutant/transform/hash_spec.rb +236 -0
  147. data/spec/unit/mutant/transform/index_spec.rb +92 -0
  148. data/spec/unit/mutant/transform/named_spec.rb +49 -0
  149. data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
  150. data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
  151. data/spec/unit/mutant/variable_spec.rb +618 -0
  152. data/spec/unit/mutant/warnings_spec.rb +89 -0
  153. data/spec/unit/mutant/world_spec.rb +63 -0
  154. data/test_app/Gemfile.minitest +0 -2
  155. metadata +79 -113
  156. data/.gitattributes +0 -1
  157. data/.ruby-gemset +0 -1
  158. data/config/triage.yml +0 -2
  159. data/lib/mutant/actor.rb +0 -57
  160. data/lib/mutant/actor/env.rb +0 -31
  161. data/lib/mutant/actor/mailbox.rb +0 -34
  162. data/lib/mutant/actor/receiver.rb +0 -42
  163. data/lib/mutant/actor/sender.rb +0 -26
  164. data/lib/mutant/ast/meta/restarg.rb +0 -19
  165. data/lib/mutant/ast/regexp.rb +0 -42
  166. data/lib/mutant/ast/regexp/transformer.rb +0 -187
  167. data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
  168. data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
  169. data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
  170. data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
  171. data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
  172. data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
  173. data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
  174. data/lib/mutant/env/bootstrap.rb +0 -160
  175. data/lib/mutant/matcher/compiler.rb +0 -60
  176. data/lib/mutant/mutator/node/regexp.rb +0 -35
  177. data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
  178. data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
  179. data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
  180. data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
  181. data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
  182. data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
  183. data/lib/mutant/parallel/master.rb +0 -181
  184. data/lib/mutant/reporter/cli/printer/status.rb +0 -53
  185. data/lib/mutant/reporter/cli/tput.rb +0 -46
  186. data/lib/mutant/warning_filter.rb +0 -61
  187. data/meta/regexp/character_types.rb +0 -23
  188. data/meta/regexp/regexp_alternation_meta.rb +0 -13
  189. data/meta/regexp/regexp_bol_anchor.rb +0 -10
  190. data/meta/regexp/regexp_bos_anchor.rb +0 -18
  191. data/meta/regexp/regexp_capture_group.rb +0 -19
  192. data/meta/regexp/regexp_eol_anchor.rb +0 -10
  193. data/meta/regexp/regexp_eos_anchor.rb +0 -8
  194. data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
  195. data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
  196. data/meta/regexp/regexp_root_expression.rb +0 -10
  197. data/meta/restarg.rb +0 -10
  198. data/spec/support/fake_actor.rb +0 -111
  199. data/spec/support/warning.rb +0 -66
  200. data/spec/unit/mutant/actor/binding_spec.rb +0 -34
  201. data/spec/unit/mutant/actor/env_spec.rb +0 -31
  202. data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
  203. data/spec/unit/mutant/actor/message_spec.rb +0 -25
  204. data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
  205. data/spec/unit/mutant/actor/sender_spec.rb +0 -24
  206. data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
  207. data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
  208. data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
  209. data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
  210. data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
  211. data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
  212. data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
  213. data/spec/unit/mutant/parallel/master_spec.rb +0 -338
  214. data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
  215. data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
  216. data/spec/unit/mutant/warning_filter_spec.rb +0 -106
  217. data/spec/unit/mutant_spec.rb +0 -17
  218. data/test_app/Gemfile.rspec3.7 +0 -7
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::AST::Regexp, '.parse' do
4
- def apply(input)
5
- described_class.parse(input)
6
- end
7
-
8
- context 'on regexp regexp_parser does accept' do
9
- it 'parses using minor ruby version' do
10
- expect(apply(/foo/).to_re).to eql(/foo/)
11
- end
12
- end
13
-
14
- context 'on regexp regexp_parser does not accept' do
15
- it 'returns nil' do
16
- expect(apply(/u{/)).to be(nil)
17
- end
18
- end
19
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::AST::Regexp::Transformer::LookupTable::Table do
4
- subject { table.lookup(:regexp_fake_thing) }
5
-
6
- let(:expression_class) { class_double(Regexp::Expression) }
7
-
8
- let(:table) do
9
- described_class.create(
10
- [:regexp_fake_thing, %i[thing fake], expression_class]
11
- )
12
- end
13
-
14
- its(:token) { should eql(Regexp::Token.new(:thing, :fake)) }
15
-
16
- its(:regexp_class) { should be(expression_class) }
17
-
18
- it 'exposes list of types' do
19
- expect(table.types).to eql([:regexp_fake_thing])
20
- end
21
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::AST::Regexp::Transformer::LookupTable do
4
- subject(:pair) { mapper.new(s(:regexp_fake)).pair }
5
-
6
- let(:table) { instance_double(described_class::Table) }
7
- let(:token) { ::Regexp::Token.new }
8
- let(:klass) { ::Regexp::Expression }
9
-
10
- let(:mapping) do
11
- described_class::Mapping.new(token, klass)
12
- end
13
-
14
- let(:mapper) do
15
- fake_table = table
16
-
17
- Class.new do
18
- include Concord.new(:node), Mutant::AST::Regexp::Transformer::LookupTable
19
-
20
- const_set(:TABLE, fake_table)
21
-
22
- def pair
23
- [expression_token, expression_class]
24
- end
25
- end
26
- end
27
-
28
- before do
29
- allow(table).to receive(:lookup).with(:regexp_fake).and_return(mapping)
30
- end
31
-
32
- it 'constructs regexp lookup table' do
33
- expect(pair).to eql([token, klass])
34
- end
35
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::AST::Regexp::Transformer do
4
- before do
5
- stub_const("#{described_class}::REGISTRY", Mutant::Registry.new)
6
- end
7
-
8
- it 'registers types to a given class' do
9
- klass = Class.new(described_class) { register(:regexp_bos_anchor) }
10
-
11
- expect(described_class.lookup(:regexp_bos_anchor)).to be(klass)
12
- end
13
-
14
- it 'rejects duplicate registrations' do
15
- Class.new(described_class) { register(:regexp_bos_anchor) }
16
-
17
- expect { Class.new(described_class) { register(:regexp_bos_anchor) } }
18
- .to raise_error(Mutant::Registry::RegistryError)
19
- .with_message('Duplicate type registration: :regexp_bos_anchor')
20
- end
21
- end
@@ -1,704 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RegexpSpec
4
- class Expression < SimpleDelegator
5
- NO_EXPRESSIONS = Object.new.freeze
6
-
7
- include Equalizer.new(:type, :token, :text, :quantifier, :expressions)
8
-
9
- def quantifier
10
- return Quantifier::NONE unless quantified?
11
-
12
- Quantifier.new(super())
13
- end
14
-
15
- def expressions
16
- return NO_EXPRESSIONS if terminal?
17
-
18
- super().map(&self.class.public_method(:new))
19
- end
20
-
21
- class Quantifier < SimpleDelegator
22
- NONE = Object.new.freeze
23
-
24
- include Equalizer.new(:token, :text, :mode, :min, :max)
25
- end # Quantifier
26
- end # Expression
27
-
28
- RSpec.shared_context 'regexp transformation' do
29
- let(:parsed) { Mutant::AST::Regexp.parse(regexp) }
30
- let(:ast) { Mutant::AST::Regexp.to_ast(parsed) }
31
- let(:expression) { Mutant::AST::Regexp.to_expression(ast) }
32
-
33
- def expect_frozen_expression(expression, root = expression)
34
- expect(expression.frozen?).to(
35
- be(true),
36
- "Expected #{root} to be deep frozen"
37
- )
38
-
39
- return if expression.terminal?
40
-
41
- expression.expressions.each do |subexpression|
42
- expect_frozen_expression(subexpression, root)
43
- end
44
- end
45
-
46
- it 'transforms into ast' do
47
- expect(ast).to eql(expected)
48
- end
49
-
50
- it 'deep freezes expression mapping' do
51
- expect_frozen_expression(expression)
52
- end
53
-
54
- it 'transforms ast back to expression' do
55
- expect(Expression.new(expression)).to eql(Expression.new(parsed))
56
- end
57
- end
58
-
59
- RSpec.shared_context 'regexp round trip' do
60
- let(:round_trip) { expression.to_re }
61
-
62
- it 'round trips Regexp' do
63
- expect(round_trip).to eql(regexp)
64
- end
65
- end
66
-
67
- def self.expect_mapping(regexp, type, &block)
68
- RSpec.describe Mutant::AST::Regexp::Transformer.lookup(type) do
69
- context "when mapping #{regexp.inspect}" do
70
- let(:regexp) { regexp }
71
- let(:expected, &block)
72
-
73
- include_context 'regexp transformation'
74
-
75
- unless regexp.encoding.name.eql?('ASCII-8BIT')
76
- include_context 'regexp round trip'
77
- end
78
- end
79
- end
80
- end
81
- end # RegexpSpec
82
-
83
- RegexpSpec.expect_mapping(/A/, :regexp_root_expression) do
84
- s(:regexp_root_expression,
85
- s(:regexp_literal_literal, 'A'))
86
- end
87
-
88
- RegexpSpec.expect_mapping(/\p{Alpha}/, :regexp_alpha_property) do
89
- s(:regexp_root_expression,
90
- s(:regexp_alpha_property))
91
- end
92
-
93
- RegexpSpec.expect_mapping(/foo|bar/, :regexp_alternation_meta) do
94
- s(:regexp_root_expression,
95
- s(:regexp_alternation_meta,
96
- s(:regexp_sequence_expression,
97
- s(:regexp_literal_literal, 'foo')),
98
- s(:regexp_sequence_expression,
99
- s(:regexp_literal_literal, 'bar'))))
100
- end
101
-
102
- RegexpSpec.expect_mapping(/(?>a)/, :regexp_atomic_group) do
103
- s(:regexp_root_expression,
104
- s(:regexp_atomic_group,
105
- s(:regexp_literal_literal, 'a')))
106
- end
107
-
108
- RegexpSpec.expect_mapping(/\\/, :regexp_backslash_escape) do
109
- s(:regexp_root_expression,
110
- s(:regexp_backslash_escape, '\\\\'))
111
- end
112
-
113
- RegexpSpec.expect_mapping(/^/, :regexp_bol_anchor) do
114
- s(:regexp_root_expression,
115
- s(:regexp_bol_anchor))
116
- end
117
-
118
- RegexpSpec.expect_mapping(/\^/, :regexp_bol_escape) do
119
- s(:regexp_root_expression,
120
- s(:regexp_bol_escape))
121
- end
122
-
123
- RegexpSpec.expect_mapping(/\A/, :regexp_bos_anchor) do
124
- s(:regexp_root_expression,
125
- s(:regexp_bos_anchor))
126
- end
127
-
128
- RegexpSpec.expect_mapping(/(foo)/, :regexp_capture_group) do
129
- s(:regexp_root_expression,
130
- s(:regexp_capture_group,
131
- s(:regexp_literal_literal, 'foo')))
132
- end
133
-
134
- RegexpSpec.expect_mapping(/()\1/, :regexp_number_backref) do
135
- s(:regexp_root_expression,
136
- s(:regexp_capture_group),
137
- s(:regexp_number_backref, '\\1'))
138
- end
139
-
140
- RegexpSpec.expect_mapping(/(a)*/, :regexp_capture_group) do
141
- s(:regexp_root_expression,
142
- s(:regexp_greedy_zero_or_more, 0, -1,
143
- s(:regexp_capture_group,
144
- s(:regexp_literal_literal, 'a'))))
145
- end
146
-
147
- RegexpSpec.expect_mapping(/\r/, :regexp_carriage_escape) do
148
- s(:regexp_root_expression,
149
- s(:regexp_carriage_escape))
150
- end
151
-
152
- RegexpSpec.expect_mapping(/\a/, :regexp_bell_escape) do
153
- s(:regexp_root_expression,
154
- s(:regexp_bell_escape))
155
- end
156
-
157
- RegexpSpec.expect_mapping(/\?/, :regexp_zero_or_one_escape) do
158
- s(:regexp_root_expression,
159
- s(:regexp_zero_or_one_escape))
160
- end
161
-
162
- RegexpSpec.expect_mapping(/\|/, :regexp_alternation_escape) do
163
- s(:regexp_root_expression,
164
- s(:regexp_alternation_escape))
165
- end
166
-
167
- RegexpSpec.expect_mapping(/\c2/, :regexp_control_escape) do
168
- s(:regexp_root_expression,
169
- s(:regexp_control_escape, '\\c2'))
170
- end
171
-
172
- RegexpSpec.expect_mapping(/\M-B/n, :regexp_meta_sequence_escape) do
173
- s(:regexp_root_expression,
174
- s(:regexp_meta_sequence_escape, '\M-B'))
175
- end
176
-
177
- RegexpSpec.expect_mapping(/\K/, :regexp_mark_keep) do
178
- s(:regexp_root_expression,
179
- s(:regexp_mark_keep))
180
- end
181
-
182
- RegexpSpec.expect_mapping(/\e/, :regexp_escape_escape) do
183
- s(:regexp_root_expression,
184
- s(:regexp_escape_escape))
185
- end
186
-
187
- RegexpSpec.expect_mapping(/\f/, :regexp_form_feed_escape) do
188
- s(:regexp_root_expression,
189
- s(:regexp_form_feed_escape))
190
- end
191
-
192
- RegexpSpec.expect_mapping(/\v/, :regexp_vertical_tab_escape) do
193
- s(:regexp_root_expression,
194
- s(:regexp_vertical_tab_escape))
195
- end
196
-
197
- RegexpSpec.expect_mapping(/\e/, :regexp_escape_escape) do
198
- s(:regexp_root_expression,
199
- s(:regexp_escape_escape))
200
- end
201
-
202
- RegexpSpec.expect_mapping(/[ab]+/, :regexp_character_set) do
203
- s(:regexp_root_expression,
204
- s(:regexp_greedy_one_or_more, 1, -1,
205
- s(:regexp_character_set,
206
- s(:regexp_literal_literal, 'a'),
207
- s(:regexp_literal_literal, 'b'))))
208
- end
209
-
210
- RegexpSpec.expect_mapping(/[ab]/, :regexp_character_set) do
211
- s(:regexp_root_expression,
212
- s(:regexp_character_set,
213
- s(:regexp_literal_literal, 'a'),
214
- s(:regexp_literal_literal, 'b')))
215
- end
216
-
217
- RegexpSpec.expect_mapping(/[a-j]/, :regexp_character_set) do
218
- s(:regexp_root_expression,
219
- s(:regexp_character_set,
220
- s(:regexp_range_set,
221
- s(:regexp_literal_literal, 'a'),
222
- s(:regexp_literal_literal, 'j'))))
223
- end
224
-
225
- RegexpSpec.expect_mapping(/[\b]/, :regexp_backspace_escape) do
226
- s(:regexp_root_expression,
227
- s(:regexp_character_set,
228
- s(:regexp_backspace_escape)))
229
- end
230
-
231
- RegexpSpec.expect_mapping(/()(?(1)a|b)/, :regexp_open_conditional) do
232
- s(:regexp_root_expression,
233
- s(:regexp_capture_group),
234
- s(:regexp_open_conditional,
235
- s(:regexp_condition_conditional, '(1)'),
236
- s(:regexp_sequence_expression,
237
- s(:regexp_literal_literal, 'a')),
238
- s(:regexp_sequence_expression,
239
- s(:regexp_literal_literal, 'b'))))
240
- end
241
-
242
- RegexpSpec.expect_mapping(/[ab&&bc]/, :regexp_intersection_set) do
243
- s(:regexp_root_expression,
244
- s(:regexp_character_set,
245
- s(:regexp_intersection_set,
246
- s(:regexp_sequence_expression,
247
- s(:regexp_literal_literal, 'a'),
248
- s(:regexp_literal_literal, 'b')),
249
- s(:regexp_sequence_expression,
250
- s(:regexp_literal_literal, 'b'),
251
- s(:regexp_literal_literal, 'c')))))
252
- end
253
-
254
- RegexpSpec.expect_mapping(/\u{9879}/, :regexp_codepoint_list_escape) do
255
- s(:regexp_root_expression,
256
- s(:regexp_codepoint_list_escape, '\\u{9879}'))
257
- end
258
-
259
- RegexpSpec.expect_mapping(/(?#foo)/, :regexp_comment_group) do
260
- s(:regexp_root_expression,
261
- s(:regexp_comment_group, '(?#foo)'))
262
- end
263
-
264
- RegexpSpec.expect_mapping(/(?x: # comment
265
- )/, :regexp_comment_free_space) do
266
- s(:regexp_root_expression,
267
- s(:regexp_options_group, {
268
- x: true
269
- },
270
- s(:regexp_whitespace_free_space, ' '),
271
- s(:regexp_comment_free_space, "# comment\n")))
272
- end
273
-
274
- RegexpSpec.expect_mapping(/\d/, :regexp_digit_type) do
275
- s(:regexp_root_expression,
276
- s(:regexp_digit_type))
277
- end
278
-
279
- RegexpSpec.expect_mapping(/\./, :regexp_dot_escape) do
280
- s(:regexp_root_expression,
281
- s(:regexp_dot_escape))
282
- end
283
-
284
- RegexpSpec.expect_mapping(/.+/, :regexp_dot_meta) do
285
- s(:regexp_root_expression,
286
- s(:regexp_greedy_one_or_more, 1, -1,
287
- s(:regexp_dot_meta)))
288
- end
289
-
290
- RegexpSpec.expect_mapping(/$/, :regexp_eol_anchor) do
291
- s(:regexp_root_expression,
292
- s(:regexp_eol_anchor))
293
- end
294
-
295
- RegexpSpec.expect_mapping(/\$/, :regexp_eol_escape) do
296
- s(:regexp_root_expression,
297
- s(:regexp_eol_escape))
298
- end
299
-
300
- RegexpSpec.expect_mapping(/\z/, :regexp_eos_anchor) do
301
- s(:regexp_root_expression,
302
- s(:regexp_eos_anchor))
303
- end
304
-
305
- RegexpSpec.expect_mapping(/\Z/, :regexp_eos_ob_eol_anchor) do
306
- s(:regexp_root_expression,
307
- s(:regexp_eos_ob_eol_anchor))
308
- end
309
-
310
- RegexpSpec.expect_mapping(/a{1,}/, :regexp_greedy_interval) do
311
- s(:regexp_root_expression,
312
- s(:regexp_greedy_interval, 1, -1,
313
- s(:regexp_literal_literal, 'a')))
314
- end
315
-
316
- RegexpSpec.expect_mapping(/.{2}/, :regexp_greedy_interval) do
317
- s(:regexp_root_expression,
318
- s(:regexp_greedy_interval, 2, 2,
319
- s(:regexp_dot_meta)))
320
- end
321
-
322
- RegexpSpec.expect_mapping(/.{3,5}/, :regexp_greedy_interval) do
323
- s(:regexp_root_expression,
324
- s(:regexp_greedy_interval, 3, 5,
325
- s(:regexp_dot_meta)))
326
- end
327
-
328
- RegexpSpec.expect_mapping(/.{,3}/, :regexp_greedy_interval) do
329
- s(:regexp_root_expression,
330
- s(:regexp_greedy_interval, 0, 3,
331
- s(:regexp_dot_meta)))
332
- end
333
-
334
- RegexpSpec.expect_mapping(/.+/, :regexp_greedy_one_or_more) do
335
- s(:regexp_root_expression,
336
- s(:regexp_greedy_one_or_more, 1, -1,
337
- s(:regexp_dot_meta)))
338
- end
339
-
340
- RegexpSpec.expect_mapping(/[ab]+/, :regexp_greedy_one_or_more) do
341
- s(:regexp_root_expression,
342
- s(:regexp_greedy_one_or_more, 1, -1,
343
- s(:regexp_character_set,
344
- s(:regexp_literal_literal, 'a'),
345
- s(:regexp_literal_literal, 'b'))))
346
- end
347
-
348
- RegexpSpec.expect_mapping(/(a)*/, :regexp_greedy_zero_or_more) do
349
- s(:regexp_root_expression,
350
- s(:regexp_greedy_zero_or_more, 0, -1,
351
- s(:regexp_capture_group,
352
- s(:regexp_literal_literal, 'a'))))
353
- end
354
-
355
- RegexpSpec.expect_mapping(/.*/, :regexp_greedy_zero_or_more) do
356
- s(:regexp_root_expression,
357
- s(:regexp_greedy_zero_or_more, 0, -1,
358
- s(:regexp_dot_meta)))
359
- end
360
-
361
- RegexpSpec.expect_mapping(/.?/, :regexp_greedy_zero_or_one) do
362
- s(:regexp_root_expression,
363
- s(:regexp_greedy_zero_or_one, 0, 1,
364
- s(:regexp_dot_meta)))
365
- end
366
-
367
- RegexpSpec.expect_mapping(/\)/, :regexp_group_close_escape) do
368
- s(:regexp_root_expression,
369
- s(:regexp_group_close_escape))
370
- end
371
-
372
- RegexpSpec.expect_mapping(/\(/, :regexp_group_open_escape) do
373
- s(:regexp_root_expression,
374
- s(:regexp_group_open_escape))
375
- end
376
-
377
- RegexpSpec.expect_mapping(/\101/, :regexp_octal_escape) do
378
- s(:regexp_root_expression,
379
- s(:regexp_octal_escape, '\\101'))
380
- end
381
-
382
- RegexpSpec.expect_mapping(/\xFF/n, :regexp_hex_escape) do
383
- s(:regexp_root_expression,
384
- s(:regexp_hex_escape, '\\xFF'))
385
- end
386
-
387
- RegexpSpec.expect_mapping(/\h/, :regexp_hex_type) do
388
- s(:regexp_root_expression,
389
- s(:regexp_hex_type))
390
- end
391
-
392
- RegexpSpec.expect_mapping(/\H/, :regexp_nonhex_type) do
393
- s(:regexp_root_expression,
394
- s(:regexp_nonhex_type))
395
- end
396
-
397
- RegexpSpec.expect_mapping(/\R/, :regexp_linebreak_type) do
398
- s(:regexp_root_expression,
399
- s(:regexp_linebreak_type))
400
- end
401
-
402
- RegexpSpec.expect_mapping(/\X/, :regexp_xgrapheme_type) do
403
- s(:regexp_root_expression,
404
- s(:regexp_xgrapheme_type))
405
- end
406
-
407
- RegexpSpec.expect_mapping(/\}/, :regexp_interval_close_escape) do
408
- s(:regexp_root_expression,
409
- s(:regexp_interval_close_escape))
410
- end
411
-
412
- RegexpSpec.expect_mapping(/\{/, :regexp_interval_open_escape) do
413
- s(:regexp_root_expression,
414
- s(:regexp_interval_open_escape))
415
- end
416
-
417
- RegexpSpec.expect_mapping(/\p{L}/, :regexp_letter_property) do
418
- s(:regexp_root_expression,
419
- s(:regexp_letter_property))
420
- end
421
-
422
- RegexpSpec.expect_mapping(/\-/, :regexp_literal_escape) do
423
- s(:regexp_root_expression,
424
- s(:regexp_literal_escape, '\\-'))
425
- end
426
-
427
- RegexpSpec.expect_mapping(/\ /, :regexp_literal_escape) do
428
- s(:regexp_root_expression,
429
- s(:regexp_literal_escape, '\\ '))
430
- end
431
-
432
- RegexpSpec.expect_mapping(/\#/, :regexp_literal_escape) do
433
- s(:regexp_root_expression,
434
- s(:regexp_literal_escape, '\\#'))
435
- end
436
-
437
- RegexpSpec.expect_mapping(/\:/, :regexp_literal_escape) do
438
- s(:regexp_root_expression,
439
- s(:regexp_literal_escape, '\\:'))
440
- end
441
-
442
- RegexpSpec.expect_mapping(/\</, :regexp_literal_escape) do
443
- s(:regexp_root_expression,
444
- s(:regexp_literal_escape, '\\<'))
445
- end
446
-
447
- RegexpSpec.expect_mapping(/foo/, :regexp_literal_literal) do
448
- s(:regexp_root_expression,
449
- s(:regexp_literal_literal, 'foo'))
450
- end
451
-
452
- RegexpSpec.expect_mapping(/a+/, :regexp_literal_literal) do
453
- s(:regexp_root_expression,
454
- s(:regexp_greedy_one_or_more, 1, -1,
455
- s(:regexp_literal_literal, 'a')))
456
- end
457
-
458
- RegexpSpec.expect_mapping(/(?=a)/, :regexp_lookahead_assertion) do
459
- s(:regexp_root_expression,
460
- s(:regexp_lookahead_assertion,
461
- s(:regexp_literal_literal, 'a')))
462
- end
463
-
464
- RegexpSpec.expect_mapping(/(?<=a)/, :regexp_lookbehind_assertion) do
465
- s(:regexp_root_expression,
466
- s(:regexp_lookbehind_assertion,
467
- s(:regexp_literal_literal, 'a')))
468
- end
469
-
470
- RegexpSpec.expect_mapping(/\G/, :regexp_match_start_anchor) do
471
- s(:regexp_root_expression,
472
- s(:regexp_match_start_anchor))
473
- end
474
-
475
- RegexpSpec.expect_mapping(/(?<foo>a)+/, :regexp_named_group) do
476
- s(:regexp_root_expression,
477
- s(:regexp_greedy_one_or_more, 1, -1,
478
- s(:regexp_named_group, 'foo',
479
- s(:regexp_literal_literal, 'a'))))
480
- end
481
-
482
- RegexpSpec.expect_mapping(/(?<a>)\g<a>/, :regexp_name_call_backref) do
483
- s(:regexp_root_expression,
484
- s(:regexp_named_group, 'a'),
485
- s(:regexp_name_call_backref, '\\g<a>'))
486
- end
487
-
488
- RegexpSpec.expect_mapping(/\n/, :regexp_newline_escape) do
489
- s(:regexp_root_expression,
490
- s(:regexp_newline_escape))
491
- end
492
-
493
- RegexpSpec.expect_mapping(/(?!a)/, :regexp_nlookahead_assertion) do
494
- s(:regexp_root_expression,
495
- s(:regexp_nlookahead_assertion,
496
- s(:regexp_literal_literal, 'a')))
497
- end
498
-
499
- RegexpSpec.expect_mapping(/(?<!a)/, :regexp_nlookbehind_assertion) do
500
- s(:regexp_root_expression,
501
- s(:regexp_nlookbehind_assertion,
502
- s(:regexp_literal_literal, 'a')))
503
- end
504
-
505
- RegexpSpec.expect_mapping(/\D/, :regexp_nondigit_type) do
506
- s(:regexp_root_expression,
507
- s(:regexp_nondigit_type))
508
- end
509
-
510
- RegexpSpec.expect_mapping(/\S/, :regexp_nonspace_type) do
511
- s(:regexp_root_expression,
512
- s(:regexp_nonspace_type))
513
- end
514
-
515
- RegexpSpec.expect_mapping(/\B/, :regexp_nonword_boundary_anchor) do
516
- s(:regexp_root_expression,
517
- s(:regexp_nonword_boundary_anchor))
518
- end
519
-
520
- RegexpSpec.expect_mapping(/\W/, :regexp_nonword_type) do
521
- s(:regexp_root_expression,
522
- s(:regexp_nonword_type))
523
- end
524
-
525
- RegexpSpec.expect_mapping(/\+/, :regexp_one_or_more_escape) do
526
- s(:regexp_root_expression,
527
- s(:regexp_one_or_more_escape))
528
- end
529
-
530
- RegexpSpec.expect_mapping(/(?i:a)+/, :regexp_options_group) do
531
- s(:regexp_root_expression,
532
- s(:regexp_greedy_one_or_more, 1, -1,
533
- s(:regexp_options_group,
534
- {
535
- i: true
536
- },
537
- s(:regexp_literal_literal, 'a'))))
538
- end
539
-
540
- RegexpSpec.expect_mapping(/(?i-x:a)+/, :regexp_options_group) do
541
- s(:regexp_root_expression,
542
- s(:regexp_greedy_one_or_more, 1, -1,
543
- s(:regexp_options_group,
544
- {
545
- i: true,
546
- x: false
547
- },
548
- s(:regexp_literal_literal, 'a'))))
549
- end
550
-
551
- RegexpSpec.expect_mapping(/a(?i)b/, :regexp_options_switch_group) do
552
- s(:regexp_root_expression,
553
- s(:regexp_literal_literal, 'a'),
554
- s(:regexp_options_switch_group, i: true),
555
- s(:regexp_literal_literal, 'b'))
556
- end
557
-
558
- RegexpSpec.expect_mapping(/(?x: #{"\n"} )/, :regexp_whitespace_free_space) do
559
- s(:regexp_root_expression,
560
- s(:regexp_options_group,
561
- {
562
- x: true
563
- },
564
- s(:regexp_whitespace_free_space, " \n ")))
565
- end
566
-
567
- RegexpSpec.expect_mapping(/(?:a)/, :regexp_passive_group) do
568
- s(:regexp_root_expression,
569
- s(:regexp_passive_group,
570
- s(:regexp_literal_literal, 'a')))
571
- end
572
-
573
- RegexpSpec.expect_mapping(/.{1,3}+/, :regexp_possessive_interval) do
574
- s(:regexp_root_expression,
575
- s(:regexp_possessive_interval, 1, 3,
576
- s(:regexp_dot_meta)))
577
- end
578
-
579
- RegexpSpec.expect_mapping(/.++/, :regexp_possessive_one_or_more) do
580
- s(:regexp_root_expression,
581
- s(:regexp_possessive_one_or_more, 1, -1,
582
- s(:regexp_dot_meta)))
583
- end
584
-
585
- RegexpSpec.expect_mapping(/.*+/, :regexp_possessive_zero_or_more) do
586
- s(:regexp_root_expression,
587
- s(:regexp_possessive_zero_or_more, 0, -1,
588
- s(:regexp_dot_meta)))
589
- end
590
-
591
- RegexpSpec.expect_mapping(/.?+/, :regexp_possessive_zero_or_one) do
592
- s(:regexp_root_expression,
593
- s(:regexp_possessive_zero_or_one, 0, 1,
594
- s(:regexp_dot_meta)))
595
- end
596
-
597
- RegexpSpec.expect_mapping(/\P{Print}/, :regexp_print_nonproperty) do
598
- s(:regexp_root_expression,
599
- s(:regexp_print_nonproperty))
600
- end
601
-
602
- RegexpSpec.expect_mapping(/[[:print:]]/, :regexp_print_posixclass) do
603
- s(:regexp_root_expression,
604
- s(:regexp_character_set,
605
- s(:regexp_print_posixclass)))
606
- end
607
-
608
- RegexpSpec.expect_mapping(/[[:^print:]]/, :regexp_print_nonposixclass) do
609
- s(:regexp_root_expression,
610
- s(:regexp_character_set,
611
- s(:regexp_print_nonposixclass)))
612
- end
613
-
614
- RegexpSpec.expect_mapping(/.{1,3}?/, :regexp_reluctant_interval) do
615
- s(:regexp_root_expression,
616
- s(:regexp_reluctant_interval, 1, 3,
617
- s(:regexp_dot_meta)))
618
- end
619
-
620
- RegexpSpec.expect_mapping(/.+?/, :regexp_reluctant_one_or_more) do
621
- s(:regexp_root_expression,
622
- s(:regexp_reluctant_one_or_more, 1, -1,
623
- s(:regexp_dot_meta)))
624
- end
625
-
626
- RegexpSpec.expect_mapping(/.*?/, :regexp_reluctant_zero_or_more) do
627
- s(:regexp_root_expression,
628
- s(:regexp_reluctant_zero_or_more, 0, -1,
629
- s(:regexp_dot_meta)))
630
- end
631
-
632
- RegexpSpec.expect_mapping(/\p{Arabic}/, :regexp_arabic_property) do
633
- s(:regexp_root_expression,
634
- s(:regexp_arabic_property))
635
- end
636
-
637
- RegexpSpec.expect_mapping(/\p{Han}/, :regexp_han_property) do
638
- s(:regexp_root_expression,
639
- s(:regexp_han_property))
640
- end
641
-
642
- RegexpSpec.expect_mapping(/\p{Hangul}/, :regexp_hangul_property) do
643
- s(:regexp_root_expression,
644
- s(:regexp_hangul_property))
645
- end
646
-
647
- RegexpSpec.expect_mapping(/\p{Hiragana}/, :regexp_hiragana_property) do
648
- s(:regexp_root_expression,
649
- s(:regexp_hiragana_property))
650
- end
651
-
652
- RegexpSpec.expect_mapping(/\p{Katakana}/, :regexp_katakana_property) do
653
- s(:regexp_root_expression,
654
- s(:regexp_katakana_property))
655
- end
656
-
657
- RegexpSpec.expect_mapping(/foo|bar/, :regexp_sequence_expression) do
658
- s(:regexp_root_expression,
659
- s(:regexp_alternation_meta,
660
- s(:regexp_sequence_expression,
661
- s(:regexp_literal_literal, 'foo')),
662
- s(:regexp_sequence_expression,
663
- s(:regexp_literal_literal, 'bar'))))
664
- end
665
-
666
- RegexpSpec.expect_mapping(/\]/, :regexp_set_close_escape) do
667
- s(:regexp_root_expression,
668
- s(:regexp_set_close_escape))
669
- end
670
-
671
- RegexpSpec.expect_mapping(/\[/, :regexp_set_open_escape) do
672
- s(:regexp_root_expression,
673
- s(:regexp_set_open_escape))
674
- end
675
-
676
- RegexpSpec.expect_mapping(/\s/, :regexp_space_type) do
677
- s(:regexp_root_expression,
678
- s(:regexp_space_type))
679
- end
680
-
681
- RegexpSpec.expect_mapping(/\t/, :regexp_tab_escape) do
682
- s(:regexp_root_expression,
683
- s(:regexp_tab_escape, '\\t'))
684
- end
685
-
686
- RegexpSpec.expect_mapping(/\b/, :regexp_word_boundary_anchor) do
687
- s(:regexp_root_expression,
688
- s(:regexp_word_boundary_anchor))
689
- end
690
-
691
- RegexpSpec.expect_mapping(/\w/, :regexp_word_type) do
692
- s(:regexp_root_expression,
693
- s(:regexp_word_type))
694
- end
695
-
696
- RegexpSpec.expect_mapping(/\h/, :regexp_hex_type) do
697
- s(:regexp_root_expression,
698
- s(:regexp_hex_type))
699
- end
700
-
701
- RegexpSpec.expect_mapping(/\*/, :regexp_zero_or_more_escape) do
702
- s(:regexp_root_expression,
703
- s(:regexp_zero_or_more_escape))
704
- end