ripper_ruby_parser 1.6.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
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,660 +1,678 @@
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
- describe '#parse' do
7
- describe 'for do blocks' do
8
- it 'works with no statements in the block body' do
9
- 'foo do; end'.
10
- must_be_parsed_as s(:iter,
11
- s(:call, nil, :foo),
12
- 0)
13
- end
14
-
15
- it 'works with redo' do
16
- 'foo do; redo; end'.
17
- must_be_parsed_as s(:iter,
18
- s(:call, nil, :foo),
19
- 0,
20
- s(:redo))
21
- end
22
-
23
- it 'works with nested begin..end' do
24
- 'foo do; begin; bar; end; end;'.
25
- must_be_parsed_as s(:iter,
26
- s(:call, nil, :foo),
27
- 0,
28
- s(:call, nil, :bar))
29
- end
30
-
31
- it 'works with nested begin..end plus other statements' do
32
- 'foo do; bar; begin; baz; end; end;'.
33
- must_be_parsed_as s(:iter,
34
- s(:call, nil, :foo),
35
- 0,
36
- s(:block,
37
- s(:call, nil, :bar),
38
- s(:call, nil, :baz)))
6
+ describe "#parse" do
7
+ describe "for do blocks" do
8
+ it "works with no statements in the block body" do
9
+ _("foo do; end")
10
+ .must_be_parsed_as s(:iter,
11
+ s(:call, nil, :foo),
12
+ 0)
13
+ end
14
+
15
+ it "works with redo" do
16
+ _("foo do; redo; end")
17
+ .must_be_parsed_as s(:iter,
18
+ s(:call, nil, :foo),
19
+ 0,
20
+ s(:redo))
21
+ end
22
+
23
+ it "works with nested begin..end" do
24
+ _("foo do; begin; bar; end; end;")
25
+ .must_be_parsed_as s(:iter,
26
+ s(:call, nil, :foo),
27
+ 0,
28
+ s(:call, nil, :bar))
29
+ end
30
+
31
+ it "works with nested begin..end plus other statements" do
32
+ _("foo do; bar; begin; baz; end; end;")
33
+ .must_be_parsed_as s(:iter,
34
+ s(:call, nil, :foo),
35
+ 0,
36
+ s(:block,
37
+ s(:call, nil, :bar),
38
+ s(:call, nil, :baz)))
39
39
  end
40
40
  end
41
41
 
42
- describe 'for brace blocks' do
43
- it 'works with no statements in the block body' do
44
- 'foo { }'.
45
- must_be_parsed_as s(:iter,
46
- s(:call, nil, :foo),
47
- 0)
42
+ describe "for brace blocks" do
43
+ it "works with no statements in the block body" do
44
+ _("foo { }")
45
+ .must_be_parsed_as s(:iter,
46
+ s(:call, nil, :foo),
47
+ 0)
48
48
  end
49
49
  end
50
50
 
51
- describe 'for block parameters' do
51
+ describe "for block parameters" do
52
52
  specify do
53
- 'foo do |(bar, baz)| end'.
54
- must_be_parsed_as s(:iter,
55
- s(:call, nil, :foo),
56
- s(:args,
57
- s(:masgn, :bar, :baz)))
53
+ _("foo do |(bar, baz)| end")
54
+ .must_be_parsed_as s(:iter,
55
+ s(:call, nil, :foo),
56
+ s(:args,
57
+ s(:masgn, :bar, :baz)))
58
58
  end
59
59
 
60
60
  specify do
61
- 'foo do |(bar, *baz)| end'.
62
- must_be_parsed_as s(:iter,
63
- s(:call, nil, :foo),
64
- s(:args,
65
- s(:masgn, :bar, :"*baz")))
61
+ _("foo do |(bar, *baz)| end")
62
+ .must_be_parsed_as s(:iter,
63
+ s(:call, nil, :foo),
64
+ s(:args,
65
+ s(:masgn, :bar, :"*baz")))
66
66
  end
67
67
 
68
68
  specify do
69
- 'foo do |bar,*| end'.
70
- must_be_parsed_as s(:iter,
71
- s(:call, nil, :foo),
72
- s(:args, :bar, :"*"))
69
+ _("foo do |bar,*| end")
70
+ .must_be_parsed_as s(:iter,
71
+ s(:call, nil, :foo),
72
+ s(:args, :bar, :"*"))
73
73
  end
74
74
 
75
75
  specify do
76
- 'foo do |bar, &baz| end'.
77
- must_be_parsed_as s(:iter,
78
- s(:call, nil, :foo),
79
- s(:args, :bar, :"&baz"))
76
+ _("foo do |bar, &baz| end")
77
+ .must_be_parsed_as s(:iter,
78
+ s(:call, nil, :foo),
79
+ s(:args, :bar, :"&baz"))
80
80
  end
81
81
 
82
- it 'handles absent parameter specs' do
83
- 'foo do; bar; end'.
84
- must_be_parsed_as s(:iter,
85
- s(:call, nil, :foo),
86
- 0,
87
- s(:call, nil, :bar))
82
+ it "handles absent parameter specs" do
83
+ _("foo do; bar; end")
84
+ .must_be_parsed_as s(:iter,
85
+ s(:call, nil, :foo),
86
+ 0,
87
+ s(:call, nil, :bar))
88
88
  end
89
89
 
90
- it 'handles empty parameter specs' do
91
- 'foo do ||; bar; end'.
92
- must_be_parsed_as s(:iter,
93
- s(:call, nil, :foo),
94
- s(:args),
95
- s(:call, nil, :bar))
90
+ it "handles empty parameter specs" do
91
+ _("foo do ||; bar; end")
92
+ .must_be_parsed_as s(:iter,
93
+ s(:call, nil, :foo),
94
+ s(:args),
95
+ s(:call, nil, :bar))
96
96
  end
