parser 2.3.0.2 → 2.3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3738,6 +3738,18 @@ class TestParser < Minitest::Test
3738
3738
  ALL_VERSIONS - %w(1.8))
3739
3739
  end
3740
3740
 
3741
+ def test_space_args_hash_literal_then_block
3742
+ # This code only parses if the lexer enters expr_endarg state correctly
3743
+ assert_parses(
3744
+ s(:block,
3745
+ s(:send, nil, :f, s(:int, 1), s(:hash, s(:pair, s(:int, 1), s(:int, 2)))),
3746
+ s(:args),
3747
+ s(:int, 1)),
3748
+ %q{f 1, {1 => 2} {1}},
3749
+ %q{},
3750
+ ALL_VERSIONS)
3751
+ end
3752
+
3741
3753
  def test_space_args_arg_call
3742
3754
  assert_parses(
3743
3755
  s(:send, nil, :fun,
@@ -255,4 +255,21 @@ __ENCODING__
255
255
  assert_equal ['# foo'],
256
256
  associations[ast].map(&:text)
257
257
  end
258
+
259
+ def test_associate_inside_heredoc
260
+ ast, associations = associate(<<-END)
261
+ <<x
262
+ \#{
263
+ foo # bar
264
+ }
265
+ x
266
+ END
267
+
268
+ begin_node = ast.children[0]
269
+ send_node = begin_node.children[0]
270
+
271
+ assert_equal 1, associations.size
272
+ assert_equal ['# bar'],
273
+ associations[send_node].map(&:text)
274
+ end
258
275
  end
@@ -55,6 +55,26 @@ class TestSourceRange < Minitest::Test
55
55
  assert !sr2.disjoint?(sr3)
56
56
  end
57
57
 
58
+ def test_overlaps
59
+ sr1 = Parser::Source::Range.new(@buf, 1, 3)
60
+ sr2 = Parser::Source::Range.new(@buf, 2, 6)
61
+ sr3 = Parser::Source::Range.new(@buf, 5, 8)
62
+
63
+ assert !sr1.overlaps?(sr3)
64
+ assert sr1.overlaps?(sr2)
65
+ assert sr2.overlaps?(sr3)
66
+ end
67
+
68
+ def test_empty
69
+ sr1 = Parser::Source::Range.new(@buf, 1, 3)
70
+ sr2 = Parser::Source::Range.new(@buf, 2, 2)
71
+ sr3 = Parser::Source::Range.new(@buf, 7, 8)
72
+
73
+ assert !sr1.empty?
74
+ assert sr2.empty?
75
+ assert !sr3.empty?
76
+ end
77
+
58
78
  def test_line
59
79
  sr = Parser::Source::Range.new(@buf, 7, 8)
60
80
  assert_equal 2, sr.line
@@ -56,16 +56,262 @@ class TestSourceRewriter < Minitest::Test
56
56
  process
57
57
  end
58
58
 
59
- def test_multiple_insertions_at_same_location
60
- assert_equal '<([foo] bar) baz>',
61
- @rewriter.
62
- insert_before(range(0, 11), '<').
63
- insert_after( range(0, 11), '>').
64
- insert_before(range(0, 7), '(').
65
- insert_after( range(0, 7), ')').
66
- insert_before(range(0, 3), '[').
67
- insert_after( range(0, 3), ']').
68
- process
59
+ #
60
+ # Merging/clobbering of overlapping edits
61
+ #
62
+
63
+ def test_insertion_just_before_replace
64
+ assert_equal 'foostrawberry jam---bar baz',
65
+ @rewriter.
66
+ replace(range(3, 1), '---').
67
+ insert_before(range(3, 1), 'strawberry jam').
68
+ process
69
+ end
70
+
71
+ def test_insertion_just_after_replace
72
+ assert_equal 'foo---strawberry jam baz',
73
+ @rewriter.
74
+ replace(range(3, 4), '---').
75
+ insert_after(range(3, 4), 'strawberry jam').
76
+ process
77
+ end
78
+
79
+ def test_insertion_just_before_remove
80
+ assert_equal 'foostrawberry jambar baz',
81
+ @rewriter.
82
+ remove(range(3, 1)).
83
+ insert_before(range(3, 1), 'strawberry jam').
84
+ process
85
+ end
86
+
87
+ def test_insertion_just_after_remove
88
+ assert_equal 'foostrawberry jam baz',
89
+ @rewriter.
90
+ remove(range(3, 4)).
91
+ insert_after(range(3, 4), 'strawberry jam').
92
+ process
93
+ end
94
+
95
+ def test_insertion_just_before_replace_at_buffer_start
96
+ assert_equal 'strawberry jam--- bar baz',
97
+ @rewriter.
98
+ replace(range(0, 3), '---').
99
+ insert_before(range(0, 1), 'strawberry jam').
100
+ process
101
+ end
102
+
103
+ def test_insertion_just_after_replace_at_buffer_end
104
+ assert_equal 'foo bar ---strawberry jam',
105
+ @rewriter.
106
+ replace(range(8, 3), '---').
107
+ insert_after(range(9, 2), 'strawberry jam').
108
+ process
109
+ end
110
+
111
+ def test_insertion_just_before_remove_at_buffer_start
112
+ assert_equal 'strawberry bar baz',
113
+ @rewriter.
114
+ remove(range(0, 3)).
115
+ insert_before(range(0, 1), 'strawberry').
116
+ process
117
+ end
118
+
119
+ def test_insertion_just_after_remove_at_buffer_end
120
+ assert_equal 'foo bar strawberry',
121
+ @rewriter.
122
+ remove(range(8, 3)).
123
+ insert_after(range(10, 1), 'strawberry').
124
+ process
125
+ end
126
+
127
+ def test_multiple_insertions_at_same_location_clobber
128
+ silence_diagnostics
129
+
130
+ assert_raises Parser::ClobberingError do
131
+ @rewriter.
132
+ insert_before(range(0, 11), '<').
133
+ insert_after( range(0, 11), '>').
134
+ insert_before(range(0, 7), '(')
135
+ end
136
+ end
137
+
138
+ def test_insertion_within_replace_clobber
139
+ silence_diagnostics
140
+
141
+ assert_raises Parser::ClobberingError do
142
+ @rewriter.
143
+ replace(range(3, 2), '<').
144
+ insert_after(range(3, 1), '>')
145
+ end
146
+ end
147
+
148
+ def test_insertion_within_remove_clobber
149
+ silence_diagnostics
150
+
151
+ assert_raises Parser::ClobberingError do
152
+ @rewriter.
153
+ remove(range(3, 2)).
154
+ insert_after(range(3, 1), '>')
155
+ end
156
+ end
157
+
158
+ def test_replace_overlapping_insertion_clobber
159
+ silence_diagnostics
160
+
161
+ assert_raises Parser::ClobberingError do
162
+ @rewriter.
163
+ insert_after(range(3, 1), '>').
164
+ replace(range(3, 2), '<')
165
+ end
166
+ end
167
+
168
+ def test_remove_overlapping_insertion_clobber
169
+ silence_diagnostics
170
+
171
+ assert_raises Parser::ClobberingError do
172
+ @rewriter.
173
+ insert_after(range(3, 1), '>').
174
+ remove(range(3, 2))
175
+ end
176
+ end
177
+
178
+ def test_insertion_on_merged_insertion_clobber
179
+ # 2 insertions at the same point clobber each other, even if the 1st one
180
+ # was merged with an adjacent edit, and even if the same text is being
181
+ # inserted
182
+
183
+ silence_diagnostics
184
+
185
+ assert_raises Parser::ClobberingError do
186
+ @rewriter.
187
+ insert_before(range(3, 1), '>').
188
+ remove(range(3, 2)).
189
+ insert_after(range(2, 1), '>')
190
+ end
191
+ end
192
+
193
+ def test_insertion_merge_with_overlapping_replace
194
+ assert_equal 'fo abc bar baz',
195
+ @rewriter.
196
+ insert_before(range(3, 1), 'abc').
197
+ replace(range(2, 2), ' abc ').
198
+ process
199
+ end
200
+
201
+ def test_replace_merge_with_overlapped_insertion
202
+ assert_equal 'fo abc bar baz',
203
+ @rewriter.
204
+ replace(range(2, 2), ' abc ').
205
+ insert_before(range(3, 1), 'abc').
206
+ process
207
+ end
208
+
209
+ def test_replace_same_begin_larger_than_replaced_range_matching
210
+ assert_equal 'foo supercalifragilistic baz',
211
+ @rewriter.
212
+ replace(range(4, 3), 'super').
213
+ replace(range(4, 3), 'supercalifragilistic').
214
+ process
215
+ end
216
+
217
+ def test_replace_same_begin_larger_than_replaced_range_non_matching
218
+ silence_diagnostics
219
+
220
+ assert_raises Parser::ClobberingError do
221
+ @rewriter.
222
+ replace(range(4, 3), 'super!').
223
+ replace(range(4, 3), 'supercalifragilistic')
224
+ end
225
+ end
226
+
227
+ def test_overlapping_replace_left_smaller_than_replaced_matching
228
+ assert_equal 'superbaz',
229
+ @rewriter.
230
+ replace(range(0, 7), 'super').
231
+ replace(range(2, 6), 'per').
232
+ process
233
+ end
234
+
235
+ def test_overlapping_replace_left_smaller_than_replaced_non_matching
236
+ silence_diagnostics
237
+
238
+ assert_raises Parser::ClobberingError do
239
+ @rewriter.
240
+ replace(range(0, 7), 'super').
241
+ replace(range(2, 8), 'perk')
242
+ end
243
+ end
244
+
245
+ def test_overlapping_replace_left_larger_right_smaller_matching
246
+ assert_equal 'foods baz',
247
+ @rewriter.
248
+ replace(range(1, 3), 'oods ').
249
+ replace(range(3, 6), 'ds b').
250
+ process
251
+ end
252
+
253
+ def test_overlapping_replace_left_larger_right_larger_matching
254
+ assert_equal 'foods abcdefghijklm',
255
+ @rewriter.
256
+ replace(range(1, 3), 'oods ').
257
+ replace(range(3, 8), 'ds abcdefghijklm').
258
+ process
259
+ end
260
+
261
+ def test_overlapping_replace_left_larger_right_smaller_non_matching
262
+ silence_diagnostics
263
+
264
+ assert_raises Parser::ClobberingError do
265
+ @rewriter.
266
+ replace(range(1, 3), 'oods ').
267
+ replace(range(3, 6), 'ds')
268
+ end
269
+ end
270
+
271
+ def test_overlapping_replace_left_larger_right_larger_non_matching
272
+ silence_diagnostics
273
+
274
+ assert_raises Parser::ClobberingError do
275
+ @rewriter.
276
+ replace(range(1, 3), 'oods b').
277
+ replace(range(3, 8), 'ds abcdefghijklm')
278
+ end
279
+ end
280
+
281
+ def test_subsuming_replace_both_smaller_matching
282
+ assert_equal 'food baz',
283
+ @rewriter.
284
+ replace(range(0, 7), 'food').
285
+ replace(range(3, 3), 'd').
286
+ process
287
+ end
288
+
289
+ def test_subsuming_replace_both_smaller_non_matching
290
+ silence_diagnostics
291
+
292
+ assert_raises Parser::ClobberingError do
293
+ @rewriter.
294
+ replace(range(0, 7), 'foo').
295
+ replace(range(3, 3), 'd')
296
+ end
297
+ end
298
+
299
+ def test_subsuming_replace_both_larger_matching
300
+ assert_equal 'foo barr baz',
301
+ @rewriter.
302
+ replace(range(0, 7), 'foo barr').
303
+ replace(range(3, 3), ' bar').
304
+ process
305
+ end
306
+
307
+ def test_subsuming_replace_both_larger_non_matching
308
+ silence_diagnostics
309
+
310
+ assert_raises Parser::ClobberingError do
311
+ @rewriter.
312
+ replace(range(0, 7), 'foo barr').
313
+ replace(range(3, 3), ' bar ')
314
+ end
69
315
  end
70
316
 
71
317
  def test_clobber
@@ -111,6 +357,7 @@ class TestSourceRewriter < Minitest::Test
111
357
  assert rescued
112
358
  end
113
359
 
360
+
114
361
  def test_overlapping_delete
115
362
  assert_equal 'faz',
116
363
  @rewriter.
@@ -147,6 +394,18 @@ class TestSourceRewriter < Minitest::Test
147
394
  process
148
395
  end
149
396
 
397
+ def test_equivalent_delete_insert_replace
398
+ # A deletion + insertion just before or after the deleted range is
399
+ # identical in every way to a replacement! So logically, they shouldn't
400
+ # conflict.
401
+ assert_equal 'tin bar baz',
402
+ @rewriter.
403
+ remove(range(0, 3)). # ' bar baz'
404
+ insert_before(range(0, 1), 'tin'). # 'tin bar baz'
405
+ replace(range(0, 3), 'tin').
406
+ process
407
+ end
408
+
150
409
  def test_transaction_returns_self
151
410
  assert_equal @rewriter, @rewriter.transaction {}
152
411
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.2
4
+ version: 2.3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast