ripper_ruby_parser 1.7.2 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +4 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
  6. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
  7. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  8. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
  10. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  11. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
  12. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
  14. data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
  15. data/lib/ripper_ruby_parser/unescape.rb +63 -22
  16. data/lib/ripper_ruby_parser/version.rb +1 -1
  17. metadata +140 -79
  18. data/Rakefile +0 -33
  19. data/test/end_to_end/comments_test.rb +0 -59
  20. data/test/end_to_end/comparison_test.rb +0 -104
  21. data/test/end_to_end/lib_comparison_test.rb +0 -18
  22. data/test/end_to_end/line_numbering_test.rb +0 -31
  23. data/test/end_to_end/samples_comparison_test.rb +0 -13
  24. data/test/end_to_end/test_comparison_test.rb +0 -18
  25. data/test/pt_testcase/pt_test.rb +0 -44
  26. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  27. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  28. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  29. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  30. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  31. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  32. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  33. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  34. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  35. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  36. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -22
  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 -285
  45. data/test/samples/number.rb +0 -9
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -111
@@ -1,536 +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 regular if" do
8
- it "works with a single statement" do
9
- _("if foo; bar; end")
10
- .must_be_parsed_as s(:if,
11
- s(:call, nil, :foo),
12
- s(:call, nil, :bar),
13
- nil)
14
- end
15
-
16
- it "works with multiple statements" do
17
- _("if foo; bar; baz; end")
18
- .must_be_parsed_as s(:if,
19
- s(:call, nil, :foo),
20
- s(:block,
21
- s(:call, nil, :bar),
22
- s(:call, nil, :baz)),
23
- nil)
24
- end
25
-
26
- it "works with zero statements" do
27
- _("if foo; end")
28
- .must_be_parsed_as s(:if,
29
- s(:call, nil, :foo),
30
- nil,
31
- nil)
32
- end
33
-
34
- it "works with a begin..end block" do
35
- _("if foo; begin; bar; end; end")
36
- .must_be_parsed_as s(:if,
37
- s(:call, nil, :foo),
38
- s(:call, nil, :bar),
39
- nil)
40
- end
41
-
42
- it "works with an else clause" do
43
- _("if foo; bar; else; baz; end")
44
- .must_be_parsed_as s(:if,
45
- s(:call, nil, :foo),
46
- s(:call, nil, :bar),
47
- s(:call, nil, :baz))
48
- end
49
-
50
- it "works with an empty main clause" do
51
- _("if foo; else; bar; end")
52
- .must_be_parsed_as s(:if,
53
- s(:call, nil, :foo),
54
- nil,
55
- s(:call, nil, :bar))
56
- end
57
-
58
- it "works with an empty else clause" do
59
- _("if foo; bar; else; end")
60
- .must_be_parsed_as s(:if,
61
- s(:call, nil, :foo),
62
- s(:call, nil, :bar),
63
- nil)
64
- end
65
-
66
- it "handles a negative condition correctly" do
67
- _("if not foo; bar; end")
68
- .must_be_parsed_as s(:if,
69
- s(:call, s(:call, nil, :foo), :!),
70
- s(:call, nil, :bar),
71
- nil)
72
- end
73
-
74
- it "handles bare integer literal in condition" do
75
- _("if 1; bar; end")
76
- .must_be_parsed_as s(:if,
77
- s(:lit, 1),
78
- s(:call, nil, :bar),
79
- nil)
80
- end
81
-
82
- it "handles bare regex literal in condition" do
83
- _("if /foo/; bar; end")
84
- .must_be_parsed_as s(:if,
85
- s(:match, s(:lit, /foo/)),
86
- s(:call, nil, :bar),
87
- nil)
88
- end
89
-
90
- it "handles interpolated regex in condition" do
91
- _('if /#{foo}/; bar; end')
92
- .must_be_parsed_as s(:if,
93
- s(:dregx, "", s(:evstr, s(:call, nil, :foo))),
94
- s(:call, nil, :bar),
95
- nil)
96
- end
97
-
98
- it "handles block conditions" do
99
- _("if (foo; bar); baz; end")
100
- .must_be_parsed_as s(:if,
101
- s(:block, s(:call, nil, :foo), s(:call, nil, :bar)),
102
- s(:call, nil, :baz),
103
- nil)
104
- end
105
-
106
- it "converts :dot2 to :flip2" do
107
- _("if foo..bar; baz; end")
108
- .must_be_parsed_as s(:if,
109
- s(:flip2, s(:call, nil, :foo), s(:call, nil, :bar)),
110
- s(:call, nil, :baz),
111
- nil)
112
- end
113
-
114
- it "converts :dot3 to :flip3" do
115
- _("if foo...bar; baz; end")
116
- .must_be_parsed_as s(:if,
117
- s(:flip3, s(:call, nil, :foo), s(:call, nil, :bar)),
118
- s(:call, nil, :baz),
119
- nil)
120
- end
121
-
122
- it "handles negative match operator" do
123
- _("if foo !~ bar; baz; else; qux; end")
124
- .must_be_parsed_as s(:if,
125
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
126
- s(:call, nil, :qux),
127
- s(:call, nil, :baz))
128
- end
129
-
130
- it "cleans up begin..end block in condition" do
131
- _("if begin foo end; bar; end")
132
- .must_be_parsed_as s(:if,
133
- s(:call, nil, :foo),
134
- s(:call, nil, :bar), nil)
135
- end
136
-
137
- it "handles special conditions inside begin..end block" do
138
- _("if begin foo..bar end; baz; end")
139
- .must_be_parsed_as s(:if,
140
- s(:flip2, s(:call, nil, :foo), s(:call, nil, :bar)),
141
- s(:call, nil, :baz),
142
- nil)
143
- end
144
-
145
- it "works with assignment in the condition" do
146
- _("if foo = bar; baz; end")
147
- .must_be_parsed_as s(:if,
148
- s(:lasgn, :foo,
149
- s(:call, nil, :bar)),
150
- s(:call, nil, :baz), nil)
151
- end
152
-
153
- it "works with bracketed assignment in the condition" do
154
- _("if (foo = bar); baz; end")
155
- .must_be_parsed_as s(:if,
156
- s(:lasgn, :foo,
157
- s(:call, nil, :bar)),
158
- s(:call, nil, :baz), nil)
159
- end
160
- end
161
-
162
- describe "for postfix if" do
163
- it "works with a simple condition" do
164
- _("foo if bar")
165
- .must_be_parsed_as s(:if,
166
- s(:call, nil, :bar),
167
- s(:call, nil, :foo),
168
- nil)
169
- end
170
-
171
- it "handles negative conditions" do
172
- _("foo if not bar")
173
- .must_be_parsed_as s(:if,
174
- s(:call, s(:call, nil, :bar), :!),
175
- s(:call, nil, :foo),
176
- nil)
177
- end
178
-
179
- it "handles bare regex literal in condition" do
180
- _("foo if /bar/")
181
- .must_be_parsed_as s(:if,
182
- s(:match, s(:lit, /bar/)),
183
- s(:call, nil, :foo),
184
- nil)
185
- end
186
-
187
- it "handles interpolated regex in condition" do
188
- _('foo if /#{bar}/')
189
- .must_be_parsed_as s(:if,
190
- s(:dregx, "", s(:evstr, s(:call, nil, :bar))),
191
- s(:call, nil, :foo),
192
- nil)
193
- end
194
-
195
- it "handles negative match operator" do
196
- _("baz if foo !~ bar")
197
- .must_be_parsed_as s(:if,
198
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
199
- nil,
200
- s(:call, nil, :baz))
201
- end
202
-
203
- it "cleans up begin..end block in condition" do
204
- _("foo if begin bar end")
205
- .must_be_parsed_as s(:if,
206
- s(:call, nil, :bar),
207
- s(:call, nil, :foo), nil)
208
- end
209
- end
210
-
211
- describe "for regular unless" do
212
- it "works with a single statement" do
213
- _("unless bar; foo; end")
214
- .must_be_parsed_as s(:if,
215
- s(:call, nil, :bar),
216
- nil,
217
- s(:call, nil, :foo))
218
- end
219
-
220
- it "works with multiple statements" do
221
- _("unless foo; bar; baz; end")
222
- .must_be_parsed_as s(:if,
223
- s(:call, nil, :foo),
224
- nil,
225
- s(:block,
226
- s(:call, nil, :bar),
227
- s(:call, nil, :baz)))
228
- end
229
-
230
- it "works with zero statements" do
231
- _("unless foo; end")
232
- .must_be_parsed_as s(:if,
233
- s(:call, nil, :foo),
234
- nil,
235
- nil)
236
- end
237
-
238
- it "works with an else clause" do
239
- _("unless foo; bar; else; baz; end")
240
- .must_be_parsed_as s(:if,
241
- s(:call, nil, :foo),
242
- s(:call, nil, :baz),
243
- s(:call, nil, :bar))
244
- end
245
-
246
- it "works with an empty main clause" do
247
- _("unless foo; else; bar; end")
248
- .must_be_parsed_as s(:if,
249
- s(:call, nil, :foo),
250
- s(:call, nil, :bar),
251
- nil)
252
- end
253
-
254
- it "works with an empty else block" do
255
- _("unless foo; bar; else; end")
256
- .must_be_parsed_as s(:if,
257
- s(:call, nil, :foo),
258
- nil,
259
- s(:call, nil, :bar))
260
- end
261
-
262
- it "handles bare regex literal in condition" do
263
- _("unless /foo/; bar; end")
264
- .must_be_parsed_as s(:if,
265
- s(:match, s(:lit, /foo/)),
266
- nil,
267
- s(:call, nil, :bar))
268
- end
269
-
270
- it "handles interpolated regex in condition" do
271
- _('unless /#{foo}/; bar; end')
272
- .must_be_parsed_as s(:if,
273
- s(:dregx, "", s(:evstr, s(:call, nil, :foo))),
274
- nil,
275
- s(:call, nil, :bar))
276
- end
277
-
278
- it "handles negative match operator" do
279
- _("unless foo !~ bar; baz; else; qux; end")
280
- .must_be_parsed_as s(:if,
281
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
282
- s(:call, nil, :baz),
283
- s(:call, nil, :qux))
284
- end
285
- end
286
-
287
- describe "for postfix unless" do
288
- it "works with a simple condition" do
289
- _("foo unless bar")
290
- .must_be_parsed_as s(:if,
291
- s(:call, nil, :bar),
292
- nil,
293
- s(:call, nil, :foo))
294
- end
295
-
296
- it "handles bare regex literal in condition" do
297
- _("foo unless /bar/")
298
- .must_be_parsed_as s(:if,
299
- s(:match, s(:lit, /bar/)),
300
- nil,
301
- s(:call, nil, :foo))
302
- end
303
-
304
- it "handles interpolated regex in condition" do
305
- _('foo unless /#{bar}/')
306
- .must_be_parsed_as s(:if,
307
- s(:dregx, "", s(:evstr, s(:call, nil, :bar))),
308
- nil,
309
- s(:call, nil, :foo))
310
- end
311
-
312
- it "handles negative match operator" do
313
- _("baz unless foo !~ bar")
314
- .must_be_parsed_as s(:if,
315
- s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
316
- s(:call, nil, :baz),
317
- nil)
318
- end
319
- end
320
-
321
- describe "for elsif" do
322
- it "works with a single statement" do
323
- _("if foo; bar; elsif baz; qux; end")
324
- .must_be_parsed_as s(:if,
325
- s(:call, nil, :foo),
326
- s(:call, nil, :bar),
327
- s(:if,
328
- s(:call, nil, :baz),
329
- s(:call, nil, :qux),
330
- nil))
331
- end
332
-
333
- it "works with an empty consequesnt" do
334
- _("if foo; bar; elsif baz; end")
335
- .must_be_parsed_as s(:if,
336
- s(:call, nil, :foo),
337
- s(:call, nil, :bar),
338
- s(:if,
339
- s(:call, nil, :baz),
340
- nil,
341
- nil))
342
- end
343
-
344
- it "works with an else" do
345
- _("if foo; bar; elsif baz; qux; else; quuz; end")
346
- .must_be_parsed_as s(:if,
347
- s(:call, nil, :foo),
348
- s(:call, nil, :bar),
349
- s(:if,
350
- s(:call, nil, :baz),
351
- s(:call, nil, :qux),
352
- s(:call, nil, :quuz)))
353
- end
354
-
355
- it "works with an empty else" do
356
- _("if foo; bar; elsif baz; qux; else; end")
357
- .must_be_parsed_as s(:if,
358
- s(:call, nil, :foo),
359
- s(:call, nil, :bar),
360
- s(:if,
361
- s(:call, nil, :baz),
362
- s(:call, nil, :qux),
363
- nil))
364
- end
365
-
366
- it "handles a negative condition correctly" do
367
- _("if foo; bar; elsif not baz; qux; end")
368
- .must_be_parsed_as s(:if,
369
- s(:call, nil, :foo),
370
- s(:call, nil, :bar),
371
- s(:if,
372
- s(:call, s(:call, nil, :baz), :!),
373
- s(:call, nil, :qux), nil))
374
- end
375
-
376
- it "does not replace :dot2 with :flip2" do
377
- _("if foo; bar; elsif baz..qux; quuz; end")
378
- .must_be_parsed_as s(:if,
379
- s(:call, nil, :foo),
380
- s(:call, nil, :bar),
381
- s(:if,
382
- s(:dot2, s(:call, nil, :baz), s(:call, nil, :qux)),
383
- s(:call, nil, :quuz), nil))
384
- end
385
-
386
- it "does not rewrite the negative match operator" do
387
- _("if foo; bar; elsif baz !~ qux; quuz; end")
388
- .must_be_parsed_as s(:if,
389
- s(:call, nil, :foo),
390
- s(:call, nil, :bar),
391
- s(:if,
392
- s(:not,
393
- s(:call,
394
- s(:call, nil, :baz),
395
- :=~,
396
- s(:call, nil, :qux))),
397
- s(:call, nil, :quuz),
398
- nil))
399
- end
400
-
401
- it "cleans up begin..end block in condition" do
402
- _("if foo; bar; elsif begin baz end; qux; end")
403
- .must_be_parsed_as s(:if,
404
- s(:call, nil, :foo),
405
- s(:call, nil, :bar),
406
- s(:if,
407
- s(:call, nil, :baz),
408
- s(:call, nil, :qux),
409
- nil))
410
- end
411
- end
412
-
413
- describe "for case block" do
414
- it "works with a single when clause" do
415
- _("case foo; when bar; baz; end")
416
- .must_be_parsed_as s(:case,
417
- s(:call, nil, :foo),
418
- s(:when,
419
- s(:array, s(:call, nil, :bar)),
420
- s(:call, nil, :baz)),
421
- nil)
422
- end
423
-
424
- it "works with multiple when clauses" do
425
- _("case foo; when bar; baz; when qux; quux; end")
426
- .must_be_parsed_as s(:case,
427
- s(:call, nil, :foo),
428
- s(:when,
429
- s(:array, s(:call, nil, :bar)),
430
- s(:call, nil, :baz)),
431
- s(:when,
432
- s(:array, s(:call, nil, :qux)),
433
- s(:call, nil, :quux)),
434
- nil)
435
- end
436
-
437
- it "works with multiple statements in the when block" do
438
- _("case foo; when bar; baz; qux; end")
439
- .must_be_parsed_as s(:case,
440
- s(:call, nil, :foo),
441
- s(:when,
442
- s(:array, s(:call, nil, :bar)),
443
- s(:call, nil, :baz),
444
- s(:call, nil, :qux)),
445
- nil)
446
- end
447
-
448
- it "works with an else clause" do
449
- _("case foo; when bar; baz; else; qux; end")
450
- .must_be_parsed_as s(:case,
451
- s(:call, nil, :foo),
452
- s(:when,
453
- s(:array, s(:call, nil, :bar)),
454
- s(:call, nil, :baz)),
455
- s(:call, nil, :qux))
456
- end
457
-
458
- it "works with multiple statements in the else block" do
459
- _("case foo; when bar; baz; else; qux; quuz end")
460
- .must_be_parsed_as s(:case,
461
- s(:call, nil, :foo),
462
- s(:when,
463
- s(:array,
464
- s(:call, nil, :bar)),
465
- s(:call, nil, :baz)),
466
- s(:block,
467
- s(:call, nil, :qux),
468
- s(:call, nil, :quuz)))
469
- end
470
-
471
- it "works with an empty when block" do
472
- _("case foo; when bar; end")
473
- .must_be_parsed_as s(:case,
474
- s(:call, nil, :foo),
475
- s(:when, s(:array, s(:call, nil, :bar)), nil),
476
- nil)
477
- end
478
-
479
- it "works with an empty else block" do
480
- _("case foo; when bar; baz; else; end")
481
- .must_be_parsed_as s(:case,
482
- s(:call, nil, :foo),
483
- s(:when,
484
- s(:array, s(:call, nil, :bar)),
485
- s(:call, nil, :baz)),
486
- nil)
487
- end
488
-
489
- it "works with a splat in the when clause" do
490
- _("case foo; when *bar; baz; end")
491
- .must_be_parsed_as s(:case,
492
- s(:call, nil, :foo),
493
- s(:when,
494
- s(:array,
495
- s(:splat, s(:call, nil, :bar))),
496
- s(:call, nil, :baz)),
497
- nil)
498
- end
499
-
500
- it "cleans up a multi-statement begin..end in the when clause" do
501
- _("case foo; when bar; begin; baz; qux; end; end")
502
- .must_be_parsed_as s(:case,
503
- s(:call, nil, :foo),
504
- s(:when,
505
- s(:array, s(:call, nil, :bar)),
506
- s(:call, nil, :baz),
507
- s(:call, nil, :qux)),
508
- nil)
509
- end
510
-
511
- it "cleans up a multi-statement begin..end at start of the when clause" do
512
- _("case foo; when bar; begin; baz; qux; end; quuz; end")
513
- .must_be_parsed_as s(:case,
514
- s(:call, nil, :foo),
515
- s(:when,
516
- s(:array, s(:call, nil, :bar)),
517
- s(:call, nil, :baz),
518
- s(:call, nil, :qux),
519
- s(:call, nil, :quuz)),
520
- nil)
521
- end
522
-
523
- it "keeps up a multi-statement begin..end in the else clause" do
524
- _("case foo; when bar; baz; else; begin; qux; quuz; end; end")
525
- .must_be_parsed_as s(:case,
526
- s(:call, nil, :foo),
527
- s(:when,
528
- s(:array, s(:call, nil, :bar)),
529
- s(:call, nil, :baz)),
530
- s(:block,
531
- s(:call, nil, :qux),
532
- s(:call, nil, :quuz)))
533
- end
534
- end
535
- end
536
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
-
5
- describe RipperRubyParser::Parser do
6
- let(:parser) { RipperRubyParser::Parser.new }
7
-
8
- describe "#parse" do
9
- describe "for character literals" do
10
- it "works for simple character literals" do
11
- _("?a")
12
- .must_be_parsed_as s(:str, "a")
13
- end
14
-
15
- it "works for escaped character literals" do
16
- _('?\\n')
17
- .must_be_parsed_as s(:str, "\n")
18
- end
19
-
20
- it "works for escaped character literals with ctrl" do
21
- _('?\\C-a')
22
- .must_be_parsed_as s(:str, "\u0001")
23
- end
24
-
25
- it "works for escaped character literals with meta" do
26
- _('?\\M-a')
27
- .must_be_parsed_as s(:str, (+"\xE1").force_encoding("ascii-8bit"))
28
- end
29
-
30
- it "works for escaped character literals with meta plus shorthand ctrl" do
31
- _('?\\M-\\ca')
32
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
33
- end
34
-
35
- it "works for escaped character literals with shorthand ctrl plus meta" do
36
- _('?\\c\\M-a')
37
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
38
- end
39
-
40
- it "works for escaped character literals with meta plus ctrl" do
41
- _('?\\M-\\C-a')
42
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
43
- end
44
-
45
- it "works for escaped character literals with ctrl plus meta" do
46
- _('?\\C-\\M-a')
47
- .must_be_parsed_as s(:str, (+"\x81").force_encoding("ascii-8bit"))
48
- end
49
- end
50
-
51
- describe "for array literals" do
52
- it "works for an empty array" do
53
- _("[]")
54
- .must_be_parsed_as s(:array)
55
- end
56
-
57
- it "works for a simple case with splat" do
58
- _("[*foo]")
59
- .must_be_parsed_as s(:array,
60
- s(:splat, s(:call, nil, :foo)))
61
- end
62
-
63
- it "works for a multi-element case with splat" do
64
- _("[foo, *bar]")
65
- .must_be_parsed_as s(:array,
66
- s(:call, nil, :foo),
67
- s(:splat, s(:call, nil, :bar)))
68
- end
69
- end
70
-
71
- describe "for hash literals" do
72
- it "works for an empty hash" do
73
- _("{}")
74
- .must_be_parsed_as s(:hash)
75
- end
76
-
77
- it "works for a hash with one pair" do
78
- _("{foo => bar}")
79
- .must_be_parsed_as s(:hash,
80
- s(:call, nil, :foo),
81
- s(:call, nil, :bar))
82
- end
83
-
84
- it "works for a hash with multiple pairs" do
85
- _("{foo => bar, baz => qux}")
86
- .must_be_parsed_as s(:hash,
87
- s(:call, nil, :foo),
88
- s(:call, nil, :bar),
89
- s(:call, nil, :baz),
90
- s(:call, nil, :qux))
91
- end
92
-
93
- it "works for a hash with label keys" do
94
- _("{foo: bar, baz: qux}")
95
- .must_be_parsed_as s(:hash,
96
- s(:lit, :foo),
97
- s(:call, nil, :bar),
98
- s(:lit, :baz),
99
- s(:call, nil, :qux))
100
- end
101
-
102
- it "works for a hash with dynamic label keys" do
103
- _("{'foo': bar}")
104
- .must_be_parsed_as s(:hash,
105
- s(:lit, :foo),
106
- s(:call, nil, :bar))
107
- end
108
-
109
- it "works for a hash with splat" do
110
- _("{foo: bar, baz: qux, **quux}")
111
- .must_be_parsed_as s(:hash,
112
- s(:lit, :foo), s(:call, nil, :bar),
113
- s(:lit, :baz), s(:call, nil, :qux),
114
- s(:kwsplat, s(:call, nil, :quux)))
115
- end
116
- end
117
-
118
- describe "for number literals" do
119
- it "works for floats" do
120
- _("3.14")
121
- .must_be_parsed_as s(:lit, 3.14)
122
- end
123
-
124
- it "works for octal integer literals" do
125
- _("0700")
126
- .must_be_parsed_as s(:lit, 448)
127
- end
128
-
129
- it "handles negative sign for integers" do
130
- _("-1")
131
- .must_be_parsed_as s(:lit, -1)
132
- end
133
-
134
- it "handles space after negative sign for integers" do
135
- _("-1 ")
136
- .must_be_parsed_as s(:lit, -1)
137
- end
138
-
139
- it "handles negative sign for floats" do
140
- _("-3.14")
141
- .must_be_parsed_as s(:lit, -3.14)
142
- end
143
-
144
- it "handles space after negative sign for floats" do
145
- _("-3.14 ")
146
- .must_be_parsed_as s(:lit, -3.14)
147
- end
148
-
149
- it "handles positive sign" do
150
- _("+1")
151
- .must_be_parsed_as s(:lit, 1)
152
- end
153
-
154
- it "works for rationals" do
155
- _("1000r")
156
- .must_be_parsed_as s(:lit, 1000r)
157
- end
158
-
159
- it "works for imaginary numbers" do
160
- _("1i")
161
- .must_be_parsed_as s(:lit, 1i)
162
- end
163
- end
164
- end
165
- end