97
97
 
98
- it 'ignores a trailing comma in the block parameters' do
99
- 'foo do |bar, | end'.
100
- must_be_parsed_as s(:iter,
101
- s(:call, nil, :foo),
102
- s(:args, :bar))
98
+ it "handles a trailing comma in the block parameters" do
99
+ _("foo do |bar, | end")
100
+ .must_be_parsed_as s(:iter,
101
+ s(:call, nil, :foo),
102
+ s(:args, :bar, nil))
103
103
  end
104
104
 
105
- it 'works with zero arguments' do
106
- 'foo do ||; end'.
107
- must_be_parsed_as s(:iter,
108
- s(:call, nil, :foo),
109
- s(:args))
105
+ it "works with zero arguments" do
106
+ _("foo do ||; end")
107
+ .must_be_parsed_as s(:iter,
108
+ s(:call, nil, :foo),
109
+ s(:args))
110
110
  end
111
111
 
112
- it 'works with one argument' do
113
- 'foo do |bar|; end'.
114
- must_be_parsed_as s(:iter,
115
- s(:call, nil, :foo),
116
- s(:args, :bar))
112
+ it "works with one argument" do
113
+ _("foo do |bar|; end")
114
+ .must_be_parsed_as s(:iter,
115
+ s(:call, nil, :foo),
116
+ s(:args, :bar))
117
117
  end
118
118
 
119
- it 'works with multiple arguments' do
120
- 'foo do |bar, baz|; end'.
121
- must_be_parsed_as s(:iter,
122
- s(:call, nil, :foo),
123
- s(:args, :bar, :baz))
119
+ it "works with multiple arguments" do
120
+ _("foo do |bar, baz|; end")
121
+ .must_be_parsed_as s(:iter,
122
+ s(:call, nil, :foo),
123
+ s(:args, :bar, :baz))
124
124
  end
125
125
 
126
- it 'works with an argument with a default value' do
127
- 'foo do |bar=baz|; end'.
128
- must_be_parsed_as s(:iter,
129
- s(:call, nil, :foo),
130
- s(:args,
131
- s(:lasgn, :bar, s(:call, nil, :baz))))
126
+ it "works with an argument with a default value" do
127
+ _("foo do |bar=baz|; end")
128
+ .must_be_parsed_as s(:iter,
129
+ s(:call, nil, :foo),
130
+ s(:args,
131
+ s(:lasgn, :bar, s(:call, nil, :baz))))
132
132
  end
133
133
 
134
- it 'works with a keyword argument with no default value' do
135
- 'foo do |bar:|; end'.
136
- must_be_parsed_as s(:iter,
137
- s(:call, nil, :foo),
138
- s(:args,
139
- s(:kwarg, :bar)))
134
+ it "works with a keyword argument with no default value" do
135
+ _("foo do |bar:|; end")
136
+ .must_be_parsed_as s(:iter,
137
+ s(:call, nil, :foo),
138
+ s(:args,
139
+ s(:kwarg, :bar)))
140
140
  end
141
141
 
142
- it 'works with a keyword argument with a default value' do
143
- 'foo do |bar: baz|; end'.
144
- must_be_parsed_as s(:iter,
145
- s(:call, nil, :foo),
146
- s(:args,
147
- s(:kwarg, :bar, s(:call, nil, :baz))))
142
+ it "works with a keyword argument with a default value" do
143
+ _("foo do |bar: baz|; end")
144
+ .must_be_parsed_as s(:iter,
145
+ s(:call, nil, :foo),
146
+ s(:args,
147
+ s(:kwarg, :bar, s(:call, nil, :baz))))
148
148
  end
149
149
 
150
- it 'works with a single splat argument' do
151
- 'foo do |*bar|; end'.
152
- must_be_parsed_as s(:iter,
153
- s(:call, nil, :foo),
154
- s(:args, :"*bar"))
150
+ it "works with a single splat argument" do
151
+ _("foo do |*bar|; end")
152
+ .must_be_parsed_as s(:iter,
153
+ s(:call, nil, :foo),
154
+ s(:args, :"*bar"))
155
155
  end
156
156
 
157
- it 'works with a combination of regular arguments and a splat argument' do
158
- 'foo do |bar, *baz|; end'.
159
- must_be_parsed_as s(:iter,
160
- s(:call, nil, :foo),
161
- s(:args, :bar, :"*baz"))
157
+ it "works with a combination of regular arguments and a splat argument" do
158
+ _("foo do |bar, *baz|; end")
159
+ .must_be_parsed_as s(:iter,
160
+ s(:call, nil, :foo),
161
+ s(:args, :bar, :"*baz"))
162
162
  end
163
163
 
164
- it 'works with a kwrest argument' do
165
- 'foo do |**bar|; baz bar; end'.
166
- must_be_parsed_as s(:iter,
167
- s(:call, nil, :foo),
168
- s(:args, :"**bar"),
169
- s(:call, nil, :baz,
170
- s(:lvar, :bar)))
164
+ it "works with a kwrest argument" do
165
+ _("foo do |**bar|; baz bar; end")
166
+ .must_be_parsed_as s(:iter,
167
+ s(:call, nil, :foo),
168
+ s(:args, :"**bar"),
169
+ s(:call, nil, :baz,
170
+ s(:lvar, :bar)))
171
171
  end
172
172
 
173
- it 'works with a regular argument after a splat argument' do
174
- 'foo do |*bar, baz|; end'.
175
- must_be_parsed_as s(:iter,
176
- s(:call, nil, :foo),
177
- s(:args, :"*bar", :baz))
173
+ it "works with a regular argument after a splat argument" do
174
+ _("foo do |*bar, baz|; end")
175
+ .must_be_parsed_as s(:iter,
176
+ s(:call, nil, :foo),
177
+ s(:args, :"*bar", :baz))
178
178
  end
