ripper_ruby_parser 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -1
- data/README.md +41 -9
- data/Rakefile +2 -0
- data/lib/ripper_ruby_parser.rb +2 -0
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +23 -45
- data/lib/ripper_ruby_parser/parser.rb +11 -1
- data/lib/ripper_ruby_parser/sexp_handlers.rb +2 -6
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +49 -35
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +78 -39
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +16 -15
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +19 -15
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +138 -30
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +10 -6
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +59 -14
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +56 -32
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +20 -27
- data/lib/ripper_ruby_parser/sexp_processor.rb +40 -10
- data/lib/ripper_ruby_parser/syntax_error.rb +2 -0
- data/lib/ripper_ruby_parser/unescape.rb +32 -11
- data/lib/ripper_ruby_parser/version.rb +3 -1
- data/test/end_to_end/comments_test.rb +2 -0
- data/test/end_to_end/comparison_test.rb +2 -0
- data/test/end_to_end/lib_comparison_test.rb +2 -0
- data/test/end_to_end/line_numbering_test.rb +2 -0
- data/test/end_to_end/samples_comparison_test.rb +5 -29
- data/test/end_to_end/test_comparison_test.rb +2 -0
- data/test/pt_testcase/pt_test.rb +2 -0
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +16 -2
- data/test/ripper_ruby_parser/parser_test.rb +17 -688
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +459 -26
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +152 -82
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +91 -0
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +331 -24
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +88 -0
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +58 -5
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +392 -0
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +174 -12
- data/test/ripper_ruby_parser/sexp_processor_test.rb +8 -18
- data/test/ripper_ruby_parser/version_test.rb +2 -0
- data/test/samples/comments.rb +13 -0
- data/test/samples/conditionals.rb +23 -0
- data/test/samples/loops.rb +36 -0
- data/test/samples/misc.rb +157 -5
- data/test/samples/number.rb +7 -0
- data/test/samples/strings.rb +39 -0
- data/test/test_helper.rb +22 -1
- metadata +18 -12
- data/lib/ripper_ruby_parser/sexp_handlers/arguments.rb +0 -29
- data/lib/ripper_ruby_parser/sexp_handlers/arrays.rb +0 -21
- data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +0 -48
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
|
2
4
|
|
3
5
|
describe RipperRubyParser::Parser do
|
6
|
+
let(:parser) { RipperRubyParser::Parser.new }
|
7
|
+
|
4
8
|
describe '#parse' do
|
5
9
|
describe 'for single assignment' do
|
6
10
|
it 'works when assigning to a namespaced constant' do
|
@@ -17,8 +21,13 @@ describe RipperRubyParser::Parser do
|
|
17
21
|
s(:call, nil, :bar))
|
18
22
|
end
|
19
23
|
|
24
|
+
it 'works with blocks' do
|
25
|
+
'foo = begin; bar; end'.
|
26
|
+
must_be_parsed_as s(:lasgn, :foo, s(:call, nil, :bar))
|
27
|
+
end
|
28
|
+
|
20
29
|
describe 'with a right-hand splat' do
|
21
|
-
|
30
|
+
it 'works in the simple case' do
|
22
31
|
'foo = *bar'.
|
23
32
|
must_be_parsed_as s(:lasgn, :foo,
|
24
33
|
s(:svalue,
|
@@ -26,19 +35,15 @@ describe RipperRubyParser::Parser do
|
|
26
35
|
s(:call, nil, :bar))))
|
27
36
|
end
|
28
37
|
|
29
|
-
|
30
|
-
'foo = bar
|
38
|
+
it 'works with blocks' do
|
39
|
+
'foo = *begin; bar; end'.
|
31
40
|
must_be_parsed_as s(:lasgn, :foo,
|
32
|
-
s(:svalue,
|
33
|
-
s(:array,
|
34
|
-
s(:call, nil, :bar),
|
35
|
-
s(:splat,
|
36
|
-
s(:call, nil, :baz)))))
|
41
|
+
s(:svalue, s(:splat, s(:call, nil, :bar))))
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
45
|
describe 'with several items on the right hand side' do
|
41
|
-
|
46
|
+
it 'works in the simple case' do
|
42
47
|
'foo = bar, baz'.
|
43
48
|
must_be_parsed_as s(:lasgn, :foo,
|
44
49
|
s(:svalue,
|
@@ -46,6 +51,16 @@ describe RipperRubyParser::Parser do
|
|
46
51
|
s(:call, nil, :bar),
|
47
52
|
s(:call, nil, :baz))))
|
48
53
|
end
|
54
|
+
|
55
|
+
it 'works with a splat' do
|
56
|
+
'foo = bar, *baz'.
|
57
|
+
must_be_parsed_as s(:lasgn, :foo,
|
58
|
+
s(:svalue,
|
59
|
+
s(:array,
|
60
|
+
s(:call, nil, :bar),
|
61
|
+
s(:splat,
|
62
|
+
s(:call, nil, :baz)))))
|
63
|
+
end
|
49
64
|
end
|
50
65
|
|
51
66
|
describe 'with an array literal on the right hand side' do
|
@@ -57,6 +72,150 @@ describe RipperRubyParser::Parser do
|
|
57
72
|
s(:call, nil, :baz)))
|
58
73
|
end
|
59
74
|
end
|
75
|
+
|
76
|
+
it 'works when assigning to an instance variable' do
|
77
|
+
'@foo = bar'.
|
78
|
+
must_be_parsed_as s(:iasgn,
|
79
|
+
:@foo,
|
80
|
+
s(:call, nil, :bar))
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'works when assigning to a constant' do
|
84
|
+
'FOO = bar'.
|
85
|
+
must_be_parsed_as s(:cdecl,
|
86
|
+
:FOO,
|
87
|
+
s(:call, nil, :bar))
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'works when assigning to a collection element' do
|
91
|
+
'foo[bar] = baz'.
|
92
|
+
must_be_parsed_as s(:attrasgn,
|
93
|
+
s(:call, nil, :foo),
|
94
|
+
:[]=,
|
95
|
+
s(:call, nil, :bar),
|
96
|
+
s(:call, nil, :baz))
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'works when assigning to an attribute' do
|
100
|
+
'foo.bar = baz'.
|
101
|
+
must_be_parsed_as s(:attrasgn,
|
102
|
+
s(:call, nil, :foo),
|
103
|
+
:bar=,
|
104
|
+
s(:call, nil, :baz))
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'when assigning to a class variable' do
|
108
|
+
it 'works outside a method' do
|
109
|
+
'@@foo = bar'.
|
110
|
+
must_be_parsed_as s(:cvdecl,
|
111
|
+
:@@foo,
|
112
|
+
s(:call, nil, :bar))
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'works inside a method' do
|
116
|
+
'def foo; @@bar = baz; end'.
|
117
|
+
must_be_parsed_as s(:defn,
|
118
|
+
:foo, s(:args),
|
119
|
+
s(:cvasgn, :@@bar, s(:call, nil, :baz)))
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'works inside a method with a receiver' do
|
123
|
+
'def self.foo; @@bar = baz; end'.
|
124
|
+
must_be_parsed_as s(:defs,
|
125
|
+
s(:self),
|
126
|
+
:foo, s(:args),
|
127
|
+
s(:cvasgn, :@@bar, s(:call, nil, :baz)))
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'works inside method arguments' do
|
131
|
+
'def foo(bar = (@@baz = qux)); end'.
|
132
|
+
must_be_parsed_as s(:defn,
|
133
|
+
:foo,
|
134
|
+
s(:args,
|
135
|
+
s(:lasgn, :bar,
|
136
|
+
s(:cvasgn, :@@baz, s(:call, nil, :qux)))),
|
137
|
+
s(:nil))
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'works inside method arguments of a singleton method' do
|
141
|
+
'def self.foo(bar = (@@baz = qux)); end'.
|
142
|
+
must_be_parsed_as s(:defs,
|
143
|
+
s(:self),
|
144
|
+
:foo,
|
145
|
+
s(:args,
|
146
|
+
s(:lasgn, :bar,
|
147
|
+
s(:cvasgn, :@@baz, s(:call, nil, :qux)))),
|
148
|
+
s(:nil))
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'works inside the receiver in a method definition' do
|
152
|
+
'def (bar = (@@baz = qux)).foo; end'.
|
153
|
+
must_be_parsed_as s(:defs,
|
154
|
+
s(:lasgn, :bar,
|
155
|
+
s(:cvdecl, :@@baz,
|
156
|
+
s(:call, nil, :qux))), :foo,
|
157
|
+
s(:args), s(:nil))
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'works when assigning to a global variable' do
|
162
|
+
'$foo = bar'.
|
163
|
+
must_be_parsed_as s(:gasgn,
|
164
|
+
:$foo,
|
165
|
+
s(:call, nil, :bar))
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'with a rescue modifier' do
|
169
|
+
it 'works with assigning a bare method call' do
|
170
|
+
'foo = bar rescue baz'.
|
171
|
+
must_be_parsed_as s(:lasgn, :foo,
|
172
|
+
s(:rescue,
|
173
|
+
s(:call, nil, :bar),
|
174
|
+
s(:resbody, s(:array), s(:call, nil, :baz))))
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'works with a method call with argument' do
|
178
|
+
'foo = bar(baz) rescue qux'.
|
179
|
+
must_be_parsed_as s(:lasgn, :foo,
|
180
|
+
s(:rescue,
|
181
|
+
s(:call, nil, :bar, s(:call, nil, :baz)),
|
182
|
+
s(:resbody, s(:array), s(:call, nil, :qux))))
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'works with a method call with argument without brackets' do
|
186
|
+
expected = if RUBY_VERSION < '2.4.0'
|
187
|
+
s(:rescue,
|
188
|
+
s(:lasgn, :foo, s(:call, nil, :bar, s(:call, nil, :baz))),
|
189
|
+
s(:resbody, s(:array), s(:call, nil, :qux)))
|
190
|
+
else
|
191
|
+
s(:lasgn, :foo,
|
192
|
+
s(:rescue,
|
193
|
+
s(:call, nil, :bar, s(:call, nil, :baz)),
|
194
|
+
s(:resbody, s(:array), s(:call, nil, :qux))))
|
195
|
+
end
|
196
|
+
'foo = bar baz rescue qux'.must_be_parsed_as expected
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'works with a class method call with argument without brackets' do
|
200
|
+
expected = if RUBY_VERSION < '2.4.0'
|
201
|
+
s(:rescue,
|
202
|
+
s(:lasgn, :foo, s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
|
203
|
+
s(:resbody, s(:array), s(:call, nil, :quuz)))
|
204
|
+
else
|
205
|
+
s(:lasgn, :foo,
|
206
|
+
s(:rescue,
|
207
|
+
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
208
|
+
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
209
|
+
end
|
210
|
+
'foo = Bar.baz qux rescue quuz'.
|
211
|
+
must_be_parsed_as expected
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'sets the correct line numbers' do
|
216
|
+
result = parser.parse 'foo = {}'
|
217
|
+
result.line.must_equal 1
|
218
|
+
end
|
60
219
|
end
|
61
220
|
|
62
221
|
describe 'for multiple assignment' do
|
@@ -84,6 +243,155 @@ describe RipperRubyParser::Parser do
|
|
84
243
|
s(:lasgn, :bar)),
|
85
244
|
s(:to_ary, s(:call, nil, :baz)))
|
86
245
|
end
|
246
|
+
|
247
|
+
it 'works with a rescue modifier' do
|
248
|
+
'foo, bar = baz rescue qux'.
|
249
|
+
must_be_parsed_as s(:rescue,
|
250
|
+
s(:masgn,
|
251
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
252
|
+
s(:to_ary, s(:call, nil, :baz))),
|
253
|
+
s(:resbody, s(:array), s(:call, nil, :qux)))
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'works the same number of items on each side' do
|
257
|
+
'foo, bar = baz, qux'.
|
258
|
+
must_be_parsed_as s(:masgn,
|
259
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
260
|
+
s(:array,
|
261
|
+
s(:call, nil, :baz),
|
262
|
+
s(:call, nil, :qux)))
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'works with a single item on the right-hand side' do
|
266
|
+
'foo, bar = baz'.
|
267
|
+
must_be_parsed_as s(:masgn,
|
268
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
269
|
+
s(:to_ary, s(:call, nil, :baz)))
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'works with left-hand splat' do
|
273
|
+
'foo, *bar = baz, qux'.
|
274
|
+
must_be_parsed_as s(:masgn,
|
275
|
+
s(:array, s(:lasgn, :foo), s(:splat, s(:lasgn, :bar))),
|
276
|
+
s(:array,
|
277
|
+
s(:call, nil, :baz),
|
278
|
+
s(:call, nil, :qux)))
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'works with parentheses around the left-hand side' do
|
282
|
+
'(foo, bar) = baz'.
|
283
|
+
must_be_parsed_as s(:masgn,
|
284
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
285
|
+
s(:to_ary, s(:call, nil, :baz)))
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'works with complex destructuring' do
|
289
|
+
'foo, (bar, baz) = qux'.
|
290
|
+
must_be_parsed_as s(:masgn,
|
291
|
+
s(:array,
|
292
|
+
s(:lasgn, :foo),
|
293
|
+
s(:masgn,
|
294
|
+
s(:array,
|
295
|
+
s(:lasgn, :bar),
|
296
|
+
s(:lasgn, :baz)))),
|
297
|
+
s(:to_ary, s(:call, nil, :qux)))
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'works with complex destructuring of the value' do
|
301
|
+
'foo, (bar, baz) = [qux, [quz, quuz]]'.
|
302
|
+
must_be_parsed_as s(:masgn,
|
303
|
+
s(:array,
|
304
|
+
s(:lasgn, :foo),
|
305
|
+
s(:masgn,
|
306
|
+
s(:array,
|
307
|
+
s(:lasgn, :bar),
|
308
|
+
s(:lasgn, :baz)))),
|
309
|
+
s(:to_ary,
|
310
|
+
s(:array,
|
311
|
+
s(:call, nil, :qux),
|
312
|
+
s(:array,
|
313
|
+
s(:call, nil, :quz),
|
314
|
+
s(:call, nil, :quuz)))))
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'works with instance variables' do
|
318
|
+
'@foo, @bar = baz'.
|
319
|
+
must_be_parsed_as s(:masgn,
|
320
|
+
s(:array, s(:iasgn, :@foo), s(:iasgn, :@bar)),
|
321
|
+
s(:to_ary, s(:call, nil, :baz)))
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'works with class variables' do
|
325
|
+
'@@foo, @@bar = baz'.
|
326
|
+
must_be_parsed_as s(:masgn,
|
327
|
+
s(:array, s(:cvdecl, :@@foo), s(:cvdecl, :@@bar)),
|
328
|
+
s(:to_ary, s(:call, nil, :baz)))
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'works with attributes' do
|
332
|
+
'foo.bar, foo.baz = qux'.
|
333
|
+
must_be_parsed_as s(:masgn,
|
334
|
+
s(:array,
|
335
|
+
s(:attrasgn, s(:call, nil, :foo), :bar=),
|
336
|
+
s(:attrasgn, s(:call, nil, :foo), :baz=)),
|
337
|
+
s(:to_ary, s(:call, nil, :qux)))
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'works with collection elements' do
|
341
|
+
'foo[1], bar[2] = baz'.
|
342
|
+
must_be_parsed_as s(:masgn,
|
343
|
+
s(:array,
|
344
|
+
s(:attrasgn,
|
345
|
+
s(:call, nil, :foo), :[]=, s(:lit, 1)),
|
346
|
+
s(:attrasgn,
|
347
|
+
s(:call, nil, :bar), :[]=, s(:lit, 2))),
|
348
|
+
s(:to_ary, s(:call, nil, :baz)))
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'works with constants' do
|
352
|
+
'Foo, Bar = baz'.
|
353
|
+
must_be_parsed_as s(:masgn,
|
354
|
+
s(:array, s(:cdecl, :Foo), s(:cdecl, :Bar)),
|
355
|
+
s(:to_ary, s(:call, nil, :baz)))
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'works with instance variables and splat' do
|
359
|
+
'@foo, *@bar = baz'.
|
360
|
+
must_be_parsed_as s(:masgn,
|
361
|
+
s(:array,
|
362
|
+
s(:iasgn, :@foo),
|
363
|
+
s(:splat, s(:iasgn, :@bar))),
|
364
|
+
s(:to_ary, s(:call, nil, :baz)))
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'works with a right-hand single splat' do
|
368
|
+
'foo, bar = *baz'.
|
369
|
+
must_be_parsed_as s(:masgn,
|
370
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
371
|
+
s(:splat, s(:call, nil, :baz)))
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'works with a splat in a list of values on the right hand' do
|
375
|
+
'foo, bar = baz, *qux'.
|
376
|
+
must_be_parsed_as s(:masgn,
|
377
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
378
|
+
s(:array,
|
379
|
+
s(:call, nil, :baz),
|
380
|
+
s(:splat, s(:call, nil, :qux))))
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'works with a right-hand single splat with begin..end block' do
|
384
|
+
'foo, bar = *begin; baz; end'.
|
385
|
+
must_be_parsed_as s(:masgn,
|
386
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
387
|
+
s(:splat,
|
388
|
+
s(:call, nil, :baz)))
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'sets the correct line numbers' do
|
392
|
+
result = parser.parse 'foo, bar = {}, {}'
|
393
|
+
result.line.must_equal 1
|
394
|
+
end
|
87
395
|
end
|
88
396
|
|
89
397
|
describe 'for assignment to a collection element' do
|
@@ -99,6 +407,88 @@ describe RipperRubyParser::Parser do
|
|
99
407
|
end
|
100
408
|
|
101
409
|
describe 'for operator assignment' do
|
410
|
+
it 'works with +=' do
|
411
|
+
'foo += bar'.
|
412
|
+
must_be_parsed_as s(:lasgn, :foo,
|
413
|
+
s(:call, s(:lvar, :foo),
|
414
|
+
:+,
|
415
|
+
s(:call, nil, :bar)))
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'works with -=' do
|
419
|
+
'foo -= bar'.
|
420
|
+
must_be_parsed_as s(:lasgn, :foo,
|
421
|
+
s(:call, s(:lvar, :foo),
|
422
|
+
:-,
|
423
|
+
s(:call, nil, :bar)))
|
424
|
+
end
|
425
|
+
|
426
|
+
it 'works with *=' do
|
427
|
+
'foo *= bar'.
|
428
|
+
must_be_parsed_as s(:lasgn, :foo,
|
429
|
+
s(:call, s(:lvar, :foo),
|
430
|
+
:*,
|
431
|
+
s(:call, nil, :bar)))
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'works with /=' do
|
435
|
+
'foo /= bar'.
|
436
|
+
must_be_parsed_as s(:lasgn, :foo,
|
437
|
+
s(:call,
|
438
|
+
s(:lvar, :foo), :/,
|
439
|
+
s(:call, nil, :bar)))
|
440
|
+
end
|
441
|
+
|
442
|
+
it 'works with ||=' do
|
443
|
+
'foo ||= bar'.
|
444
|
+
must_be_parsed_as s(:op_asgn_or,
|
445
|
+
s(:lvar, :foo),
|
446
|
+
s(:lasgn, :foo,
|
447
|
+
s(:call, nil, :bar)))
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'works when assigning to an instance variable' do
|
451
|
+
'@foo += bar'.
|
452
|
+
must_be_parsed_as s(:iasgn, :@foo,
|
453
|
+
s(:call,
|
454
|
+
s(:ivar, :@foo), :+,
|
455
|
+
s(:call, nil, :bar)))
|
456
|
+
end
|
457
|
+
|
458
|
+
it 'works when assigning to a collection element' do
|
459
|
+
'foo[bar] += baz'.
|
460
|
+
must_be_parsed_as s(:op_asgn1,
|
461
|
+
s(:call, nil, :foo),
|
462
|
+
s(:arglist, s(:call, nil, :bar)),
|
463
|
+
:+,
|
464
|
+
s(:call, nil, :baz))
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'works with ||= when assigning to a collection element' do
|
468
|
+
'foo[bar] ||= baz'.
|
469
|
+
must_be_parsed_as s(:op_asgn1,
|
470
|
+
s(:call, nil, :foo),
|
471
|
+
s(:arglist, s(:call, nil, :bar)),
|
472
|
+
:"||",
|
473
|
+
s(:call, nil, :baz))
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'works when assigning to an attribute' do
|
477
|
+
'foo.bar += baz'.
|
478
|
+
must_be_parsed_as s(:op_asgn2,
|
479
|
+
s(:call, nil, :foo),
|
480
|
+
:bar=, :+,
|
481
|
+
s(:call, nil, :baz))
|
482
|
+
end
|
483
|
+
|
484
|
+
it 'works with ||= when assigning to an attribute' do
|
485
|
+
'foo.bar ||= baz'.
|
486
|
+
must_be_parsed_as s(:op_asgn2,
|
487
|
+
s(:call, nil, :foo),
|
488
|
+
:bar=, :'||',
|
489
|
+
s(:call, nil, :baz))
|
490
|
+
end
|
491
|
+
|
102
492
|
describe 'assigning to a collection element' do
|
103
493
|
it 'handles multiple indices' do
|
104
494
|
'foo[bar, baz] += qux'.
|
@@ -111,31 +501,74 @@ describe RipperRubyParser::Parser do
|
|
111
501
|
s(:call, nil, :qux))
|
112
502
|
end
|
113
503
|
|
114
|
-
it 'works with
|
504
|
+
it 'works with boolean operators' do
|
115
505
|
'foo &&= bar'.
|
116
506
|
must_be_parsed_as s(:op_asgn_and,
|
117
507
|
s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
|
118
508
|
end
|
119
|
-
end
|
120
|
-
end
|
121
509
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
must_be_parsed_as s(:masgn,
|
127
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
128
|
-
s(:splat, s(:call, nil, :baz)))
|
510
|
+
it 'works with boolean operators and blocks' do
|
511
|
+
'foo &&= begin; bar; end'.
|
512
|
+
must_be_parsed_as s(:op_asgn_and,
|
513
|
+
s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
|
129
514
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
s(:
|
135
|
-
s(:call, nil, :baz),
|
136
|
-
s(:splat, s(:call, nil, :qux))))
|
515
|
+
|
516
|
+
it 'works with arithmetic operators and blocks' do
|
517
|
+
'foo += begin; bar; end'.
|
518
|
+
must_be_parsed_as s(:lasgn, :foo,
|
519
|
+
s(:call, s(:lvar, :foo), :+, s(:call, nil, :bar)))
|
137
520
|
end
|
138
521
|
end
|
139
522
|
end
|
523
|
+
|
524
|
+
describe 'when extra compatibility is turned on' do
|
525
|
+
it 'works with a bare method call' do
|
526
|
+
'foo = bar'.
|
527
|
+
must_be_parsed_as s(:lasgn, :foo, s(:call, nil, :bar)),
|
528
|
+
extra_compatible: true
|
529
|
+
end
|
530
|
+
|
531
|
+
it 'works with a literal' do
|
532
|
+
'foo = 0'.
|
533
|
+
must_be_parsed_as s(:lasgn, :foo, s(:lit, 0)),
|
534
|
+
extra_compatible: true
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'works with a bare method call with rescue modifier' do
|
538
|
+
'foo = bar rescue baz'.
|
539
|
+
must_be_parsed_as s(:lasgn, :foo,
|
540
|
+
s(:rescue,
|
541
|
+
s(:call, nil, :bar),
|
542
|
+
s(:resbody, s(:array), s(:call, nil, :baz)))),
|
543
|
+
extra_compatible: true
|
544
|
+
end
|
545
|
+
|
546
|
+
it 'works with a method call with argument with bracket with rescue modifier' do
|
547
|
+
'foo = bar(baz) rescue qux'.
|
548
|
+
must_be_parsed_as s(:lasgn, :foo,
|
549
|
+
s(:rescue,
|
550
|
+
s(:call, nil, :bar, s(:call, nil, :baz)),
|
551
|
+
s(:resbody, s(:array), s(:call, nil, :qux)))),
|
552
|
+
extra_compatible: true
|
553
|
+
end
|
554
|
+
|
555
|
+
it 'works with a method call with argument without bracket with rescue modifier' do
|
556
|
+
'foo = bar baz rescue qux'.
|
557
|
+
must_be_parsed_as s(:rescue,
|
558
|
+
s(:lasgn, :foo, s(:call, nil, :bar, s(:call, nil, :baz))),
|
559
|
+
s(:resbody, s(:array), s(:call, nil, :qux))),
|
560
|
+
extra_compatible: true
|
561
|
+
end
|
562
|
+
|
563
|
+
it 'works with a class method call with argument without bracket with rescue modifier' do
|
564
|
+
'foo = Bar.baz qux rescue quuz'.
|
565
|
+
must_be_parsed_as s(:rescue,
|
566
|
+
s(:lasgn,
|
567
|
+
:foo,
|
568
|
+
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
|
569
|
+
s(:resbody, s(:array), s(:call, nil, :quuz))),
|
570
|
+
extra_compatible: true
|
571
|
+
end
|
572
|
+
end
|
140
573
|
end
|
141
574
|
end
|