ripper_ruby_parser 1.6.1 → 1.7.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +4 -23
  4. data/Rakefile +12 -12
  5. data/lib/ripper_ruby_parser.rb +2 -2
  6. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +9 -9
  7. data/lib/ripper_ruby_parser/parser.rb +3 -3
  8. data/lib/ripper_ruby_parser/sexp_handlers.rb +9 -9
  9. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +3 -9
  10. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +19 -24
  11. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +14 -18
  12. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_processor.rb +4 -4
  14. data/lib/ripper_ruby_parser/unescape.rb +11 -11
  15. data/lib/ripper_ruby_parser/version.rb +1 -1
  16. data/test/end_to_end/comments_test.rb +10 -10
  17. data/test/end_to_end/comparison_test.rb +28 -28
  18. data/test/end_to_end/lib_comparison_test.rb +6 -6
  19. data/test/end_to_end/line_numbering_test.rb +10 -10
  20. data/test/end_to_end/samples_comparison_test.rb +5 -5
  21. data/test/end_to_end/test_comparison_test.rb +6 -6
  22. data/test/pt_testcase/pt_test.rb +7 -7
  23. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +163 -169
  24. data/test/ripper_ruby_parser/parser_test.rb +338 -338
  25. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +475 -511
  26. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +582 -564
  27. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +469 -469
  28. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +713 -724
  29. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +155 -155
  30. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +181 -181
  31. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +337 -352
  32. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +298 -298
  33. data/test/ripper_ruby_parser/sexp_processor_test.rb +119 -119
  34. data/test/ripper_ruby_parser/version_test.rb +2 -2
  35. data/test/samples/lambdas.rb +5 -0
  36. data/test/samples/misc.rb +3 -0
  37. data/test/samples/strings.rb +7 -0
  38. data/test/test_helper.rb +8 -6
  39. metadata +12 -10
@@ -1,191 +1,192 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
3
+ require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
4
 
5
5
  describe RipperRubyParser::Parser do
6
6
  let(:parser) { RipperRubyParser::Parser.new }
7
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))
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
15
  end
16
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))
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
22
  end
23
23
 
24
- it 'works with blocks' do
25
- 'foo = begin; bar; end'.
26
- must_be_parsed_as s(:lasgn, :foo, s(:call, nil, :bar))
24
+ it "works with blocks" do
25
+ _("foo = begin; bar; end")
26
+ .must_be_parsed_as s(:lasgn, :foo, s(:call, nil, :bar))
27
27
  end
28
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))))
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
36
  end
37
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))))
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
42
  end
43
43
  end
44
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))))
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
53
  end
54
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)))))
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
63
  end
64
64
  end
65
65
 
66
- describe 'with an array literal on the right hand side' do
66
+ describe "with an array literal on the right hand side" do
67
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)))
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
73
  end
74
74
  end
75
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))
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
81
  end
82
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))
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
88
  end
89
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))
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
97
  end
98
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))
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
105
  end
106
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))
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
113
  end
114
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)))
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
120
  end
121
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)))
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
128
  end
129
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))
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
138
  end
139
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))
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
149
  end
150
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))
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
158
  end
159
159
  end
160
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))
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
166
  end
167
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))))
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
175
  end
176
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))))
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
183
  end
184
184
 
185
- it 'works with a method call with argument without brackets' do
186
- expected = if RUBY_VERSION < '2.4.0'
185
+ it "works with a method call with argument without brackets" do
186
+ expected = if RUBY_VERSION < "2.4.0"
187
187
  s(:rescue,
188
- s(:lasgn, :foo, s(:call, nil, :bar, s(:call, nil, :baz))),
188
+ s(:lasgn, :foo,
189
+ s(:call, nil, :bar, s(:call, nil, :baz))),
189
190
  s(:resbody, s(:array), s(:call, nil, :qux)))
190
191
  else
191
192
  s(:lasgn, :foo,
@@ -193,13 +194,14 @@ describe RipperRubyParser::Parser do
193
194
  s(:call, nil, :bar, s(:call, nil, :baz)),
194
195
  s(:resbody, s(:array), s(:call, nil, :qux))))
195
196
  end
196
- 'foo = bar baz rescue qux'.must_be_parsed_as expected
197
+ _("foo = bar baz rescue qux").must_be_parsed_as expected
197
198
  end
198
199
 