179
179
 
180
- it 'works with a combination of regular arguments and a kwrest argument' do
181
- 'foo do |bar, **baz|; qux bar, baz; end'.
182
- must_be_parsed_as s(:iter,
183
- s(:call, nil, :foo),
184
- s(:args, :bar, :"**baz"),
185
- s(:call, nil, :qux,
186
- s(:lvar, :bar),
187
- s(:lvar, :baz)))
180
+ it "works with a combination of regular arguments and a kwrest argument" do
181
+ _("foo do |bar, **baz|; qux bar, baz; end")
182
+ .must_be_parsed_as s(:iter,
183
+ s(:call, nil, :foo),
184
+ s(:args, :bar, :"**baz"),
185
+ s(:call, nil, :qux,
186
+ s(:lvar, :bar),
187
+ s(:lvar, :baz)))
188
188
  end
189
189
  end
190
190
 
191
- describe 'for begin' do
192
- it 'works for an empty begin..end block' do
193
- 'begin end'.must_be_parsed_as s(:nil)
191
+ describe "for begin" do
192
+ it "works for an empty begin..end block" do
193
+ _("begin end").must_be_parsed_as s(:nil)
194
194
  end
195
195
 
196
- it 'works for a simple begin..end block' do
197
- 'begin; foo; end'.must_be_parsed_as s(:call, nil, :foo)
196
+ it "works for a simple begin..end block" do
197
+ _("begin; foo; end").must_be_parsed_as s(:call, nil, :foo)
198
198
  end
199
199
 
200
- it 'works for begin..end block with more than one statement' do
201
- 'begin; foo; bar; end'.
202
- must_be_parsed_as s(:block,
203
- s(:call, nil, :foo),
204
- s(:call, nil, :bar))
200
+ it "works for begin..end block with more than one statement" do
201
+ _("begin; foo; bar; end")
202
+ .must_be_parsed_as s(:block,
203
+ s(:call, nil, :foo),
204
+ s(:call, nil, :bar))
205
205
  end
206
206
 
207
- it 'keeps :begin for the truepart of a postfix if' do
208
- 'begin; foo; end if bar'.
209
- must_be_parsed_as s(:if,
210
- s(:call, nil, :bar),
211
- s(:begin, s(:call, nil, :foo)),
212
- nil)
207
+ it "keeps :begin for the truepart of a postfix if" do
208
+ _("begin; foo; end if bar")
209
+ .must_be_parsed_as s(:if,
210
+ s(:call, nil, :bar),
211
+ s(:begin, s(:call, nil, :foo)),
212
+ nil)
213
213
  end
214
214
 
215
- it 'keeps :begin for the falsepart of a postfix unless' do
216
- 'begin; foo; end unless bar'.
217
- must_be_parsed_as s(:if,
218
- s(:call, nil, :bar),
219
- nil,
220
- s(:begin, s(:call, nil, :foo)))
215
+ it "keeps :begin for the falsepart of a postfix unless" do
216
+ _("begin; foo; end unless bar")
217
+ .must_be_parsed_as s(:if,
218
+ s(:call, nil, :bar),
219
+ nil,
220
+ s(:begin, s(:call, nil, :foo)))
221
221
  end
222
222
  end
223
223
 
224
- describe 'for rescue/else' do
225
- it 'works for a block with multiple rescue statements' do
226
- 'begin foo; rescue; bar; rescue; baz; end'.
227
- must_be_parsed_as s(:rescue,
228
- s(:call, nil, :foo),
229
- s(:resbody,
230
- s(:array),
231
- s(:call, nil, :bar)),
232
- s(:resbody,
233
- s(:array),
234
- s(:call, nil, :baz)))
235
- end
236
-
237
- it 'works for a block with rescue and else' do
238
- 'begin; foo; rescue; bar; else; baz; end'.
239
- must_be_parsed_as s(:rescue,
240
- s(:call, nil, :foo),
241
- s(:resbody,
242
- s(:array),
243
- s(:call, nil, :bar)),
244
- s(:call, nil, :baz))
245
- end
246
-
247
- it 'works for a block with only else' do
248
- 'begin; foo; else; bar; end'.
249
- must_be_parsed_as s(:block,
250
- s(:call, nil, :foo),
251
- s(:call, nil, :bar))
224
+ describe "for rescue/else" do
225
+ it "works for a block with multiple rescue statements" do
226
+ _("begin foo; rescue; bar; rescue; baz; end")
227
+ .must_be_parsed_as s(:rescue,
228
+ s(:call, nil, :foo),
229
+ s(:resbody,
230
+ s(:array),
231
+ s(:call, nil, :bar)),
232
+ s(:resbody,
233
+ s(:array),
234
+ s(:call, nil, :baz)))
235
+ end
236
+
237
+ it "works for a block with rescue and else" do
238
+ _("begin; foo; rescue; bar; else; baz; end")
239
+ .must_be_parsed_as s(:rescue,
240
+ s(:call, nil, :foo),
241
+ s(:resbody,
242
+ s(:array),
243
+ s(:call, nil, :bar)),
244
+ s(:call, nil, :baz))
245
+ end
246
+
247
+ it "works for a block with only else" do
248
+ _("begin; foo; else; bar; end")
249
+ .must_be_parsed_as s(:block,
250
+ s(:call, nil, :foo),
251
+ s(:call, nil, :bar))
252
252
  end
253
253
  end
254
254
 
