ripper_ruby_parser 1.7.2 → 1.10.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 +50 -0
- data/README.md +4 -4
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
- data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
- data/lib/ripper_ruby_parser/unescape.rb +63 -22
- data/lib/ripper_ruby_parser/version.rb +1 -1
- metadata +140 -79
- data/Rakefile +0 -33
- data/test/end_to_end/comments_test.rb +0 -59
- data/test/end_to_end/comparison_test.rb +0 -104
- data/test/end_to_end/lib_comparison_test.rb +0 -18
- data/test/end_to_end/line_numbering_test.rb +0 -31
- data/test/end_to_end/samples_comparison_test.rb +0 -13
- data/test/end_to_end/test_comparison_test.rb +0 -18
- data/test/pt_testcase/pt_test.rb +0 -44
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
- data/test/ripper_ruby_parser/parser_test.rb +0 -576
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
- data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
- data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
- data/test/ripper_ruby_parser/version_test.rb +0 -7
- data/test/samples/assignment.rb +0 -22
- data/test/samples/comments.rb +0 -13
- data/test/samples/conditionals.rb +0 -23
- data/test/samples/lambdas.rb +0 -5
- data/test/samples/loops.rb +0 -36
- data/test/samples/misc.rb +0 -285
- data/test/samples/number.rb +0 -9
- data/test/samples/operators.rb +0 -18
- data/test/samples/strings.rb +0 -147
- data/test/test_helper.rb +0 -111
@@ -1,597 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
describe RipperRubyParser::Parser do
|
6
|
-
let(:parser) { RipperRubyParser::Parser.new }
|
7
|
-
|
8
|
-
describe "#parse" do
|
9
|
-
describe "for single assignment" do
|
10
|
-
it "works when assigning to a namespaced constant" do
|
11
|
-
_("Foo::Bar = baz")
|
12
|
-
.must_be_parsed_as s(:cdecl,
|
13
|
-
s(:colon2, s(:const, :Foo), :Bar),
|
14
|
-
s(:call, nil, :baz))
|
15
|
-
end
|
16
|
-
|
17
|
-
it "works when assigning to constant in the root namespace" do
|
18
|
-
_("::Foo = bar")
|
19
|
-
.must_be_parsed_as s(:cdecl,
|
20
|
-
s(:colon3, :Foo),
|
21
|
-
s(:call, nil, :bar))
|
22
|
-
end
|
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
|
-
|
29
|
-
describe "with a right-hand splat" do
|
30
|
-
it "works in the simple case" do
|
31
|
-
_("foo = *bar")
|
32
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
33
|
-
s(:svalue,
|
34
|
-
s(:splat,
|
35
|
-
s(:call, nil, :bar))))
|
36
|
-
end
|
37
|
-
|
38
|
-
it "works with blocks" do
|
39
|
-
_("foo = *begin; bar; end")
|
40
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
41
|
-
s(:svalue, s(:splat, s(:call, nil, :bar))))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "with several items on the right hand side" do
|
46
|
-
it "works in the simple case" do
|
47
|
-
_("foo = bar, baz")
|
48
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
49
|
-
s(:svalue,
|
50
|
-
s(:array,
|
51
|
-
s(:call, nil, :bar),
|
52
|
-
s(:call, nil, :baz))))
|
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
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "with an array literal on the right hand side" do
|
67
|
-
specify do
|
68
|
-
_("foo = [bar, baz]")
|
69
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
70
|
-
s(:array,
|
71
|
-
s(:call, nil, :bar),
|
72
|
-
s(:call, nil, :baz)))
|
73
|
-
end
|
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
|
-
it "works when safe-assigning to an attribute" do
|
108
|
-
_("foo&.bar = baz")
|
109
|
-
.must_be_parsed_as s(:safe_attrasgn,
|
110
|
-
s(:call, nil, :foo),
|
111
|
-
:bar=,
|
112
|
-
s(:call, nil, :baz))
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "when assigning to a class variable" do
|
116
|
-
it "works outside a method" do
|
117
|
-
_("@@foo = bar")
|
118
|
-
.must_be_parsed_as s(:cvdecl,
|
119
|
-
:@@foo,
|
120
|
-
s(:call, nil, :bar))
|
121
|
-
end
|
122
|
-
|
123
|
-
it "works inside a method" do
|
124
|
-
_("def foo; @@bar = baz; end")
|
125
|
-
.must_be_parsed_as s(:defn,
|
126
|
-
:foo, s(:args),
|
127
|
-
s(:cvasgn, :@@bar, s(:call, nil, :baz)))
|
128
|
-
end
|
129
|
-
|
130
|
-
it "works inside a method with a receiver" do
|
131
|
-
_("def self.foo; @@bar = baz; end")
|
132
|
-
.must_be_parsed_as s(:defs,
|
133
|
-
s(:self),
|
134
|
-
:foo, s(:args),
|
135
|
-
s(:cvasgn, :@@bar, s(:call, nil, :baz)))
|
136
|
-
end
|
137
|
-
|
138
|
-
it "works inside method arguments" do
|
139
|
-
_("def foo(bar = (@@baz = qux)); end")
|
140
|
-
.must_be_parsed_as s(:defn,
|
141
|
-
:foo,
|
142
|
-
s(:args,
|
143
|
-
s(:lasgn, :bar,
|
144
|
-
s(:cvasgn, :@@baz, s(:call, nil, :qux)))),
|
145
|
-
s(:nil))
|
146
|
-
end
|
147
|
-
|
148
|
-
it "works inside method arguments of a singleton method" do
|
149
|
-
_("def self.foo(bar = (@@baz = qux)); end")
|
150
|
-
.must_be_parsed_as s(:defs,
|
151
|
-
s(:self),
|
152
|
-
:foo,
|
153
|
-
s(:args,
|
154
|
-
s(:lasgn, :bar,
|
155
|
-
s(:cvasgn, :@@baz, s(:call, nil, :qux)))),
|
156
|
-
s(:nil))
|
157
|
-
end
|
158
|
-
|
159
|
-
it "works inside the receiver in a method definition" do
|
160
|
-
_("def (bar = (@@baz = qux)).foo; end")
|
161
|
-
.must_be_parsed_as s(:defs,
|
162
|
-
s(:lasgn, :bar,
|
163
|
-
s(:cvdecl, :@@baz,
|
164
|
-
s(:call, nil, :qux))), :foo,
|
165
|
-
s(:args), s(:nil))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
it "works when assigning to a global variable" do
|
170
|
-
_("$foo = bar")
|
171
|
-
.must_be_parsed_as s(:gasgn,
|
172
|
-
:$foo,
|
173
|
-
s(:call, nil, :bar))
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "with a rescue modifier" do
|
177
|
-
it "works with assigning a bare method call" do
|
178
|
-
_("foo = bar rescue baz")
|
179
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
180
|
-
s(:rescue,
|
181
|
-
s(:call, nil, :bar),
|
182
|
-
s(:resbody, s(:array), s(:call, nil, :baz))))
|
183
|
-
end
|
184
|
-
|
185
|
-
it "works with a method call with argument" do
|
186
|
-
_("foo = bar(baz) rescue qux")
|
187
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
188
|
-
s(:rescue,
|
189
|
-
s(:call, nil, :bar, s(:call, nil, :baz)),
|
190
|
-
s(:resbody, s(:array), s(:call, nil, :qux))))
|
191
|
-
end
|
192
|
-
|
193
|
-
it "works with a method call with argument without brackets" do
|
194
|
-
_("foo = bar baz rescue qux")
|
195
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
196
|
-
s(:rescue,
|
197
|
-
s(:call, nil, :bar, s(:call, nil, :baz)),
|
198
|
-
s(:resbody, s(:array), s(:call, nil, :qux))))
|
199
|
-
end
|
200
|
-
|
201
|
-
it "works with a class method call with argument without brackets" do
|
202
|
-
_("foo = Bar.baz qux rescue quuz")
|
203
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
204
|
-
s(:rescue,
|
205
|
-
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
206
|
-
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
it "sets the correct line numbers" do
|
211
|
-
result = parser.parse "foo = {}"
|
212
|
-
_(result.line).must_equal 1
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "for multiple assignment" do
|
217
|
-
specify do
|
218
|
-
_("foo, * = bar")
|
219
|
-
.must_be_parsed_as s(:masgn,
|
220
|
-
s(:array, s(:lasgn, :foo), s(:splat)),
|
221
|
-
s(:to_ary, s(:call, nil, :bar)))
|
222
|
-
end
|
223
|
-
|
224
|
-
specify do
|
225
|
-
_("(foo, *bar) = baz")
|
226
|
-
.must_be_parsed_as s(:masgn,
|
227
|
-
s(:array,
|
228
|
-
s(:lasgn, :foo),
|
229
|
-
s(:splat, s(:lasgn, :bar))),
|
230
|
-
s(:to_ary, s(:call, nil, :baz)))
|
231
|
-
end
|
232
|
-
|
233
|
-
specify do
|
234
|
-
_("*foo, bar = baz")
|
235
|
-
.must_be_parsed_as s(:masgn,
|
236
|
-
s(:array,
|
237
|
-
s(:splat, s(:lasgn, :foo)),
|
238
|
-
s(:lasgn, :bar)),
|
239
|
-
s(:to_ary, s(:call, nil, :baz)))
|
240
|
-
end
|
241
|
-
|
242
|
-
it "works with blocks" do
|
243
|
-
_("foo, bar = begin; baz; end")
|
244
|
-
.must_be_parsed_as s(:masgn,
|
245
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
246
|
-
s(:to_ary, s(:call, nil, :baz)))
|
247
|
-
end
|
248
|
-
|
249
|
-
it "works with a rescue modifier" do
|
250
|
-
expected = if RUBY_VERSION < "2.7.0"
|
251
|
-
s(:rescue,
|
252
|
-
s(:masgn,
|
253
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
254
|
-
s(:to_ary, s(:call, nil, :baz))),
|
255
|
-
s(:resbody, s(:array), s(:call, nil, :qux)))
|
256
|
-
else
|
257
|
-
s(:masgn,
|
258
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
259
|
-
s(:to_ary,
|
260
|
-
s(:rescue,
|
261
|
-
s(:call, nil, :baz),
|
262
|
-
s(:resbody, s(:array), s(:call, nil, :qux)))))
|
263
|
-
end
|
264
|
-
|
265
|
-
_("foo, bar = baz rescue qux")
|
266
|
-
.must_be_parsed_as expected
|
267
|
-
end
|
268
|
-
|
269
|
-
it "works the same number of items on each side" do
|
270
|
-
_("foo, bar = baz, qux")
|
271
|
-
.must_be_parsed_as s(:masgn,
|
272
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
273
|
-
s(:array,
|
274
|
-
s(:call, nil, :baz),
|
275
|
-
s(:call, nil, :qux)))
|
276
|
-
end
|
277
|
-
|
278
|
-
it "works with a single item on the right-hand side" do
|
279
|
-
_("foo, bar = baz")
|
280
|
-
.must_be_parsed_as s(:masgn,
|
281
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
282
|
-
s(:to_ary, s(:call, nil, :baz)))
|
283
|
-
end
|
284
|
-
|
285
|
-
it "works with left-hand splat" do
|
286
|
-
_("foo, *bar = baz, qux")
|
287
|
-
.must_be_parsed_as s(:masgn,
|
288
|
-
s(:array, s(:lasgn, :foo), s(:splat, s(:lasgn, :bar))),
|
289
|
-
s(:array,
|
290
|
-
s(:call, nil, :baz),
|
291
|
-
s(:call, nil, :qux)))
|
292
|
-
end
|
293
|
-
|
294
|
-
it "works with parentheses around the left-hand side" do
|
295
|
-
_("(foo, bar) = baz")
|
296
|
-
.must_be_parsed_as s(:masgn,
|
297
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
298
|
-
s(:to_ary, s(:call, nil, :baz)))
|
299
|
-
end
|
300
|
-
|
301
|
-
it "works with complex destructuring" do
|
302
|
-
_("foo, (bar, baz) = qux")
|
303
|
-
.must_be_parsed_as s(:masgn,
|
304
|
-
s(:array,
|
305
|
-
s(:lasgn, :foo),
|
306
|
-
s(:masgn,
|
307
|
-
s(:array,
|
308
|
-
s(:lasgn, :bar),
|
309
|
-
s(:lasgn, :baz)))),
|
310
|
-
s(:to_ary, s(:call, nil, :qux)))
|
311
|
-
end
|
312
|
-
|
313
|
-
it "works with complex destructuring of the value" do
|
314
|
-
_("foo, (bar, baz) = [qux, [quz, quuz]]")
|
315
|
-
.must_be_parsed_as s(:masgn,
|
316
|
-
s(:array,
|
317
|
-
s(:lasgn, :foo),
|
318
|
-
s(:masgn,
|
319
|
-
s(:array,
|
320
|
-
s(:lasgn, :bar),
|
321
|
-
s(:lasgn, :baz)))),
|
322
|
-
s(:to_ary,
|
323
|
-
s(:array,
|
324
|
-
s(:call, nil, :qux),
|
325
|
-
s(:array,
|
326
|
-
s(:call, nil, :quz),
|
327
|
-
s(:call, nil, :quuz)))))
|
328
|
-
end
|
329
|
-
|
330
|
-
it "works with destructuring with multiple levels" do
|
331
|
-
_("((foo, bar)) = baz")
|
332
|
-
.must_be_parsed_as s(:masgn,
|
333
|
-
s(:array,
|
334
|
-
s(:masgn,
|
335
|
-
s(:array,
|
336
|
-
s(:lasgn, :foo),
|
337
|
-
s(:lasgn, :bar)))),
|
338
|
-
s(:to_ary, s(:call, nil, :baz)))
|
339
|
-
end
|
340
|
-
|
341
|
-
it "works with instance variables" do
|
342
|
-
_("@foo, @bar = baz")
|
343
|
-
.must_be_parsed_as s(:masgn,
|
344
|
-
s(:array, s(:iasgn, :@foo), s(:iasgn, :@bar)),
|
345
|
-
s(:to_ary, s(:call, nil, :baz)))
|
346
|
-
end
|
347
|
-
|
348
|
-
it "works with class variables" do
|
349
|
-
_("@@foo, @@bar = baz")
|
350
|
-
.must_be_parsed_as s(:masgn,
|
351
|
-
s(:array, s(:cvdecl, :@@foo), s(:cvdecl, :@@bar)),
|
352
|
-
s(:to_ary, s(:call, nil, :baz)))
|
353
|
-
end
|
354
|
-
|
355
|
-
it "works with attributes" do
|
356
|
-
_("foo.bar, foo.baz = qux")
|
357
|
-
.must_be_parsed_as s(:masgn,
|
358
|
-
s(:array,
|
359
|
-
s(:attrasgn, s(:call, nil, :foo), :bar=),
|
360
|
-
s(:attrasgn, s(:call, nil, :foo), :baz=)),
|
361
|
-
s(:to_ary, s(:call, nil, :qux)))
|
362
|
-
end
|
363
|
-
|
364
|
-
it "works with collection elements" do
|
365
|
-
_("foo[1], bar[2] = baz")
|
366
|
-
.must_be_parsed_as s(:masgn,
|
367
|
-
s(:array,
|
368
|
-
s(:attrasgn,
|
369
|
-
s(:call, nil, :foo), :[]=, s(:lit, 1)),
|
370
|
-
s(:attrasgn,
|
371
|
-
s(:call, nil, :bar), :[]=, s(:lit, 2))),
|
372
|
-
s(:to_ary, s(:call, nil, :baz)))
|
373
|
-
end
|
374
|
-
|
375
|
-
it "works with constants" do
|
376
|
-
_("Foo, Bar = baz")
|
377
|
-
.must_be_parsed_as s(:masgn,
|
378
|
-
s(:array, s(:cdecl, :Foo), s(:cdecl, :Bar)),
|
379
|
-
s(:to_ary, s(:call, nil, :baz)))
|
380
|
-
end
|
381
|
-
|
382
|
-
it "works with instance variables and splat" do
|
383
|
-
_("@foo, *@bar = baz")
|
384
|
-
.must_be_parsed_as s(:masgn,
|
385
|
-
s(:array,
|
386
|
-
s(:iasgn, :@foo),
|
387
|
-
s(:splat, s(:iasgn, :@bar))),
|
388
|
-
s(:to_ary, s(:call, nil, :baz)))
|
389
|
-
end
|
390
|
-
|
391
|
-
it "works with a right-hand single splat" do
|
392
|
-
_("foo, bar = *baz")
|
393
|
-
.must_be_parsed_as s(:masgn,
|
394
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
395
|
-
s(:splat, s(:call, nil, :baz)))
|
396
|
-
end
|
397
|
-
|
398
|
-
it "works with a splat in a list of values on the right hand" do
|
399
|
-
_("foo, bar = baz, *qux")
|
400
|
-
.must_be_parsed_as s(:masgn,
|
401
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
402
|
-
s(:array,
|
403
|
-
s(:call, nil, :baz),
|
404
|
-
s(:splat, s(:call, nil, :qux))))
|
405
|
-
end
|
406
|
-
|
407
|
-
it "works with a right-hand single splat with begin..end block" do
|
408
|
-
_("foo, bar = *begin; baz; end")
|
409
|
-
.must_be_parsed_as s(:masgn,
|
410
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
411
|
-
s(:splat,
|
412
|
-
s(:call, nil, :baz)))
|
413
|
-
end
|
414
|
-
|
415
|
-
it "sets the correct line numbers" do
|
416
|
-
result = parser.parse "foo, bar = {}, {}"
|
417
|
-
_(result.line).must_equal 1
|
418
|
-
end
|
419
|
-
end
|
420
|
-
|
421
|
-
describe "for assignment to a collection element" do
|
422
|
-
it "handles multiple indices" do
|
423
|
-
_("foo[bar, baz] = qux")
|
424
|
-
.must_be_parsed_as s(:attrasgn,
|
425
|
-
s(:call, nil, :foo),
|
426
|
-
:[]=,
|
427
|
-
s(:call, nil, :bar),
|
428
|
-
s(:call, nil, :baz),
|
429
|
-
s(:call, nil, :qux))
|
430
|
-
end
|
431
|
-
|
432
|
-
it "handles safe-assigning to an attribute of the collection element" do
|
433
|
-
_("foo[bar]&.baz = qux")
|
434
|
-
.must_be_parsed_as s(:safe_attrasgn,
|
435
|
-
s(:call,
|
436
|
-
s(:call, nil, :foo),
|
437
|
-
:[],
|
438
|
-
s(:call, nil, :bar)),
|
439
|
-
:baz=,
|
440
|
-
s(:call, nil, :qux))
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
describe "for operator assignment" do
|
445
|
-
it "works with +=" do
|
446
|
-
_("foo += bar")
|
447
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
448
|
-
s(:call, s(:lvar, :foo),
|
449
|
-
:+,
|
450
|
-
s(:call, nil, :bar)))
|
451
|
-
end
|
452
|
-
|
453
|
-
it "works with -=" do
|
454
|
-
_("foo -= bar")
|
455
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
456
|
-
s(:call, s(:lvar, :foo),
|
457
|
-
:-,
|
458
|
-
s(:call, nil, :bar)))
|
459
|
-
end
|
460
|
-
|
461
|
-
it "works with *=" do
|
462
|
-
_("foo *= bar")
|
463
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
464
|
-
s(:call, s(:lvar, :foo),
|
465
|
-
:*,
|
466
|
-
s(:call, nil, :bar)))
|
467
|
-
end
|
468
|
-
|
469
|
-
it "works with /=" do
|
470
|
-
_("foo /= bar")
|
471
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
472
|
-
s(:call,
|
473
|
-
s(:lvar, :foo), :/,
|
474
|
-
s(:call, nil, :bar)))
|
475
|
-
end
|
476
|
-
|
477
|
-
it "works with ||=" do
|
478
|
-
_("foo ||= bar")
|
479
|
-
.must_be_parsed_as s(:op_asgn_or,
|
480
|
-
s(:lvar, :foo),
|
481
|
-
s(:lasgn, :foo,
|
482
|
-
s(:call, nil, :bar)))
|
483
|
-
end
|
484
|
-
|
485
|
-
it "works when assigning to an instance variable" do
|
486
|
-
_("@foo += bar")
|
487
|
-
.must_be_parsed_as s(:iasgn, :@foo,
|
488
|
-
s(:call,
|
489
|
-
s(:ivar, :@foo), :+,
|
490
|
-
s(:call, nil, :bar)))
|
491
|
-
end
|
492
|
-
|
493
|
-
it "works with boolean operators" do
|
494
|
-
_("foo &&= bar")
|
495
|
-
.must_be_parsed_as s(:op_asgn_and,
|
496
|
-
s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
|
497
|
-
end
|
498
|
-
|
499
|
-
it "works with boolean operators and blocks" do
|
500
|
-
_("foo &&= begin; bar; end")
|
501
|
-
.must_be_parsed_as s(:op_asgn_and,
|
502
|
-
s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
|
503
|
-
end
|
504
|
-
|
505
|
-
it "works with arithmetic operators and blocks" do
|
506
|
-
_("foo += begin; bar; end")
|
507
|
-
.must_be_parsed_as s(:lasgn, :foo,
|
508
|
-
s(:call, s(:lvar, :foo), :+, s(:call, nil, :bar)))
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
describe "for operator assignment to an attribute" do
|
513
|
-
it "works with +=" do
|
514
|
-
_("foo.bar += baz")
|
515
|
-
.must_be_parsed_as s(:op_asgn2,
|
516
|
-
s(:call, nil, :foo),
|
517
|
-
:bar=, :+,
|
518
|
-
s(:call, nil, :baz))
|
519
|
-
end
|
520
|
-
|
521
|
-
it "works with ||=" do
|
522
|
-
_("foo.bar ||= baz")
|
523
|
-
.must_be_parsed_as s(:op_asgn2,
|
524
|
-
s(:call, nil, :foo),
|
525
|
-
:bar=, :'||',
|
526
|
-
s(:call, nil, :baz))
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
describe "for operator assignment to a collection element" do
|
531
|
-
it "works with +=" do
|
532
|
-
_("foo[bar] += baz")
|
533
|
-
.must_be_parsed_as s(:op_asgn1,
|
534
|
-
s(:call, nil, :foo),
|
535
|
-
s(:arglist, s(:call, nil, :bar)),
|
536
|
-
:+,
|
537
|
-
s(:call, nil, :baz))
|
538
|
-
end
|
539
|
-
|
540
|
-
it "works with ||=" do
|
541
|
-
_("foo[bar] ||= baz")
|
542
|
-
.must_be_parsed_as s(:op_asgn1,
|
543
|
-
s(:call, nil, :foo),
|
544
|
-
s(:arglist, s(:call, nil, :bar)),
|
545
|
-
:"||",
|
546
|
-
s(:call, nil, :baz))
|
547
|
-
end
|
548
|
-
|
549
|
-
it "handles multiple indices" do
|
550
|
-
_("foo[bar, baz] += qux")
|
551
|
-
.must_be_parsed_as s(:op_asgn1,
|
552
|
-
s(:call, nil, :foo),
|
553
|
-
s(:arglist,
|
554
|
-
s(:call, nil, :bar),
|
555
|
-
s(:call, nil, :baz)),
|
556
|
-
:+,
|
557
|
-
s(:call, nil, :qux))
|
558
|
-
end
|
559
|
-
|
560
|
-
it "works with a function call without parentheses" do
|
561
|
-
_("foo[bar] += baz qux")
|
562
|
-
.must_be_parsed_as s(:op_asgn1,
|
563
|
-
s(:call, nil, :foo),
|
564
|
-
s(:arglist, s(:call, nil, :bar)),
|
565
|
-
:+,
|
566
|
-
s(:call, nil, :baz, s(:call, nil, :qux)))
|
567
|
-
end
|
568
|
-
|
569
|
-
it "works with a function call with parentheses" do
|
570
|
-
_("foo[bar] += baz(qux)")
|
571
|
-
.must_be_parsed_as s(:op_asgn1,
|
572
|
-
s(:call, nil, :foo),
|
573
|
-
s(:arglist, s(:call, nil, :bar)),
|
574
|
-
:+,
|
575
|
-
s(:call, nil, :baz, s(:call, nil, :qux)))
|
576
|
-
end
|
577
|
-
|
578
|
-
it "works with a method call without parentheses" do
|
579
|
-
_("foo[bar] += baz.qux quuz")
|
580
|
-
.must_be_parsed_as s(:op_asgn1,
|
581
|
-
s(:call, nil, :foo),
|
582
|
-
s(:arglist, s(:call, nil, :bar)),
|
583
|
-
:+,
|
584
|
-
s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
|
585
|
-
end
|
586
|
-
|
587
|
-
it "works with a method call with parentheses" do
|
588
|
-
_("foo[bar] += baz.qux(quuz)")
|
589
|
-
.must_be_parsed_as s(:op_asgn1,
|
590
|
-
s(:call, nil, :foo),
|
591
|
-
s(:arglist, s(:call, nil, :bar)),
|
592
|
-
:+,
|
593
|
-
s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
|
594
|
-
end
|
595
|
-
end
|
596
|
-
end
|
597
|
-
end
|