199
- it 'works with a class method call with argument without brackets' do
200
- expected = if RUBY_VERSION < '2.4.0'
200
+ it "works with a class method call with argument without brackets" do
201
+ expected = if RUBY_VERSION < "2.4.0"
201
202
  s(:rescue,
202
- s(:lasgn, :foo, s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
203
+ s(:lasgn, :foo,
204
+ s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
203
205
  s(:resbody, s(:array), s(:call, nil, :quuz)))
204
206
  else
205
207
  s(:lasgn, :foo,
@@ -207,14 +209,15 @@ describe RipperRubyParser::Parser do
207
209
  s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
208
210
  s(:resbody, s(:array), s(:call, nil, :quuz))))
209
211
  end
210
- 'foo = Bar.baz qux rescue quuz'.
211
- must_be_parsed_as expected
212
+ _("foo = Bar.baz qux rescue quuz")
213
+ .must_be_parsed_as expected
212
214
  end
213
215
 
214
- it 'works with a method call with argument without brackets' do
215
- expected = if RUBY_VERSION < '2.4.0'
216
+ it "works with a method call with argument without brackets" do
217
+ expected = if RUBY_VERSION < "2.4.0"
216
218
  s(:rescue,
217
- s(:lasgn, :foo, s(:call, nil, :bar, s(:call, nil, :baz))),
219
+ s(:lasgn, :foo,
220
+ s(:call, nil, :bar, s(:call, nil, :baz))),
218
221
  s(:resbody, s(:array), s(:call, nil, :qux)))
219
222
  else
220
223
  s(:lasgn, :foo,
@@ -222,13 +225,14 @@ describe RipperRubyParser::Parser do
222
225
  s(:call, nil, :bar, s(:call, nil, :baz)),
223
226
  s(:resbody, s(:array), s(:call, nil, :qux))))
224
227
  end
225
- 'foo = bar baz rescue qux'.must_be_parsed_as expected
228
+ _("foo = bar baz rescue qux").must_be_parsed_as expected
226
229
  end
227
230
 