255
- describe 'for the rescue statement' do
256
- it 'works with assignment to an error variable' do
257
- 'begin; foo; rescue => bar; baz; end'.
258
- must_be_parsed_as s(:rescue,
259
- s(:call, nil, :foo),
260
- s(:resbody,
261
- s(:array,
262
- s(:lasgn, :bar, s(:gvar, :$!))),
263
- s(:call, nil, :baz)))
264
- end
265
-
266
- it 'works with assignment of the exception to an instance variable' do
267
- 'begin; foo; rescue => @bar; baz; end'.
268
- must_be_parsed_as s(:rescue,
269
- s(:call, nil, :foo),
270
- s(:resbody,
271
- s(:array,
272
- s(:iasgn, :@bar, s(:gvar, :$!))),
273
- s(:call, nil, :baz)))
274
- end
275
-
276
- it 'works with empty main and rescue bodies' do
277
- 'begin; rescue; end'.
278
- must_be_parsed_as s(:rescue,
279
- s(:resbody, s(:array), nil))
280
- end
281
-
282
- it 'works with single statement main and rescue bodies' do
283
- 'begin; foo; rescue; bar; end'.
284
- must_be_parsed_as s(:rescue,
285
- s(:call, nil, :foo),
286
- s(:resbody,
287
- s(:array),
288
- s(:call, nil, :bar)))
289
- end
290
-
291
- it 'works with multi-statement main and rescue bodies' do
292
- 'begin; foo; bar; rescue; baz; qux; end'.
293
- must_be_parsed_as s(:rescue,
294
- s(:block,
295
- s(:call, nil, :foo),
296
- s(:call, nil, :bar)),
297
- s(:resbody,
298
- s(:array),
299
- s(:call, nil, :baz),
300
- s(:call, nil, :qux)))
301
- end
302
-
303
- it 'works with assignment to an error variable' do
304
- 'begin; foo; rescue => e; bar; end'.
305
- must_be_parsed_as s(:rescue,
306
- s(:call, nil, :foo),
307
- s(:resbody,
308
- s(:array, s(:lasgn, :e, s(:gvar, :$!))),
309
- s(:call, nil, :bar)))
310
- end
311
-
312
- it 'works with filtering of the exception type' do
313
- 'begin; foo; rescue Bar; baz; end'.
314
- must_be_parsed_as s(:rescue,
315
- s(:call, nil, :foo),
316
- s(:resbody,
317
- s(:array, s(:const, :Bar)),
318
- s(:call, nil, :baz)))
319
- end
320
-
321
- it 'works with filtering of the exception type and assignment to an error variable' do
322
- 'begin; foo; rescue Bar => e; baz; end'.
323
- must_be_parsed_as s(:rescue,
324
- s(:call, nil, :foo),
325
- s(:resbody,
326
- s(:array,
327
- s(:const, :Bar),
328
- s(:lasgn, :e, s(:gvar, :$!))),
329
- s(:call, nil, :baz)))
330
- end
331
-
332
- it 'works rescuing multiple exception types' do
333
- 'begin; foo; rescue Bar, Baz; qux; end'.
334
- must_be_parsed_as s(:rescue,
335
- s(:call, nil, :foo),
336
- s(:resbody,
337
- s(:array, s(:const, :Bar), s(:const, :Baz)),
338
- s(:call, nil, :qux)))
339
- end
340
-
341
- it 'works rescuing a splatted list of exception types' do
342
- 'begin; foo; rescue *bar; baz; end'.
343
- must_be_parsed_as s(:rescue,
344
- s(:call, nil, :foo),
345
- s(:resbody,
346
- s(:splat, s(:call, nil, :bar)),
347
- s(:call, nil, :baz)))
348
- end
349
-
350
- it 'works rescuing a complex list of exception types' do
351
- 'begin; foo; rescue *bar, Baz; qux; end'.
352
- must_be_parsed_as s(:rescue,
353
- s(:call, nil, :foo),
354
- s(:resbody,
355
- s(:array,
356
- s(:splat, s(:call, nil, :bar)),
357
- s(:const, :Baz)),
358
- s(:call, nil, :qux)))
359
- end
360
-
361
- it 'works with a nested begin..end block' do
362
- 'begin; foo; rescue; begin; bar; end; end'.
363
- must_be_parsed_as s(:rescue,
364
- s(:call, nil, :foo),
365
- s(:resbody, s(:array),
366
- s(:call, nil, :bar)))
367
- end
368
-
369
- it 'works in a plain method body' do
370
- 'def foo; bar; rescue; baz; end'.
371
- must_be_parsed_as s(:defn,
372
- :foo,
373
- s(:args),
374
- s(:rescue,
375
- s(:call, nil, :bar),
376
- s(:resbody,
377
- s(:array),
378
- s(:call, nil, :baz))))
379
- end
380
-
381
- it 'works in a method body inside begin..end with rescue' do
382
- 'def foo; bar; begin; baz; rescue; qux; end; quuz; end'.
383
- must_be_parsed_as s(:defn,
384
- :foo,
385
- s(:args),
386
- s(:call, nil, :bar),
387
- s(:rescue,
388
- s(:call, nil, :baz),
389
- s(:resbody, s(:array), s(:call, nil, :qux))),
390
- s(:call, nil, :quuz))
391
- end
392
-
393
- it 'works in a method body inside begin..end without rescue' do
394
- 'def foo; bar; begin; baz; qux; end; quuz; end'.
395
- must_be_parsed_as s(:defn,
396
- :foo,
397
- s(:args),
398
- s(:call, nil, :bar),
399
- s(:block,
400
- s(:call, nil, :baz),
401
- s(:call, nil, :qux)),
402
- s(:call, nil, :quuz))
403
- end
404
-
405
- it 'works in a method body fully inside begin..end' do
406
- 'def foo; begin; bar; baz; end; end'.
407
- must_be_parsed_as s(:defn,
408
- :foo,
409
- s(:args),
410
- s(:call, nil, :bar),
411
- s(:call, nil, :baz))
255
+ describe "for the rescue statement" do
256
+ it "works with assignment to an error variable" do
257
+ _("begin; foo; rescue => bar; baz; end")
258
+ .must_be_parsed_as s(:rescue,
259
+ s(:call, nil, :foo),
260
+ s(:resbody,
261
+ s(:array,
262
+ s(:lasgn, :bar, s(:gvar, :$!))),
263
+ s(:call, nil, :baz)))
264
+ end
265
+
266
+ it "works with assignment of the exception to an instance variable" do
267
+ _("begin; foo; rescue => @bar; baz; end")
268
+ .must_be_parsed_as s(:rescue,
269
+ s(:call, nil, :foo),
270
+ s(:resbody,
271
+ s(:array,
272
+ s(:iasgn, :@bar, s(:gvar, :$!))),
273
+ s(:call, nil, :baz)))
274
+ end
275
+
276
+ it "works with empty main and rescue bodies" do
277
+ _("begin; rescue; end")
278
+ .must_be_parsed_as s(:rescue,
279
+ s(:resbody, s(:array), nil))
280
+ end
281
+
282
+ it "works with single statement main and rescue bodies" do
283
+ _("begin; foo; rescue; bar; end")
284
+ .must_be_parsed_as s(:rescue,
285
+ s(:call, nil, :foo),
286
+ s(:resbody,
287
+ s(:array),
288
+ s(:call, nil, :bar)))
289
+ end
290
+
291
+ it "works with multi-statement main and rescue bodies" do
292
+ _("begin; foo; bar; rescue; baz; qux; end")
293
+ .must_be_parsed_as s(:rescue,
294
+ s(:block,
295
+ s(:call, nil, :foo),
296
+ s(:call, nil, :bar)),
297
+ s(:resbody,
298
+ s(:array),
299
+ s(:call, nil, :baz),
300
+ s(:call, nil, :qux)))
301
+ end
302
+
303
+ it "works with assignment to an error variable" do
304
+ _("begin; foo; rescue => e; bar; end")
305
+ .must_be_parsed_as s(:rescue,
306
+ s(:call, nil, :foo),
307
+ s(:resbody,
308
+ s(:array, s(:lasgn, :e, s(:gvar, :$!))),
309
+ s(:call, nil, :bar)))
310
+ end
311
+
312
+ it "works with filtering of the exception type" do
313
+ _("begin; foo; rescue Bar; baz; end")
314
+ .must_be_parsed_as s(:rescue,
315
+ s(:call, nil, :foo),
316
+ s(:resbody,
317
+ s(:array, s(:const, :Bar)),
318
+ s(:call, nil, :baz)))
319
+ end
320
+
321
+ it "works with filtering of the exception type and assignment to an error variable" do
322
+ _("begin; foo; rescue Bar => e; baz; end")
323
+ .must_be_parsed_as s(:rescue,
324
+ s(:call, nil, :foo),
325
+ s(:resbody,
326
+ s(:array,
327
+ s(:const, :Bar),
328
+ s(:lasgn, :e, s(:gvar, :$!))),
329
+ s(:call, nil, :baz)))
330
+ end
331
+
332
+ it "works rescuing multiple exception types" do
333
+ _("begin; foo; rescue Bar, Baz; qux; end")
334
+ .must_be_parsed_as s(:rescue,
335
+ s(:call, nil, :foo),
336
+ s(:resbody,
337
+ s(:array, s(:const, :Bar), s(:const, :Baz)),
338
+ s(:call, nil, :qux)))
339
+ end
340
+
341
+ it "works rescuing a splatted list of exception types" do
342
+ _("begin; foo; rescue *bar; baz; end")
343
+ .must_be_parsed_as s(:rescue,
344
+ s(:call, nil, :foo),
345
+ s(:resbody,
346
+ s(:splat, s(:call, nil, :bar)),
347
+ s(:call, nil, :baz)))
348
+ end
349
+
350
+ it "works rescuing a complex list of exception types" do
351
+ _("begin; foo; rescue *bar, Baz; qux; end")
352
+ .must_be_parsed_as s(:rescue,
353
+ s(:call, nil, :foo),
354
+ s(:resbody,
355
+ s(:array,
356
+ s(:splat, s(:call, nil, :bar)),
357
+ s(:const, :Baz)),
358
+ s(:call, nil, :qux)))
359
+ end
360
+
361
+ it "works with a nested begin..end block" do
362
+ _("begin; foo; rescue; begin; bar; end; end")
363
+ .must_be_parsed_as s(:rescue,
364
+ s(:call, nil, :foo),
365
+ s(:resbody, s(:array),
366
+ s(:call, nil, :bar)))
367
+ end
368
+
369
+ it "works in a plain method body" do
370
+ _("def foo; bar; rescue; baz; end")
371
+ .must_be_parsed_as s(:defn,
372
+ :foo,
373
+ s(:args),
374
+ s(:rescue,
375
+ s(:call, nil, :bar),
376
+ s(:resbody,
377
+ s(:array),
378
+ s(:call, nil, :baz))))
379
+ end
380
+
381
+ it "works in a method body inside begin..end with rescue" do
382
+ _("def foo; bar; begin; baz; rescue; qux; end; quuz; end")
383
+ .must_be_parsed_as s(:defn,
384
+ :foo,
385
+ s(:args),
386
+ s(:call, nil, :bar),
387
+ s(:rescue,
388
+ s(:call, nil, :baz),
389
+ s(:resbody, s(:array), s(:call, nil, :qux))),
390
+ s(:call, nil, :quuz))
391
+ end
392
+
393
+ it "works in a method body inside begin..end without rescue" do
394
+ _("def foo; bar; begin; baz; qux; end; quuz; end")
395
+ .must_be_parsed_as s(:defn,
396
+ :foo,
397
+ s(:args),
398
+ s(:call, nil, :bar),
399
+ s(:block,
400
+ s(:call, nil, :baz),
401
+ s(:call, nil, :qux)),
402
+ s(:call, nil, :quuz))
403
+ end
404
+
405
+ it "works in a method body fully inside begin..end" do
406
+ _("def foo; begin; bar; baz; end; end")
407
+ .must_be_parsed_as s(:defn,
408
+ :foo,
409
+ s(:args),
410
+ s(:call, nil, :bar),
411
+ s(:call, nil, :baz))
412
412
  end
