ripper_ruby_parser 1.7.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +76 -0
  3. data/README.md +6 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers.rb +2 -0
  6. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +9 -4
  7. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +40 -52
  8. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  9. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +35 -2
  10. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +15 -242
  11. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  12. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +22 -17
  13. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  14. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +256 -0
  15. data/lib/ripper_ruby_parser/sexp_processor.rb +12 -56
  16. data/lib/ripper_ruby_parser/unescape.rb +89 -43
  17. data/lib/ripper_ruby_parser/version.rb +1 -1
  18. metadata +125 -76
  19. data/Rakefile +0 -33
  20. data/test/end_to_end/comments_test.rb +0 -59
  21. data/test/end_to_end/comparison_test.rb +0 -104
  22. data/test/end_to_end/lib_comparison_test.rb +0 -29
  23. data/test/end_to_end/line_numbering_test.rb +0 -31
  24. data/test/end_to_end/samples_comparison_test.rb +0 -13
  25. data/test/end_to_end/test_comparison_test.rb +0 -32
  26. data/test/pt_testcase/pt_test.rb +0 -44
  27. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  28. data/test/ripper_ruby_parser/parser_test.rb +0 -553
  29. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -613
  30. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -679
  31. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  32. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -1106
  33. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  34. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -267
  35. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -421
  36. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -399
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -303
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -17
  40. data/test/samples/comments.rb +0 -13
  41. data/test/samples/conditionals.rb +0 -23
  42. data/test/samples/lambdas.rb +0 -5
  43. data/test/samples/loops.rb +0 -36
  44. data/test/samples/misc.rb +0 -281
  45. data/test/samples/number.rb +0 -7
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -107
@@ -1,679 +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 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
- end
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)))
188
- end
189
- end
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)
194
- end
195
-
196
- it "works for a simple begin..end block" do
197
- _("begin; foo; end").must_be_parsed_as s(:call, nil, :foo)
198
- end
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))
205
- end
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)
213
- end
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)))
221
- end
222
- end
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))
252
- end
253
- end
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))
412
- end
413
- end
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)))
423
- end
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)))
432
- end
433
- end
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))
441
- end
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)))
452
- end
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))
463
- end
464
-
465
- it "works with empty main and ensure bodies" do
466
- _("begin; ensure; end")
467
- .must_be_parsed_as s(:ensure, s(:nil))
468
- end
469
- end
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))))
528
- end
529
- end
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))))
588
- end
589
- end
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))
598
- end
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)))
607
- end
608
- end
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(: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))
676
- end
677
- end
678
- end
679
- end