228
- it 'works with a class method call with argument without brackets' do
229
- expected = if RUBY_VERSION < '2.4.0'
231
+ it "works with a class method call with argument without brackets" do
232
+ expected = if RUBY_VERSION < "2.4.0"
230
233
  s(:rescue,
231
- s(:lasgn, :foo, s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
234
+ s(:lasgn, :foo,
235
+ s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
232
236
  s(:resbody, s(:array), s(:call, nil, :quuz)))
233
237
  else
234
238
  s(:lasgn, :foo,
@@ -236,413 +240,373 @@ describe RipperRubyParser::Parser do
236
240
  s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
237
241
  s(:resbody, s(:array), s(:call, nil, :quuz))))
238
242
  end
239
- 'foo = Bar.baz qux rescue quuz'.
240
- must_be_parsed_as expected
243
+ _("foo = Bar.baz qux rescue quuz")
244
+ .must_be_parsed_as expected
241
245
  end
242
246
  end
243
247
 
244
- it 'sets the correct line numbers' do
245
- result = parser.parse 'foo = {}'
246
- result.line.must_equal 1
248
+ it "sets the correct line numbers" do
249
+ result = parser.parse "foo = {}"
250
+ _(result.line).must_equal 1
247
251
  end
248
252
  end
249
253
 
250
- describe 'for multiple assignment' do
254
+ describe "for multiple assignment" do
251
255
  specify do
252
- 'foo, * = bar'.
253
- must_be_parsed_as s(:masgn,
254
- s(:array, s(:lasgn, :foo), s(:splat)),
255
- s(:to_ary, s(:call, nil, :bar)))
256
+ _("foo, * = bar")
257
+ .must_be_parsed_as s(:masgn,
258
+ s(:array, s(:lasgn, :foo), s(:splat)),
259
+ s(:to_ary, s(:call, nil, :bar)))
256
260
  end
257
261
 
258
262
  specify do
259
- '(foo, *bar) = baz'.
260
- must_be_parsed_as s(:masgn,
261
- s(:array,
262
- s(:lasgn, :foo),
263
- s(:splat, s(:lasgn, :bar))),
264
- s(:to_ary, s(:call, nil, :baz)))
263
+ _("(foo, *bar) = baz")
264
+ .must_be_parsed_as s(:masgn,
265
+ s(:array,
266
+ s(:lasgn, :foo),
267
+ s(:splat, s(:lasgn, :bar))),
268
+ s(:to_ary, s(:call, nil, :baz)))
265
269
  end
266
270
 
267
271
  specify do
268
- '*foo, bar = baz'.
269
- must_be_parsed_as s(:masgn,
270
- s(:array,
271
- s(:splat, s(:lasgn, :foo)),
272
- s(:lasgn, :bar)),
273
- s(:to_ary, s(:call, nil, :baz)))
274
- end
275
-
276
- it 'works with blocks' do
277
- 'foo, bar = begin; baz; end'.
278
- must_be_parsed_as s(:masgn,
279
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
280
- s(:to_ary, s(:call, nil, :baz)))
281
- end
282
-
283
- it 'works with a rescue modifier' do
284
- 'foo, bar = baz rescue qux'.
285
- must_be_parsed_as s(:rescue,
286
- s(:masgn,
287
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
288
- s(:to_ary, s(:call, nil, :baz))),
289
- s(:resbody, s(:array), s(:call, nil, :qux)))
290
- end
291
-
292
- it 'works the same number of items on each side' do
293
- 'foo, bar = baz, qux'.
294
- must_be_parsed_as s(:masgn,
295
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
296
- s(:array,
297
- s(:call, nil, :baz),
298
- s(:call, nil, :qux)))
299
- end
300
-
301
- it 'works with a single item on the right-hand side' do
302
- 'foo, bar = baz'.
303
- must_be_parsed_as s(:masgn,
304
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
305
- s(:to_ary, s(:call, nil, :baz)))
306
- end
307
-
308
- it 'works with left-hand splat' do
309
- 'foo, *bar = baz, qux'.
310
- must_be_parsed_as s(:masgn,
311
- s(:array, s(:lasgn, :foo), s(:splat, s(:lasgn, :bar))),
312
- s(:array,
313
- s(:call, nil, :baz),
314
- s(:call, nil, :qux)))
315
- end
316
-
317
- it 'works with parentheses around the left-hand side' do
318
- '(foo, bar) = baz'.
319
- must_be_parsed_as s(:masgn,
320
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
321
- s(:to_ary, s(:call, nil, :baz)))
322
- end
323
-
324
- it 'works with complex destructuring' do
325
- 'foo, (bar, baz) = qux'.
326
- must_be_parsed_as s(:masgn,
327
- s(:array,
328
- s(:lasgn, :foo),
329
- s(:masgn,
330
- s(:array,
331
- s(:lasgn, :bar),
332
- s(:lasgn, :baz)))),
333
- s(:to_ary, s(:call, nil, :qux)))
334
- end
335
-
336
- it 'works with complex destructuring of the value' do
337
- 'foo, (bar, baz) = [qux, [quz, quuz]]'.
338
- must_be_parsed_as s(:masgn,
339
- s(:array,
340
- s(:lasgn, :foo),
341
- s(:masgn,
342
- s(:array,
343
- s(:lasgn, :bar),
344
- s(:lasgn, :baz)))),
345
- s(:to_ary,
346
- s(:array,
347
- s(:call, nil, :qux),
348
- s(:array,
349
- s(:call, nil, :quz),
350
- s(:call, nil, :quuz)))))
351
- end
352
-
353
- it 'works with destructuring with multiple levels' do
354
- '((foo, bar)) = baz'.
355
- must_be_parsed_as s(:masgn,
356
- s(:array,
357
- s(:masgn,
358
- s(:array,
359
- s(:lasgn, :foo),
360
- s(:lasgn, :bar)))),
361
- s(:to_ary, s(:call, nil, :baz)))
362
- end
363
-
364
- it 'works with instance variables' do
365
- '@foo, @bar = baz'.
366
- must_be_parsed_as s(:masgn,
367
- s(:array, s(:iasgn, :@foo), s(:iasgn, :@bar)),
368
- s(:to_ary, s(:call, nil, :baz)))
369
- end
370
-
371
- it 'works with class variables' do
372
- '@@foo, @@bar = baz'.
373
- must_be_parsed_as s(:masgn,
374
- s(:array, s(:cvdecl, :@@foo), s(:cvdecl, :@@bar)),
375
- s(:to_ary, s(:call, nil, :baz)))
376
- end
377
-
378
- it 'works with attributes' do
379
- 'foo.bar, foo.baz = qux'.
380
- must_be_parsed_as s(:masgn,
381
- s(:array,
382
- s(:attrasgn, s(:call, nil, :foo), :bar=),
383
- s(:attrasgn, s(:call, nil, :foo), :baz=)),
384
- s(:to_ary, s(:call, nil, :qux)))
385
- end
386
-
387
- it 'works with collection elements' do
388
- 'foo[1], bar[2] = baz'.
389
- must_be_parsed_as s(:masgn,
390
- s(:array,
391
- s(:attrasgn,
392
- s(:call, nil, :foo), :[]=, s(:lit, 1)),
393
- s(:attrasgn,
394
- s(:call, nil, :bar), :[]=, s(:lit, 2))),
395
- s(:to_ary, s(:call, nil, :baz)))
396
- end
397
-
398
- it 'works with constants' do
399
- 'Foo, Bar = baz'.
400
- must_be_parsed_as s(:masgn,
401
- s(:array, s(:cdecl, :Foo), s(:cdecl, :Bar)),
402
- s(:to_ary, s(:call, nil, :baz)))
403
- end
404
-
405
- it 'works with instance variables and splat' do
406
- '@foo, *@bar = baz'.
407
- must_be_parsed_as s(:masgn,
408
- s(:array,
409
- s(:iasgn, :@foo),
410
- s(:splat, s(:iasgn, :@bar))),
411
- s(:to_ary, s(:call, nil, :baz)))
412
- end
413
-
414
- it 'works with a right-hand single splat' do
415
- 'foo, bar = *baz'.
416
- must_be_parsed_as s(:masgn,
417
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
418
- s(:splat, s(:call, nil, :baz)))
419
- end
420
-
421
- it 'works with a splat in a list of values on the right hand' do
422
- 'foo, bar = baz, *qux'.
423
- must_be_parsed_as s(:masgn,
424
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
425
- s(:array,
426
- s(:call, nil, :baz),
427
- s(:splat, s(:call, nil, :qux))))
428
- end
429
-
430
- it 'works with a right-hand single splat with begin..end block' do
431
- 'foo, bar = *begin; baz; end'.
432
- must_be_parsed_as s(:masgn,
433
- s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
434
- s(:splat,
435
- s(:call, nil, :baz)))
436
- end
437
-
438
- it 'sets the correct line numbers' do
439
- result = parser.parse 'foo, bar = {}, {}'
440
- result.line.must_equal 1
272
+ _("*foo, bar = baz")
273
+ .must_be_parsed_as s(:masgn,
274
+ s(:array,
275
+ s(:splat, s(:lasgn, :foo)),
276
+ s(:lasgn, :bar)),
277
+ s(:to_ary, s(:call, nil, :baz)))
278
+ end
279
+
280
+ it "works with blocks" do
281
+ _("foo, bar = begin; baz; end")
282
+ .must_be_parsed_as s(:masgn,
283
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
284
+ s(:to_ary, s(:call, nil, :baz)))
285
+ end
286
+
287
+ it "works with a rescue modifier" do
288
+ _("foo, bar = baz rescue qux")
289
+ .must_be_parsed_as s(:rescue,
290
+ s(:masgn,
291
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
292
+ s(:to_ary, s(:call, nil, :baz))),
293
+ s(:resbody, s(:array), s(:call, nil, :qux)))
294
+ end
295
+
296
+ it "works the same number of items on each side" do
297
+ _("foo, bar = baz, qux")
298
+ .must_be_parsed_as s(:masgn,
299
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
300
+ s(:array,
301
+ s(:call, nil, :baz),
302
+ s(:call, nil, :qux)))
303
+ end
304
+
305
+ it "works with a single item on the right-hand side" do
306
+ _("foo, bar = baz")
307
+ .must_be_parsed_as s(:masgn,
308
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
309
+ s(:to_ary, s(:call, nil, :baz)))
310
+ end
311
+
312
+ it "works with left-hand splat" do
313
+ _("foo, *bar = baz, qux")
314
+ .must_be_parsed_as s(:masgn,
315
+ s(:array, s(:lasgn, :foo), s(:splat, s(:lasgn, :bar))),
316
+ s(:array,
317
+ s(:call, nil, :baz),
318
+ s(:call, nil, :qux)))
319
+ end
320
+
321
+ it "works with parentheses around the left-hand side" do
322
+ _("(foo, bar) = baz")
323
+ .must_be_parsed_as s(:masgn,
324
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
325
+ s(:to_ary, s(:call, nil, :baz)))
326
+ end
327
+
328
+ it "works with complex destructuring" do
329
+ _("foo, (bar, baz) = qux")
330
+ .must_be_parsed_as s(:masgn,
331
+ s(:array,
332
+ s(:lasgn, :foo),
333
+ s(:masgn,
334
+ s(:array,
335
+ s(:lasgn, :bar),
336
+ s(:lasgn, :baz)))),
337
+ s(:to_ary, s(:call, nil, :qux)))
338
+ end
339
+
340
+ it "works with complex destructuring of the value" do
341
+ _("foo, (bar, baz) = [qux, [quz, quuz]]")
342
+ .must_be_parsed_as s(:masgn,
343
+ s(:array,
344
+ s(:lasgn, :foo),
345
+ s(:masgn,
346
+ s(:array,
347
+ s(:lasgn, :bar),
348
+ s(:lasgn, :baz)))),
349
+ s(:to_ary,
350
+ s(:array,
351
+ s(:call, nil, :qux),
352
+ s(:array,
353
+ s(:call, nil, :quz),
354
+ s(:call, nil, :quuz)))))
355
+ end
356
+
357
+ it "works with destructuring with multiple levels" do
358
+ _("((foo, bar)) = baz")
359
+ .must_be_parsed_as s(:masgn,
360
+ s(:array,
361
+ s(:masgn,
362
+ s(:array,
363
+ s(:lasgn, :foo),
364
+ s(:lasgn, :bar)))),
365
+ s(:to_ary, s(:call, nil, :baz)))
366
+ end
367
+
368
+ it "works with instance variables" do
369
+ _("@foo, @bar = baz")
370
+ .must_be_parsed_as s(:masgn,
371
+ s(:array, s(:iasgn, :@foo), s(:iasgn, :@bar)),
372
+ s(:to_ary, s(:call, nil, :baz)))
373
+ end
374
+
375
+ it "works with class variables" do
376
+ _("@@foo, @@bar = baz")
377
+ .must_be_parsed_as s(:masgn,
378
+ s(:array, s(:cvdecl, :@@foo), s(:cvdecl, :@@bar)),
379
+ s(:to_ary, s(:call, nil, :baz)))
380
+ end
381
+
382
+ it "works with attributes" do
383
+ _("foo.bar, foo.baz = qux")
384
+ .must_be_parsed_as s(:masgn,
385
+ s(:array,
386
+ s(:attrasgn, s(:call, nil, :foo), :bar=),
387
+ s(:attrasgn, s(:call, nil, :foo), :baz=)),
388
+ s(:to_ary, s(:call, nil, :qux)))
389
+ end
390
+
391
+ it "works with collection elements" do
392
+ _("foo[1], bar[2] = baz")
393
+ .must_be_parsed_as s(:masgn,
394
+ s(:array,
395
+ s(:attrasgn,
396
+ s(:call, nil, :foo), :[]=, s(:lit, 1)),
397
+ s(:attrasgn,
398
+ s(:call, nil, :bar), :[]=, s(:lit, 2))),
399
+ s(:to_ary, s(:call, nil, :baz)))
400
+ end
401
+
402
+ it "works with constants" do
403
+ _("Foo, Bar = baz")
404
+ .must_be_parsed_as s(:masgn,
405
+ s(:array, s(:cdecl, :Foo), s(:cdecl, :Bar)),
406
+ s(:to_ary, s(:call, nil, :baz)))
407
+ end
408
+
409
+ it "works with instance variables and splat" do
410
+ _("@foo, *@bar = baz")
411
+ .must_be_parsed_as s(:masgn,
412
+ s(:array,
413
+ s(:iasgn, :@foo),
414
+ s(:splat, s(:iasgn, :@bar))),
415
+ s(:to_ary, s(:call, nil, :baz)))
416
+ end
417
+
418
+ it "works with a right-hand single splat" do
419
+ _("foo, bar = *baz")
420
+ .must_be_parsed_as s(:masgn,
421
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
422
+ s(:splat, s(:call, nil, :baz)))
423
+ end
424
+
425
+ it "works with a splat in a list of values on the right hand" do
426
+ _("foo, bar = baz, *qux")
427
+ .must_be_parsed_as s(:masgn,
428
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
429
+ s(:array,
430
+ s(:call, nil, :baz),
431
+ s(:splat, s(:call, nil, :qux))))
432
+ end
433
+
434
+ it "works with a right-hand single splat with begin..end block" do
435
+ _("foo, bar = *begin; baz; end")
436
+ .must_be_parsed_as s(:masgn,
437
+ s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
438
+ s(:splat,
439
+ s(:call, nil, :baz)))
440
+ end
441
+
442
+ it "sets the correct line numbers" do
443
+ result = parser.parse "foo, bar = {}, {}"
444
+ _(result.line).must_equal 1
441
445
  end
442
446
  end
443
447
 
444
- describe 'for assignment to a collection element' do
445
- it 'handles multiple indices' do
446
- 'foo[bar, baz] = qux'.
447
- must_be_parsed_as s(:attrasgn,
448
- s(:call, nil, :foo),
449
- :[]=,
450
- s(:call, nil, :bar),
451
- s(:call, nil, :baz),
452
- s(:call, nil, :qux))
448
+ describe "for assignment to a collection element" do
449
+ it "handles multiple indices" do
450
+ _("foo[bar, baz] = qux")
451
+ .must_be_parsed_as s(:attrasgn,
452
+ s(:call, nil, :foo),
453
+ :[]=,
454
+ s(:call, nil, :bar),
455
+ s(:call, nil, :baz),
456
+ s(:call, nil, :qux))
453
457
  end
454
458
  end
455
459
 
456
- describe 'for operator assignment' do
457
- it 'works with +=' do
458
- 'foo += bar'.
459
- must_be_parsed_as s(:lasgn, :foo,
460
- s(:call, s(:lvar, :foo),
461
- :+,
462
- s(:call, nil, :bar)))
460
+ describe "for operator assignment" do
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)))
463
467
  end