413
413
  end
414
414
 
415
- describe 'for the postfix rescue modifier' do
416
- it 'works in the basic case' do
417
- 'foo rescue bar'.
418
- must_be_parsed_as s(:rescue,
419
- s(:call, nil, :foo),
420
- s(:resbody,
421
- s(:array),
422
- s(:call, nil, :bar)))
415
+ describe "for the postfix rescue modifier" do
416
+ it "works in the basic case" do
417
+ _("foo rescue bar")
418
+ .must_be_parsed_as s(:rescue,
419
+ s(:call, nil, :foo),
420
+ s(:resbody,
421
+ s(:array),
422
+ s(:call, nil, :bar)))
423
423
  end
424
424
 
425
- it 'works when the fallback value is a keyword' do
426
- 'foo rescue next'.
427
- must_be_parsed_as s(:rescue,
428
- s(:call, nil, :foo),
429
- s(:resbody,
430
- s(:array),
431
- s(:next)))
425
+ it "works when the fallback value is a keyword" do
426
+ _("foo rescue next")
427
+ .must_be_parsed_as s(:rescue,
428
+ s(:call, nil, :foo),
429
+ s(:resbody,
430
+ s(:array),
431
+ s(:next)))
432
432
  end
433
433
  end
434
434
 
435
- describe 'for the ensure statement' do
436
- it 'works with single statement main and ensure bodies' do
437
- 'begin; foo; ensure; bar; end'.
438
- must_be_parsed_as s(:ensure,
439
- s(:call, nil, :foo),
440
- s(:call, nil, :bar))
435
+ describe "for the ensure statement" do
436
+ it "works with single statement main and ensure bodies" do
437
+ _("begin; foo; ensure; bar; end")
438
+ .must_be_parsed_as s(:ensure,
439
+ s(:call, nil, :foo),
440
+ s(:call, nil, :bar))
441
441
  end
