ripper_ruby_parser 1.7.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,717 +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
|
-
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
|
-
end
|
40
|
-
end
|
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)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "for block parameters" do
|
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)))
|
58
|
-
end
|
59
|
-
|
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")))
|
66
|
-
end
|
67
|
-
|
68
|
-
specify do
|
69
|
-
_("foo do |bar,*| end")
|
70
|
-
.must_be_parsed_as s(:iter,
|
71
|
-
s(:call, nil, :foo),
|
72
|
-
s(:args, :bar, :"*"))
|
73
|
-
end
|
74
|
-
|
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"))
|
80
|
-
end
|
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))
|
88
|
-
end
|
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))
|
96
|
-
end
|
97
|
-
|
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
|
-
end
|
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))
|
110
|
-
end
|
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))
|
117
|
-
end
|
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))
|
124
|
-
end
|
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))))
|
132
|
-
end
|
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)))
|
140
|
-
end
|
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))))
|
148
|
-
end
|
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"))
|
155
|
-
end
|
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"))
|
162
|
-
end
|
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)))
|
171
|
-
end
|
172
|
-
|
173
|
-
it "works with a nameless kwrest argument" do
|
174
|
-
_("foo do |**|; bar; end")
|
175
|
-
.must_be_parsed_as s(:iter,
|
176
|
-
s(:call, nil, :foo),
|
177
|
-
s(:args, :**),
|
178
|
-
s(:call, nil, :bar))
|
179
|
-
end
|
180
|
-
|
181
|
-
it "works with a regular argument after a splat argument" do
|
182
|
-
_("foo do |*bar, baz|; end")
|
183
|
-
.must_be_parsed_as s(:iter,
|
184
|
-
s(:call, nil, :foo),
|
185
|
-
s(:args, :"*bar", :baz))
|
186
|
-
end
|
187
|
-
|
188
|
-
it "works with a combination of regular arguments and a kwrest argument" do
|
189
|
-
_("foo do |bar, **baz|; qux bar, baz; end")
|
190
|
-
.must_be_parsed_as s(:iter,
|
191
|
-
s(:call, nil, :foo),
|
192
|
-
s(:args, :bar, :"**baz"),
|
193
|
-
s(:call, nil, :qux,
|
194
|
-
s(:lvar, :bar),
|
195
|
-
s(:lvar, :baz)))
|
196
|
-
end
|
197
|
-
|
198
|
-
it "works with a combination of regular arguments and an anonymous kwrest argument" do
|
199
|
-
_("foo do |bar, **|; qux bar; end")
|
200
|
-
.must_be_parsed_as s(:iter,
|
201
|
-
s(:call, nil, :foo),
|
202
|
-
s(:args, :bar, :"**"),
|
203
|
-
s(:call, nil, :qux,
|
204
|
-
s(:lvar, :bar)))
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
describe "for begin" do
|
209
|
-
it "works for an empty begin..end block" do
|
210
|
-
_("begin end").must_be_parsed_as s(:nil)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "works for a simple begin..end block" do
|
214
|
-
_("begin; foo; end").must_be_parsed_as s(:call, nil, :foo)
|
215
|
-
end
|
216
|
-
|
217
|
-
it "works for begin..end block with more than one statement" do
|
218
|
-
_("begin; foo; bar; end")
|
219
|
-
.must_be_parsed_as s(:block,
|
220
|
-
s(:call, nil, :foo),
|
221
|
-
s(:call, nil, :bar))
|
222
|
-
end
|
223
|
-
|
224
|
-
it "keeps :begin for the truepart of a postfix if" do
|
225
|
-
_("begin; foo; end if bar")
|
226
|
-
.must_be_parsed_as s(:if,
|
227
|
-
s(:call, nil, :bar),
|
228
|
-
s(:begin, s(:call, nil, :foo)),
|
229
|
-
nil)
|
230
|
-
end
|
231
|
-
|
232
|
-
it "keeps :begin for the falsepart of a postfix unless" do
|
233
|
-
_("begin; foo; end unless bar")
|
234
|
-
.must_be_parsed_as s(:if,
|
235
|
-
s(:call, nil, :bar),
|
236
|
-
nil,
|
237
|
-
s(:begin, s(:call, nil, :foo)))
|
238
|
-
end
|
239
|
-
|
240
|
-
it "removes :begin for a method receiver" do
|
241
|
-
_("begin; foo; end.bar")
|
242
|
-
.must_be_parsed_as s(:call, s(:call, nil, :foo), :bar)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "for rescue/else" do
|
247
|
-
it "works for a block with multiple rescue statements" do
|
248
|
-
_("begin foo; rescue; bar; rescue; baz; end")
|
249
|
-
.must_be_parsed_as s(:rescue,
|
250
|
-
s(:call, nil, :foo),
|
251
|
-
s(:resbody,
|
252
|
-
s(:array),
|
253
|
-
s(:call, nil, :bar)),
|
254
|
-
s(:resbody,
|
255
|
-
s(:array),
|
256
|
-
s(:call, nil, :baz)))
|
257
|
-
end
|
258
|
-
|
259
|
-
it "works for a block with rescue and else" do
|
260
|
-
_("begin; foo; rescue; bar; else; baz; end")
|
261
|
-
.must_be_parsed_as s(:rescue,
|
262
|
-
s(:call, nil, :foo),
|
263
|
-
s(:resbody,
|
264
|
-
s(:array),
|
265
|
-
s(:call, nil, :bar)),
|
266
|
-
s(:call, nil, :baz))
|
267
|
-
end
|
268
|
-
|
269
|
-
it "works for a block with only else" do
|
270
|
-
_("begin; foo; else; bar; end")
|
271
|
-
.must_be_parsed_as s(:block,
|
272
|
-
s(:call, nil, :foo),
|
273
|
-
s(:call, nil, :bar))
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "for the rescue statement" do
|
278
|
-
it "works with assignment to an error variable" do
|
279
|
-
_("begin; foo; rescue => bar; baz; end")
|
280
|
-
.must_be_parsed_as s(:rescue,
|
281
|
-
s(:call, nil, :foo),
|
282
|
-
s(:resbody,
|
283
|
-
s(:array,
|
284
|
-
s(:lasgn, :bar, s(:gvar, :$!))),
|
285
|
-
s(:call, nil, :baz)))
|
286
|
-
end
|
287
|
-
|
288
|
-
it "works with assignment of the exception to an instance variable" do
|
289
|
-
_("begin; foo; rescue => @bar; baz; end")
|
290
|
-
.must_be_parsed_as s(:rescue,
|
291
|
-
s(:call, nil, :foo),
|
292
|
-
s(:resbody,
|
293
|
-
s(:array,
|
294
|
-
s(:iasgn, :@bar, s(:gvar, :$!))),
|
295
|
-
s(:call, nil, :baz)))
|
296
|
-
end
|
297
|
-
|
298
|
-
it "works with empty main and rescue bodies" do
|
299
|
-
_("begin; rescue; end")
|
300
|
-
.must_be_parsed_as s(:rescue,
|
301
|
-
s(:resbody, s(:array), nil))
|
302
|
-
end
|
303
|
-
|
304
|
-
it "works with single statement main and rescue bodies" do
|
305
|
-
_("begin; foo; rescue; bar; end")
|
306
|
-
.must_be_parsed_as s(:rescue,
|
307
|
-
s(:call, nil, :foo),
|
308
|
-
s(:resbody,
|
309
|
-
s(:array),
|
310
|
-
s(:call, nil, :bar)))
|
311
|
-
end
|
312
|
-
|
313
|
-
it "works with multi-statement main and rescue bodies" do
|
314
|
-
_("begin; foo; bar; rescue; baz; qux; end")
|
315
|
-
.must_be_parsed_as s(:rescue,
|
316
|
-
s(:block,
|
317
|
-
s(:call, nil, :foo),
|
318
|
-
s(:call, nil, :bar)),
|
319
|
-
s(:resbody,
|
320
|
-
s(:array),
|
321
|
-
s(:call, nil, :baz),
|
322
|
-
s(:call, nil, :qux)))
|
323
|
-
end
|
324
|
-
|
325
|
-
it "works with assignment to an error variable" do
|
326
|
-
_("begin; foo; rescue => e; bar; end")
|
327
|
-
.must_be_parsed_as s(:rescue,
|
328
|
-
s(:call, nil, :foo),
|
329
|
-
s(:resbody,
|
330
|
-
s(:array, s(:lasgn, :e, s(:gvar, :$!))),
|
331
|
-
s(:call, nil, :bar)))
|
332
|
-
end
|
333
|
-
|
334
|
-
it "works with filtering of the exception type" do
|
335
|
-
_("begin; foo; rescue Bar; baz; end")
|
336
|
-
.must_be_parsed_as s(:rescue,
|
337
|
-
s(:call, nil, :foo),
|
338
|
-
s(:resbody,
|
339
|
-
s(:array, s(:const, :Bar)),
|
340
|
-
s(:call, nil, :baz)))
|
341
|
-
end
|
342
|
-
|
343
|
-
it "works with filtering of the exception type and assignment to an error variable" do
|
344
|
-
_("begin; foo; rescue Bar => e; baz; end")
|
345
|
-
.must_be_parsed_as s(:rescue,
|
346
|
-
s(:call, nil, :foo),
|
347
|
-
s(:resbody,
|
348
|
-
s(:array,
|
349
|
-
s(:const, :Bar),
|
350
|
-
s(:lasgn, :e, s(:gvar, :$!))),
|
351
|
-
s(:call, nil, :baz)))
|
352
|
-
end
|
353
|
-
|
354
|
-
it "works rescuing multiple exception types" do
|
355
|
-
_("begin; foo; rescue Bar, Baz; qux; end")
|
356
|
-
.must_be_parsed_as s(:rescue,
|
357
|
-
s(:call, nil, :foo),
|
358
|
-
s(:resbody,
|
359
|
-
s(:array, s(:const, :Bar), s(:const, :Baz)),
|
360
|
-
s(:call, nil, :qux)))
|
361
|
-
end
|
362
|
-
|
363
|
-
it "works rescuing a splatted list of exception types" do
|
364
|
-
_("begin; foo; rescue *bar; baz; end")
|
365
|
-
.must_be_parsed_as s(:rescue,
|
366
|
-
s(:call, nil, :foo),
|
367
|
-
s(:resbody,
|
368
|
-
s(:splat, s(:call, nil, :bar)),
|
369
|
-
s(:call, nil, :baz)))
|
370
|
-
end
|
371
|
-
|
372
|
-
it "works rescuing a complex list of exception types" do
|
373
|
-
_("begin; foo; rescue *bar, Baz; qux; end")
|
374
|
-
.must_be_parsed_as s(:rescue,
|
375
|
-
s(:call, nil, :foo),
|
376
|
-
s(:resbody,
|
377
|
-
s(:array,
|
378
|
-
s(:splat, s(:call, nil, :bar)),
|
379
|
-
s(:const, :Baz)),
|
380
|
-
s(:call, nil, :qux)))
|
381
|
-
end
|
382
|
-
|
383
|
-
it "works with a nested begin..end block" do
|
384
|
-
_("begin; foo; rescue; begin; bar; end; end")
|
385
|
-
.must_be_parsed_as s(:rescue,
|
386
|
-
s(:call, nil, :foo),
|
387
|
-
s(:resbody, s(:array),
|
388
|
-
s(:call, nil, :bar)))
|
389
|
-
end
|
390
|
-
|
391
|
-
it "works in a plain method body" do
|
392
|
-
_("def foo; bar; rescue; baz; end")
|
393
|
-
.must_be_parsed_as s(:defn,
|
394
|
-
:foo,
|
395
|
-
s(:args),
|
396
|
-
s(:rescue,
|
397
|
-
s(:call, nil, :bar),
|
398
|
-
s(:resbody,
|
399
|
-
s(:array),
|
400
|
-
s(:call, nil, :baz))))
|
401
|
-
end
|
402
|
-
|
403
|
-
it "works in a method body inside begin..end with rescue" do
|
404
|
-
_("def foo; bar; begin; baz; rescue; qux; end; quuz; end")
|
405
|
-
.must_be_parsed_as s(:defn,
|
406
|
-
:foo,
|
407
|
-
s(:args),
|
408
|
-
s(:call, nil, :bar),
|
409
|
-
s(:rescue,
|
410
|
-
s(:call, nil, :baz),
|
411
|
-
s(:resbody, s(:array), s(:call, nil, :qux))),
|
412
|
-
s(:call, nil, :quuz))
|
413
|
-
end
|
414
|
-
|
415
|
-
it "works in a method body inside begin..end without rescue" do
|
416
|
-
_("def foo; bar; begin; baz; qux; end; quuz; end")
|
417
|
-
.must_be_parsed_as s(:defn,
|
418
|
-
:foo,
|
419
|
-
s(:args),
|
420
|
-
s(:call, nil, :bar),
|
421
|
-
s(:block,
|
422
|
-
s(:call, nil, :baz),
|
423
|
-
s(:call, nil, :qux)),
|
424
|
-
s(:call, nil, :quuz))
|
425
|
-
end
|
426
|
-
|
427
|
-
it "works in a method body fully inside begin..end" do
|
428
|
-
_("def foo; begin; bar; baz; end; end")
|
429
|
-
.must_be_parsed_as s(:defn,
|
430
|
-
:foo,
|
431
|
-
s(:args),
|
432
|
-
s(:call, nil, :bar),
|
433
|
-
s(:call, nil, :baz))
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
describe "for the postfix rescue modifier" do
|
438
|
-
it "works in the basic case" do
|
439
|
-
_("foo rescue bar")
|
440
|
-
.must_be_parsed_as s(:rescue,
|
441
|
-
s(:call, nil, :foo),
|
442
|
-
s(:resbody,
|
443
|
-
s(:array),
|
444
|
-
s(:call, nil, :bar)))
|
445
|
-
end
|
446
|
-
|
447
|
-
it "works when the fallback value is a keyword" do
|
448
|
-
_("foo rescue next")
|
449
|
-
.must_be_parsed_as s(:rescue,
|
450
|
-
s(:call, nil, :foo),
|
451
|
-
s(:resbody,
|
452
|
-
s(:array),
|
453
|
-
s(:next)))
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
describe "for the ensure statement" do
|
458
|
-
it "works with single statement main and ensure bodies" do
|
459
|
-
_("begin; foo; ensure; bar; end")
|
460
|
-
.must_be_parsed_as s(:ensure,
|
461
|
-
s(:call, nil, :foo),
|
462
|
-
s(:call, nil, :bar))
|
463
|
-
end
|
464
|
-
|
465
|
-
it "works with multi-statement main and ensure bodies" do
|
466
|
-
_("begin; foo; bar; ensure; baz; qux; end")
|
467
|
-
.must_be_parsed_as s(:ensure,
|
468
|
-
s(:block,
|
469
|
-
s(:call, nil, :foo),
|
470
|
-
s(:call, nil, :bar)),
|
471
|
-
s(:block,
|
472
|
-
s(:call, nil, :baz),
|
473
|
-
s(:call, nil, :qux)))
|
474
|
-
end
|
475
|
-
|
476
|
-
it "works together with rescue" do
|
477
|
-
_("begin; foo; rescue; bar; ensure; baz; end")
|
478
|
-
.must_be_parsed_as s(:ensure,
|
479
|
-
s(:rescue,
|
480
|
-
s(:call, nil, :foo),
|
481
|
-
s(:resbody,
|
482
|
-
s(:array),
|
483
|
-
s(:call, nil, :bar))),
|
484
|
-
s(:call, nil, :baz))
|
485
|
-
end
|
486
|
-
|
487
|
-
it "works with empty main and ensure bodies" do
|
488
|
-
_("begin; ensure; end")
|
489
|
-
.must_be_parsed_as s(:ensure, s(:nil))
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
describe "for the next statement" do
|
494
|
-
it "works with no arguments" do
|
495
|
-
_("foo do; next; end")
|
496
|
-
.must_be_parsed_as s(:iter,
|
497
|
-
s(:call, nil, :foo),
|
498
|
-
0,
|
499
|
-
s(:next))
|
500
|
-
end
|
501
|
-
|
502
|
-
it "works with one argument" do
|
503
|
-
_("foo do; next bar; end")
|
504
|
-
.must_be_parsed_as s(:iter,
|
505
|
-
s(:call, nil, :foo),
|
506
|
-
0,
|
507
|
-
s(:next, s(:call, nil, :bar)))
|
508
|
-
end
|
509
|
-
|
510
|
-
it "works with a splat argument" do
|
511
|
-
_("foo do; next *bar; end")
|
512
|
-
.must_be_parsed_as s(:iter,
|
513
|
-
s(:call, nil, :foo),
|
514
|
-
0,
|
515
|
-
s(:next,
|
516
|
-
s(:svalue,
|
517
|
-
s(:splat,
|
518
|
-
s(:call, nil, :bar)))))
|
519
|
-
end
|
520
|
-
|
521
|
-
it "works with several arguments" do
|
522
|
-
_("foo do; next bar, baz; end")
|
523
|
-
.must_be_parsed_as s(:iter,
|
524
|
-
s(:call, nil, :foo),
|
525
|
-
0,
|
526
|
-
s(:next,
|
527
|
-
s(:array,
|
528
|
-
s(:call, nil, :bar),
|
529
|
-
s(:call, nil, :baz))))
|
530
|
-
end
|
531
|
-
|
532
|
-
it "works with a function call with parentheses" do
|
533
|
-
_("foo do; next foo(bar); end")
|
534
|
-
.must_be_parsed_as s(:iter,
|
535
|
-
s(:call, nil, :foo),
|
536
|
-
0,
|
537
|
-
s(:next,
|
538
|
-
s(:call, nil, :foo,
|
539
|
-
s(:call, nil, :bar))))
|
540
|
-
end
|
541
|
-
|
542
|
-
it "works with a function call without parentheses" do
|
543
|
-
_("foo do; next foo bar; end")
|
544
|
-
.must_be_parsed_as s(:iter,
|
545
|
-
s(:call, nil, :foo),
|
546
|
-
0,
|
547
|
-
s(:next,
|
548
|
-
s(:call, nil, :foo,
|
549
|
-
s(:call, nil, :bar))))
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
describe "for the break statement" do
|
554
|
-
it "works with break with no arguments" do
|
555
|
-
_("foo do; break; end")
|
556
|
-
.must_be_parsed_as s(:iter,
|
557
|
-
s(:call, nil, :foo),
|
558
|
-
0,
|
559
|
-
s(:break))
|
560
|
-
end
|
561
|
-
|
562
|
-
it "works with break with one argument" do
|
563
|
-
_("foo do; break bar; end")
|
564
|
-
.must_be_parsed_as s(:iter,
|
565
|
-
s(:call, nil, :foo),
|
566
|
-
0,
|
567
|
-
s(:break, s(:call, nil, :bar)))
|
568
|
-
end
|
569
|
-
|
570
|
-
it "works with a splat argument" do
|
571
|
-
_("foo do; break *bar; end")
|
572
|
-
.must_be_parsed_as s(:iter,
|
573
|
-
s(:call, nil, :foo),
|
574
|
-
0,
|
575
|
-
s(:break,
|
576
|
-
s(:svalue,
|
577
|
-
s(:splat,
|
578
|
-
s(:call, nil, :bar)))))
|
579
|
-
end
|
580
|
-
|
581
|
-
it "works with break with several arguments" do
|
582
|
-
_("foo do; break bar, baz; end")
|
583
|
-
.must_be_parsed_as s(:iter,
|
584
|
-
s(:call, nil, :foo),
|
585
|
-
0,
|
586
|
-
s(:break,
|
587
|
-
s(:array,
|
588
|
-
s(:call, nil, :bar),
|
589
|
-
s(:call, nil, :baz))))
|
590
|
-
end
|
591
|
-
|
592
|
-
it "works with break with a function call with parentheses" do
|
593
|
-
_("foo do; break foo(bar); end")
|
594
|
-
.must_be_parsed_as s(:iter,
|
595
|
-
s(:call, nil, :foo),
|
596
|
-
0,
|
597
|
-
s(:break,
|
598
|
-
s(:call, nil, :foo,
|
599
|
-
s(:call, nil, :bar))))
|
600
|
-
end
|
601
|
-
|
602
|
-
it "works with break with a function call without parentheses" do
|
603
|
-
_("foo do; break foo bar; end")
|
604
|
-
.must_be_parsed_as s(:iter,
|
605
|
-
s(:call, nil, :foo),
|
606
|
-
0,
|
607
|
-
s(:break,
|
608
|
-
s(:call, nil, :foo,
|
609
|
-
s(:call, nil, :bar))))
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
|
-
describe "for lists of consecutive statments" do
|
614
|
-
it "removes extra blocks for grouped statements at the start of the list" do
|
615
|
-
_("(foo; bar); baz")
|
616
|
-
.must_be_parsed_as s(:block,
|
617
|
-
s(:call, nil, :foo),
|
618
|
-
s(:call, nil, :bar),
|
619
|
-
s(:call, nil, :baz))
|
620
|
-
end
|
621
|
-
|
622
|
-
it "keeps extra blocks for grouped statements at the end of the list" do
|
623
|
-
_("foo; (bar; baz)")
|
624
|
-
.must_be_parsed_as s(:block,
|
625
|
-
s(:call, nil, :foo),
|
626
|
-
s(:block,
|
627
|
-
s(:call, nil, :bar),
|
628
|
-
s(:call, nil, :baz)))
|
629
|
-
end
|
630
|
-
end
|
631
|
-
|
632
|
-
describe "for stabby lambda" do
|
633
|
-
it "works in the simple case" do
|
634
|
-
_("->(foo) { bar }")
|
635
|
-
.must_be_parsed_as s(:iter,
|
636
|
-
s(:lambda),
|
637
|
-
s(:args, :foo),
|
638
|
-
s(:call, nil, :bar))
|
639
|
-
end
|
640
|
-
|
641
|
-
it "works in the simple case without parentheses" do
|
642
|
-
_("-> foo { bar }")
|
643
|
-
.must_be_parsed_as s(:iter,
|
644
|
-
s(:lambda),
|
645
|
-
s(:args, :foo),
|
646
|
-
s(:call, nil, :bar))
|
647
|
-
end
|
648
|
-
|
649
|
-
it "works when there are zero arguments" do
|
650
|
-
_("->() { bar }")
|
651
|
-
.must_be_parsed_as s(:iter,
|
652
|
-
s(:lambda),
|
653
|
-
s(:args),
|
654
|
-
s(:call, nil, :bar))
|
655
|
-
end
|
656
|
-
|
657
|
-
it "works when there are no arguments" do
|
658
|
-
_("-> { bar }")
|
659
|
-
.must_be_parsed_as s(:iter,
|
660
|
-
s(:lambda),
|
661
|
-
0,
|
662
|
-
s(:call, nil, :bar))
|
663
|
-
end
|
664
|
-
|
665
|
-
it "works when there are no statements in the body" do
|
666
|
-
_("->(foo) { }")
|
667
|
-
.must_be_parsed_as s(:iter,
|
668
|
-
s(:lambda),
|
669
|
-
s(:args, :foo))
|
670
|
-
end
|
671
|
-
|
672
|
-
it "works when there are several statements in the body" do
|
673
|
-
_("->(foo) { bar; baz }")
|
674
|
-
.must_be_parsed_as s(:iter,
|
675
|
-
s(:lambda),
|
676
|
-
s(:args, :foo),
|
677
|
-
s(:block,
|
678
|
-
s(:call, nil, :bar),
|
679
|
-
s(:call, nil, :baz)))
|
680
|
-
end
|
681
|
-
|
682
|
-
it "sets line numbers correctly for lambdas with empty bodies" do
|
683
|
-
_("->(foo) { }\nbar")
|
684
|
-
.must_be_parsed_as s(:block,
|
685
|
-
s(:iter, s(:lambda).line(1), s(:args, :foo).line(1)).line(1),
|
686
|
-
s(:call, nil, :bar).line(2)).line(1),
|
687
|
-
with_line_numbers: true
|
688
|
-
end
|
689
|
-
|
690
|
-
it "sets line numbers correctly for empty lambdas" do
|
691
|
-
_("->() { }\nfoo")
|
692
|
-
.must_be_parsed_as s(:block,
|
693
|
-
s(:iter, s(:lambda).line(1), s(:args).line(1)).line(1),
|
694
|
-
s(:call, nil, :foo).line(2)).line(1),
|
695
|
-
with_line_numbers: true
|
696
|
-
end
|
697
|
-
end
|
698
|
-
|
699
|
-
describe "for lambda keyword" do
|
700
|
-
it "works in the simple case" do
|
701
|
-
_("lambda { |foo| bar }")
|
702
|
-
.must_be_parsed_as s(:iter,
|
703
|
-
s(:call, nil, :lambda),
|
704
|
-
s(:args, :foo),
|
705
|
-
s(:call, nil, :bar))
|
706
|
-
end
|
707
|
-
|
708
|
-
it "works with trailing argument comma" do
|
709
|
-
_("lambda { |foo,| bar }")
|
710
|
-
.must_be_parsed_as s(:iter,
|
711
|
-
s(:call, nil, :lambda),
|
712
|
-
s(:args, :foo, nil),
|
713
|
-
s(:call, nil, :bar))
|
714
|
-
end
|
715
|
-
end
|
716
|
-
end
|
717
|
-
end
|