464
468
 
465
- it 'works with -=' do
466
- 'foo -= bar'.
467
- must_be_parsed_as s(:lasgn, :foo,
468
- s(:call, s(:lvar, :foo),
469
- :-,
470
- s(:call, nil, :bar)))
469
+ it "works with -=" do
470
+ _("foo -= bar")
471
+ .must_be_parsed_as s(:lasgn, :foo,
472
+ s(:call, s(:lvar, :foo),
473
+ :-,
474
+ s(:call, nil, :bar)))
471
475
  end
472
476
 
473
- it 'works with *=' do
474
- 'foo *= bar'.
475
- must_be_parsed_as s(:lasgn, :foo,
476
- s(:call, s(:lvar, :foo),
477
- :*,
478
- s(:call, nil, :bar)))
477
+ it "works with *=" do
478
+ _("foo *= bar")
479
+ .must_be_parsed_as s(:lasgn, :foo,
480
+ s(:call, s(:lvar, :foo),
481
+ :*,
482
+ s(:call, nil, :bar)))
479
483
  end
480
484
 
481
- it 'works with /=' do
482
- 'foo /= bar'.
483
- must_be_parsed_as s(:lasgn, :foo,
484
- s(:call,
485
- s(:lvar, :foo), :/,
486
- s(:call, nil, :bar)))
485
+ it "works with /=" do
486
+ _("foo /= bar")
487
+ .must_be_parsed_as s(:lasgn, :foo,
488
+ s(:call,
489
+ s(:lvar, :foo), :/,
490
+ s(:call, nil, :bar)))
487
491
  end