442
442
 
443
- it 'works with multi-statement main and ensure bodies' do
444
- 'begin; foo; bar; ensure; baz; qux; end'.
445
- must_be_parsed_as s(:ensure,
446
- s(:block,
447
- s(:call, nil, :foo),
448
- s(:call, nil, :bar)),
449
- s(:block,
450
- s(:call, nil, :baz),
451
- s(:call, nil, :qux)))
443
+ it "works with multi-statement main and ensure bodies" do
444
+ _("begin; foo; bar; ensure; baz; qux; end")
445
+ .must_be_parsed_as s(:ensure,
446
+ s(:block,
447
+ s(:call, nil, :foo),
448
+ s(:call, nil, :bar)),
449
+ s(:block,
450
+ s(:call, nil, :baz),
451
+ s(:call, nil, :qux)))
452
452
  end
453
453
 
454
- it 'works together with rescue' do
455
- 'begin; foo; rescue; bar; ensure; baz; end'.
456
- must_be_parsed_as s(:ensure,
457
- s(:rescue,
458
- s(:call, nil, :foo),
459
- s(:resbody,
460
- s(:array),
461
- s(:call, nil, :bar))),
462
- s(:call, nil, :baz))
454
+ it "works together with rescue" do
455
+ _("begin; foo; rescue; bar; ensure; baz; end")
456
+ .must_be_parsed_as s(:ensure,
457
+ s(:rescue,
458
+ s(:call, nil, :foo),
459
+ s(:resbody,
460
+ s(:array),
461
+ s(:call, nil, :bar))),
462
+ s(:call, nil, :baz))
463
463
  end
464
464
 
465
- it 'works with empty main and ensure bodies' do
466
- 'begin; ensure; end'.
467
- must_be_parsed_as s(:ensure, s(:nil))
465
+ it "works with empty main and ensure bodies" do
466
+ _("begin; ensure; end")
467
+ .must_be_parsed_as s(:ensure, s(:nil))
468
468
  end
469
469
  end
470
470
 