488
492
 
489
- it 'works with ||=' do
490
- 'foo ||= bar'.
491
- must_be_parsed_as s(:op_asgn_or,
492
- s(:lvar, :foo),
493
- s(:lasgn, :foo,
494
- s(:call, nil, :bar)))
493
+ it "works with ||=" do
494
+ _("foo ||= bar")
495
+ .must_be_parsed_as s(:op_asgn_or,
496
+ s(:lvar, :foo),
497
+ s(:lasgn, :foo,
498
+ s(:call, nil, :bar)))
495
499
  end
496
500
 
497
- it 'works when assigning to an instance variable' do
498
- '@foo += bar'.
499
- must_be_parsed_as s(:iasgn, :@foo,
500
- s(:call,
501
- s(:ivar, :@foo), :+,
502
- s(:call, nil, :bar)))
501
+ it "works when assigning to an instance variable" do
502
+ _("@foo += bar")
503
+ .must_be_parsed_as s(:iasgn, :@foo,
504
+ s(:call,
505
+ s(:ivar, :@foo), :+,
506
+ s(:call, nil, :bar)))
503
507
  end
504
508
 
505
- it 'works with boolean operators' do
506
- 'foo &&= bar'.
507
- must_be_parsed_as s(:op_asgn_and,
508
- s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
509
+ it "works with boolean operators" do
510
+ _("foo &&= bar")
511
+ .must_be_parsed_as s(:op_asgn_and,
512
+ s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
509
513
  end
510
514
 
511
- it 'works with boolean operators and blocks' do
512
- 'foo &&= begin; bar; end'.
513
- must_be_parsed_as s(:op_asgn_and,
514
- s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
515
+ it "works with boolean operators and blocks" do
516
+ _("foo &&= begin; bar; end")
517
+ .must_be_parsed_as s(:op_asgn_and,
518
+ s(:lvar, :foo), s(:lasgn, :foo, s(:call, nil, :bar)))
515
519
  end
516
520
 
517
- it 'works with arithmetic operators and blocks' do
518
- 'foo += begin; bar; end'.
519
- must_be_parsed_as s(:lasgn, :foo,
520
- s(:call, s(:lvar, :foo), :+, s(:call, nil, :bar)))
521
+ it "works with arithmetic operators and blocks" do
522
+ _("foo += begin; bar; end")
523
+ .must_be_parsed_as s(:lasgn, :foo,
524
+ s(:call, s(:lvar, :foo), :+, s(:call, nil, :bar)))
521
525
  end
522
526
  end
523
527
 
524
- describe 'for operator assignment to an attribute' do
525
- it 'works with +=' do
526
- 'foo.bar += baz'.
527
- must_be_parsed_as s(:op_asgn2,
528
- s(:call, nil, :foo),
529
- :bar=, :+,
530
- s(:call, nil, :baz))
528
+ describe "for operator assignment to an attribute" do
529
+ it "works with +=" do
530
+ _("foo.bar += baz")
531
+ .must_be_parsed_as s(:op_asgn2,
532
+ s(:call, nil, :foo),
533
+ :bar=, :+,
534
+ s(:call, nil, :baz))
531
535
  end
532
536
 
533
- it 'works with ||=' do
534
- 'foo.bar ||= baz'.
535
- must_be_parsed_as s(:op_asgn2,
536
- s(:call, nil, :foo),
537
- :bar=, :'||',
538
- s(:call, nil, :baz))
537
+ it "works with ||=" do
538
+ _("foo.bar ||= baz")
539
+ .must_be_parsed_as s(:op_asgn2,
540
+ s(:call, nil, :foo),
541
+ :bar=, :'||',
542
+ s(:call, nil, :baz))
539
543
  end
540
544
  end
541
545
 
542
- describe 'for operator assignment to a collection element' do
543
- it 'works with +=' do
544
- 'foo[bar] += baz'.
545
- must_be_parsed_as s(:op_asgn1,
546
- s(:call, nil, :foo),
547
- s(:arglist, s(:call, nil, :bar)),
548
- :+,
549
- s(:call, nil, :baz))
550
- end
551
-
552
- it 'works with ||=' do
553
- 'foo[bar] ||= baz'.
554
- must_be_parsed_as s(:op_asgn1,
555
- s(:call, nil, :foo),
556
- s(:arglist, s(:call, nil, :bar)),
557
- :"||",
558
- s(:call, nil, :baz))
559
- end
560
-
561
- it 'handles multiple indices' do
562
- 'foo[bar, baz] += qux'.
563
- must_be_parsed_as s(:op_asgn1,
564
- s(:call, nil, :foo),
565
- s(:arglist,
566
- s(:call, nil, :bar),
567
- s(:call, nil, :baz)),
568
- :+,
569
- s(:call, nil, :qux))
570
- end
571
-
572
- it 'works with a function call without parentheses' do
573
- 'foo[bar] += baz qux'.
574
- must_be_parsed_as s(:op_asgn1,
575
- s(:call, nil, :foo),
576
- s(:arglist, s(:call, nil, :bar)),
577
- :+,
578
- s(:call, nil, :baz, s(:call, nil, :qux)))
579
- end
580
-
581
- it 'works with a function call with parentheses' do
582
- 'foo[bar] += baz(qux)'.
583
- must_be_parsed_as s(:op_asgn1,
584
- s(:call, nil, :foo),
585
- s(:arglist, s(:call, nil, :bar)),
586
- :+,
587
- s(:call, nil, :baz, s(:call, nil, :qux)))
588
- end
589
-
590
- it 'works with a method call without parentheses' do
591
- 'foo[bar] += baz.qux quuz'.
592
- must_be_parsed_as s(:op_asgn1,
593
- s(:call, nil, :foo),
594
- s(:arglist, s(:call, nil, :bar)),
595
- :+,
596
- s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
597
- end
598
-
599
- it 'works with a method call with parentheses' do
600
- 'foo[bar] += baz.qux(quuz)'.
601
- must_be_parsed_as s(:op_asgn1,
602
- s(:call, nil, :foo),
603
- s(:arglist, s(:call, nil, :bar)),
604
- :+,
605
- s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
606
- end
607
-
608
- it 'works with a function call without parentheses in extra compatible mode' do
609
- 'foo[bar] += baz qux'.
610
- must_be_parsed_as s(:op_asgn1,
611
- s(:call, nil, :foo),
612
- s(:array, s(:call, nil, :bar)),
613
- :+,
614
- s(:call, nil, :baz, s(:call, nil, :qux))),
615
- extra_compatible: true
616
- end
617
-
618
- it 'works with a function call with parentheses in extra compatible mode' do
619
- 'foo[bar] += baz(qux)'.
620
- must_be_parsed_as s(:op_asgn1,
621
- s(:call, nil, :foo),
622
- s(:arglist, s(:call, nil, :bar)),
623
- :+,
624
- s(:call, nil, :baz, s(:call, nil, :qux))),
625
- extra_compatible: true
626
- end
627
-
628
- it 'works with a method call without parentheses in extra compatible mode' do
629
- 'foo[bar] += baz.qux quuz'.
630
- must_be_parsed_as s(:op_asgn1,
631
- s(:call, nil, :foo),
632
- s(:array, s(:call, nil, :bar)),
633
- :+,
634
- s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz))),
635
- extra_compatible: true
636
- end
637
-
638
- it 'works with a method call with parentheses in extra compatible mode' do
639
- 'foo[bar] += baz.qux(quuz)'.
640
- must_be_parsed_as s(:op_asgn1,
641
- s(:call, nil, :foo),
642
- s(:arglist, s(:call, nil, :bar)),
643
- :+,
644
- s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz))),
645
- extra_compatible: true
546
+ describe "for operator assignment to a collection element" do
547
+ it "works with +=" do
548
+ _("foo[bar] += baz")
549
+ .must_be_parsed_as s(:op_asgn1,
550
+ s(:call, nil, :foo),
551
+ s(:arglist, s(:call, nil, :bar)),
552
+ :+,
553
+ s(:call, nil, :baz))
554
+ end
555
+
556
+ it "works with ||=" do
557
+ _("foo[bar] ||= baz")
558
+ .must_be_parsed_as s(:op_asgn1,
559
+ s(:call, nil, :foo),
560
+ s(:arglist, s(:call, nil, :bar)),
561
+ :"||",
562
+ s(:call, nil, :baz))
563
+ end
564
+
565
+ it "handles multiple indices" do
566
+ _("foo[bar, baz] += qux")
567
+ .must_be_parsed_as s(:op_asgn1,
568
+ s(:call, nil, :foo),
569
+ s(:arglist,
570
+ s(:call, nil, :bar),
571
+ s(:call, nil, :baz)),
572
+ :+,
573
+ s(:call, nil, :qux))
574
+ end
575
+
576
+ it "works with a function call without parentheses" do
577
+ _("foo[bar] += baz qux")
578
+ .must_be_parsed_as s(:op_asgn1,
579
+ s(:call, nil, :foo),
580
+ s(:arglist, s(:call, nil, :bar)),
581
+ :+,
582
+ s(:call, nil, :baz, s(:call, nil, :qux)))
583
+ end
584
+
585
+ it "works with a function call with parentheses" do
586
+ _("foo[bar] += baz(qux)")
587
+ .must_be_parsed_as s(:op_asgn1,
588
+ s(:call, nil, :foo),
589
+ s(:arglist, s(:call, nil, :bar)),
590
+ :+,
591
+ s(:call, nil, :baz, s(:call, nil, :qux)))
592
+ end
593
+
594
+ it "works with a method call without parentheses" do
595
+ _("foo[bar] += baz.qux quuz")
596
+ .must_be_parsed_as s(:op_asgn1,
597
+ s(:call, nil, :foo),
598
+ s(:arglist, s(:call, nil, :bar)),
599
+ :+,
600
+ s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
601
+ end
602
+
603
+ it "works with a method call with parentheses" do
604
+ _("foo[bar] += baz.qux(quuz)")
605
+ .must_be_parsed_as s(:op_asgn1,
606
+ s(:call, nil, :foo),
607
+ s(:arglist, s(:call, nil, :bar)),
608
+ :+,
609
+ s(:call, s(:call, nil, :baz), :qux, s(:call, nil, :quuz)))
646
610
  end
647
611
  end
648
612
  end