471
- describe 'for the next statement' do
472
- it 'works with no arguments' do
473
- 'foo do; next; end'.
474
- must_be_parsed_as s(:iter,
475
- s(:call, nil, :foo),
476
- 0,
477
- s(:next))
478
- end
479
-
480
- it 'works with one argument' do
481
- 'foo do; next bar; end'.
482
- must_be_parsed_as s(:iter,
483
- s(:call, nil, :foo),
484
- 0,
485
- s(:next, s(:call, nil, :bar)))
486
- end
487
-
488
- it 'works with a splat argument' do
489
- 'foo do; next *bar; end'.
490
- must_be_parsed_as s(:iter,
491
- s(:call, nil, :foo),
492
- 0,
493
- s(:next,
494
- s(:svalue,
495
- s(:splat,
496
- s(:call, nil, :bar)))))
497
- end
498
-
499
- it 'works with several arguments' do
500
- 'foo do; next bar, baz; end'.
501
- must_be_parsed_as s(:iter,
502
- s(:call, nil, :foo),
503
- 0,
504
- s(:next,
505
- s(:array,
506
- s(:call, nil, :bar),
507
- s(:call, nil, :baz))))
508
- end
509
-
510
- it 'works with a function call with parentheses' do
511
- 'foo do; next foo(bar); end'.
512
- must_be_parsed_as s(:iter,
513
- s(:call, nil, :foo),
514
- 0,
515
- s(:next,
516
- s(:call, nil, :foo,
517
- s(:call, nil, :bar))))
518
- end
519
-
520
- it 'works with a function call without parentheses' do
521
- 'foo do; next foo bar; end'.
522
- must_be_parsed_as s(:iter,
523
- s(:call, nil, :foo),
524
- 0,
525
- s(:next,
526
- s(:call, nil, :foo,
527
- s(:call, nil, :bar))))
471
+ describe "for the next statement" do
472
+ it "works with no arguments" do
473
+ _("foo do; next; end")
474
+ .must_be_parsed_as s(:iter,
475
+ s(:call, nil, :foo),
476
+ 0,
477
+ s(:next))
478
+ end
479
+
480
+ it "works with one argument" do
481
+ _("foo do; next bar; end")
482
+ .must_be_parsed_as s(:iter,
483
+ s(:call, nil, :foo),
484
+ 0,
485
+ s(:next, s(:call, nil, :bar)))
486
+ end
487
+
488
+ it "works with a splat argument" do
489
+ _("foo do; next *bar; end")
490
+ .must_be_parsed_as s(:iter,
491
+ s(:call, nil, :foo),
492
+ 0,
493
+ s(:next,
494
+ s(:svalue,
495
+ s(:splat,
496
+ s(:call, nil, :bar)))))
497
+ end
498
+
499
+ it "works with several arguments" do
500
+ _("foo do; next bar, baz; end")
501
+ .must_be_parsed_as s(:iter,
502
+ s(:call, nil, :foo),
503
+ 0,
504
+ s(:next,
505
+ s(:array,
506
+ s(:call, nil, :bar),
507
+ s(:call, nil, :baz))))
508
+ end
509
+
510
+ it "works with a function call with parentheses" do
511
+ _("foo do; next foo(bar); end")
512
+ .must_be_parsed_as s(:iter,
513
+ s(:call, nil, :foo),
514
+ 0,
515
+ s(:next,
516
+ s(:call, nil, :foo,
517
+ s(:call, nil, :bar))))
518
+ end
519
+
520
+ it "works with a function call without parentheses" do
521
+ _("foo do; next foo bar; end")
522
+ .must_be_parsed_as s(:iter,
523
+ s(:call, nil, :foo),
524
+ 0,
525
+ s(:next,
526
+ s(:call, nil, :foo,
527
+ s(:call, nil, :bar))))
528
528
  end
529
529
  end
530
530
 
531
- describe 'for the break statement' do
532
- it 'works with break with no arguments' do
533
- 'foo do; break; end'.
534
- must_be_parsed_as s(:iter,
535
- s(:call, nil, :foo),
536
- 0,
537
- s(:break))
538
- end
539
-
540
- it 'works with break with one argument' do
541
- 'foo do; break bar; end'.
542
- must_be_parsed_as s(:iter,
543
- s(:call, nil, :foo),
544
- 0,
545
- s(:break, s(:call, nil, :bar)))
546
- end
547
-
548
- it 'works with a splat argument' do
549
- 'foo do; break *bar; end'.
550
- must_be_parsed_as s(:iter,
551
- s(:call, nil, :foo),
552
- 0,
553
- s(:break,
554
- s(:svalue,
555
- s(:splat,
556
- s(:call, nil, :bar)))))
557
- end
558
-
559
- it 'works with break with several arguments' do
560
- 'foo do; break bar, baz; end'.
561
- must_be_parsed_as s(:iter,
562
- s(:call, nil, :foo),
563
- 0,
564
- s(:break,
565
- s(:array,
566
- s(:call, nil, :bar),
567
- s(:call, nil, :baz))))
568
- end
569
-
570
- it 'works with break with a function call with parentheses' do
571
- 'foo do; break foo(bar); end'.
572
- must_be_parsed_as s(:iter,
573
- s(:call, nil, :foo),
574
- 0,
575
- s(:break,
576
- s(:call, nil, :foo,
577
- s(:call, nil, :bar))))
578
- end
579
-
580
- it 'works with break with a function call without parentheses' do
581
- 'foo do; break foo bar; end'.
582
- must_be_parsed_as s(:iter,
583
- s(:call, nil, :foo),
584
- 0,
585
- s(:break,
586
- s(:call, nil, :foo,
587
- s(:call, nil, :bar))))
531
+ describe "for the break statement" do
532
+ it "works with break with no arguments" do
533
+ _("foo do; break; end")
534
+ .must_be_parsed_as s(:iter,
535
+ s(:call, nil, :foo),
536
+ 0,
537
+ s(:break))
538
+ end
539
+
540
+ it "works with break with one argument" do
541
+ _("foo do; break bar; end")
542
+ .must_be_parsed_as s(:iter,
543
+ s(:call, nil, :foo),
544
+ 0,
545
+ s(:break, s(:call, nil, :bar)))
546
+ end
547
+
548
+ it "works with a splat argument" do
549
+ _("foo do; break *bar; end")
550
+ .must_be_parsed_as s(:iter,
551
+ s(:call, nil, :foo),
552
+ 0,
553
+ s(:break,
554
+ s(:svalue,
555
+ s(:splat,
556
+ s(:call, nil, :bar)))))
557
+ end
558
+
559
+ it "works with break with several arguments" do
560
+ _("foo do; break bar, baz; end")
561
+ .must_be_parsed_as s(:iter,
562
+ s(:call, nil, :foo),
563
+ 0,
564
+ s(:break,
565
+ s(:array,
566
+ s(:call, nil, :bar),
567
+ s(:call, nil, :baz))))
568
+ end
569
+
570
+ it "works with break with a function call with parentheses" do
571
+ _("foo do; break foo(bar); end")
572
+ .must_be_parsed_as s(:iter,
573
+ s(:call, nil, :foo),
574
+ 0,
575
+ s(:break,
576
+ s(:call, nil, :foo,
577
+ s(:call, nil, :bar))))
578
+ end
579
+
580
+ it "works with break with a function call without parentheses" do
581
+ _("foo do; break foo bar; end")
582
+ .must_be_parsed_as s(:iter,
583
+ s(:call, nil, :foo),
584
+ 0,
585
+ s(:break,
586
+ s(:call, nil, :foo,
587
+ s(:call, nil, :bar))))
588
588
  end
589
589
  end
590
590
 
591
- describe 'for lists of consecutive statments' do
592
- it 'removes extra blocks for grouped statements at the start of the list' do
593
- '(foo; bar); baz'.
594
- must_be_parsed_as s(:block,
595
- s(:call, nil, :foo),
596
- s(:call, nil, :bar),
597
- s(:call, nil, :baz))
591
+ describe "for lists of consecutive statments" do
592
+ it "removes extra blocks for grouped statements at the start of the list" do
593
+ _("(foo; bar); baz")
594
+ .must_be_parsed_as s(:block,
595
+ s(:call, nil, :foo),
596
+ s(:call, nil, :bar),
597
+ s(:call, nil, :baz))
598
598
  end
599
599
 
600
- it 'keeps extra blocks for grouped statements at the end of the list' do
601
- 'foo; (bar; baz)'.
602
- must_be_parsed_as s(:block,
603
- s(:call, nil, :foo),
604
- s(:block,
605
- s(:call, nil, :bar),
606
- s(:call, nil, :baz)))
600
+ it "keeps extra blocks for grouped statements at the end of the list" do
601
+ _("foo; (bar; baz)")
602
+ .must_be_parsed_as s(:block,
603
+ s(:call, nil, :foo),
604
+ s(:block,
605
+ s(:call, nil, :bar),
606
+ s(:call, nil, :baz)))
607
607
  end
608
608
  end
609
609
 
610
- describe 'for stabby lambda' do
611
- it 'works in the simple case' do
612
- '->(foo) { bar }'.
613
- must_be_parsed_as s(:iter,
614
- s(:call, nil, :lambda),
615
- s(:args, :foo),
616
- s(:call, nil, :bar))
617
- end
618
-
619
- it 'works in the simple case without parentheses' do
620
- '-> foo { bar }'.
621
- must_be_parsed_as s(:iter,
622
- s(:call, nil, :lambda),
623
- s(:args, :foo),
624
- s(:call, nil, :bar))
625
- end
626
-
627
- it 'works when there are zero arguments' do
628
- '->() { bar }'.
629
- must_be_parsed_as s(:iter,
630
- s(:call, nil, :lambda),
631
- s(:args),
632
- s(:call, nil, :bar))
633
- end
634
-
635
- it 'works when there are no arguments' do
636
- '-> { bar }'.
637
- must_be_parsed_as s(:iter,
638
- s(:call, nil, :lambda),
639
- 0,
640
- s(:call, nil, :bar))
641
- end
642
-
643
- it 'works when there are no statements in the body' do
644
- '->(foo) { }'.
645
- must_be_parsed_as s(:iter,
646
- s(:call, nil, :lambda),
647
- s(:args, :foo))
648
- end
649
-
650
- it 'works when there are several statements in the body' do
651
- '->(foo) { bar; baz }'.
652
- must_be_parsed_as s(:iter,
653
- s(:call, nil, :lambda),
654
- s(:args, :foo),
655
- s(:block,
656
- s(:call, nil, :bar),
657
- s(:call, nil, :baz)))
610
+ describe "for stabby lambda" do
611
+ it "works in the simple case" do
612
+ _("->(foo) { bar }")
613
+ .must_be_parsed_as s(:iter,
614
+ s(:lambda),
615
+ s(:args, :foo),
616
+ s(:call, nil, :bar))
617
+ end
618
+
619
+ it "works in the simple case without parentheses" do
620
+ _("-> foo { bar }")
621
+ .must_be_parsed_as s(:iter,
622
+ s(:lambda),
623
+ s(:args, :foo),
624
+ s(:call, nil, :bar))
625
+ end
626
+
627
+ it "works when there are zero arguments" do
628
+ _("->() { bar }")
629
+ .must_be_parsed_as s(:iter,
630
+ s(:lambda),
631
+ s(:args),
632
+ s(:call, nil, :bar))
633
+ end
634
+
635
+ it "works when there are no arguments" do
636
+ _("-> { bar }")
637
+ .must_be_parsed_as s(:iter,
638
+ s(:lambda),
639
+ 0,
640
+ s(:call, nil, :bar))
641
+ end
642
+
643
+ it "works when there are no statements in the body" do
644
+ _("->(foo) { }")
645
+ .must_be_parsed_as s(:iter,
646
+ s(:lambda),
647
+ s(:args, :foo))
648
+ end
649
+
650
+ it "works when there are several statements in the body" do
651
+ _("->(foo) { bar; baz }")
652
+ .must_be_parsed_as s(:iter,
653
+ s(:lambda),
654
+ s(:args, :foo),
655
+ s(:block,
656
+ s(:call, nil, :bar),
657
+ s(:call, nil, :baz)))
658
+ end
659
+ end
660
+
661
+ describe "for lambda keyword" do
662
+ it "works in the simple case" do
663
+ _("lambda { |foo| bar }")
664
+ .must_be_parsed_as s(:iter,
665
+ s(:call, nil, :lambda),
666
+ s(:args, :foo),
667
+ s(:call, nil, :bar))
668
+ end
669
+
670
+ it "works with trailing argument comma" do
671
+ _("lambda { |foo,| bar }")
672
+ .must_be_parsed_as s(:iter,
673
+ s(:call, nil, :lambda),
674
+ s(:args, :foo, nil),
675
+ s(:call, nil, :bar))
658
676
  end
659
677
  end
660
678
  end