ripper_ruby_parser 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/README.md +8 -25
  4. data/lib/ripper_ruby_parser.rb +2 -2
  5. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +54 -23
  6. data/lib/ripper_ruby_parser/parser.rb +3 -3
  7. data/lib/ripper_ruby_parser/sexp_handlers.rb +11 -9
  8. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +10 -11
  9. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +48 -63
  10. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  11. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +35 -2
  12. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +15 -242
  13. data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +4 -2
  14. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
  15. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +24 -24
  16. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +266 -0
  17. data/lib/ripper_ruby_parser/sexp_processor.rb +47 -78
  18. data/lib/ripper_ruby_parser/unescape.rb +79 -50
  19. data/lib/ripper_ruby_parser/version.rb +1 -1
  20. metadata +115 -78
  21. data/Rakefile +0 -33
  22. data/test/end_to_end/comments_test.rb +0 -59
  23. data/test/end_to_end/comparison_test.rb +0 -104
  24. data/test/end_to_end/lib_comparison_test.rb +0 -29
  25. data/test/end_to_end/line_numbering_test.rb +0 -64
  26. data/test/end_to_end/samples_comparison_test.rb +0 -13
  27. data/test/end_to_end/test_comparison_test.rb +0 -32
  28. data/test/pt_testcase/pt_test.rb +0 -44
  29. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -190
  30. data/test/ripper_ruby_parser/parser_test.rb +0 -469
  31. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -649
  32. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -661
  33. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  34. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -1117
  35. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  36. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -267
  37. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -427
  38. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -399
  39. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -303
  40. data/test/ripper_ruby_parser/version_test.rb +0 -7
  41. data/test/samples/assignment.rb +0 -17
  42. data/test/samples/comments.rb +0 -13
  43. data/test/samples/conditionals.rb +0 -23
  44. data/test/samples/loops.rb +0 -36
  45. data/test/samples/misc.rb +0 -278
  46. data/test/samples/number.rb +0 -7
  47. data/test/samples/operators.rb +0 -18
  48. data/test/samples/strings.rb +0 -140
  49. data/test/test_helper.rb +0 -79
@@ -1,427 +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 instance method definitions' do
8
- it 'treats kwargs as a local variable' do
9
- 'def foo(**bar); bar; end'.
10
- must_be_parsed_as s(:defn,
11
- :foo,
12
- s(:args, :"**bar"),
13
- s(:lvar, :bar))
14
- end
15
-
16
- it 'treats kwargs as a local variable when other arguments are present' do
17
- 'def foo(bar, **baz); baz; end'.
18
- must_be_parsed_as s(:defn,
19
- :foo,
20
- s(:args, :bar, :"**baz"),
21
- s(:lvar, :baz))
22
- end
23
-
24
- it 'treats kwargs as a local variable when an explicit block is present' do
25
- 'def foo(**bar, &baz); bar; end'.
26
- must_be_parsed_as s(:defn,
27
- :foo,
28
- s(:args, :"**bar", :"&baz"),
29
- s(:lvar, :bar))
30
- end
31
-
32
- it 'treats block kwargs as lvars' do
33
- 'def foo(**bar); baz { |**qux| bar; qux }; end'.
34
- must_be_parsed_as s(:defn, :foo,
35
- s(:args, :"**bar"),
36
- s(:iter,
37
- s(:call, nil, :baz),
38
- s(:args, :"**qux"),
39
- s(:block,
40
- s(:lvar, :bar),
41
- s(:lvar, :qux))))
42
- end
43
-
44
- it 'works with a method argument with a default value' do
45
- 'def foo bar=nil; end'.
46
- must_be_parsed_as s(:defn,
47
- :foo,
48
- s(:args, s(:lasgn, :bar, s(:nil))),
49
- s(:nil))
50
- end
51
-
52
- it 'works with several method arguments with default values' do
53
- 'def foo bar=1, baz=2; end'.
54
- must_be_parsed_as s(:defn,
55
- :foo,
56
- s(:args,
57
- s(:lasgn, :bar, s(:lit, 1)),
58
- s(:lasgn, :baz, s(:lit, 2))),
59
- s(:nil))
60
- end
61
-
62
- it 'works with parentheses around the parameter list' do
63
- 'def foo(bar); end'.
64
- must_be_parsed_as s(:defn, :foo, s(:args, :bar), s(:nil))
65
- end
66
-
67
- it 'works with a simple splat' do
68
- 'def foo *bar; end'.
69
- must_be_parsed_as s(:defn, :foo, s(:args, :"*bar"), s(:nil))
70
- end
71
-
72
- it 'works with a regular argument plus splat' do
73
- 'def foo bar, *baz; end'.
74
- must_be_parsed_as s(:defn, :foo, s(:args, :bar, :"*baz"), s(:nil))
75
- end
76
-
77
- it 'works with a nameless splat' do
78
- 'def foo *; end'.
79
- must_be_parsed_as s(:defn,
80
- :foo,
81
- s(:args, :"*"),
82
- s(:nil))
83
- end
84
-
85
- it 'works for a simple case with explicit block parameter' do
86
- 'def foo &bar; end'.
87
- must_be_parsed_as s(:defn,
88
- :foo,
89
- s(:args, :"&bar"),
90
- s(:nil))
91
- end
92
-
93
- it 'works with a regular argument plus explicit block parameter' do
94
- 'def foo bar, &baz; end'.
95
- must_be_parsed_as s(:defn,
96
- :foo,
97
- s(:args, :bar, :"&baz"),
98
- s(:nil))
99
- end
100
-
101
- it 'works with a default value plus explicit block parameter' do
102
- 'def foo bar=1, &baz; end'.
103
- must_be_parsed_as s(:defn,
104
- :foo,
105
- s(:args,
106
- s(:lasgn, :bar, s(:lit, 1)),
107
- :"&baz"),
108
- s(:nil))
109
- end
110
-
111
- it 'works with a default value plus mandatory argument' do
112
- 'def foo bar=1, baz; end'.
113
- must_be_parsed_as s(:defn,
114
- :foo,
115
- s(:args,
116
- s(:lasgn, :bar, s(:lit, 1)),
117
- :baz),
118
- s(:nil))
119
- end
120
-
121
- it 'works with a splat plus explicit block parameter' do
122
- 'def foo *bar, &baz; end'.
123
- must_be_parsed_as s(:defn,
124
- :foo,
125
- s(:args, :"*bar", :"&baz"),
126
- s(:nil))
127
- end
128
-
129
- it 'works with a default value plus splat' do
130
- 'def foo bar=1, *baz; end'.
131
- must_be_parsed_as s(:defn,
132
- :foo,
133
- s(:args,
134
- s(:lasgn, :bar, s(:lit, 1)),
135
- :"*baz"),
136
- s(:nil))
137
- end
138
-
139
- it 'works with a default value, splat, plus final mandatory arguments' do
140
- 'def foo bar=1, *baz, qux, quuz; end'.
141
- must_be_parsed_as s(:defn,
142
- :foo,
143
- s(:args,
144
- s(:lasgn, :bar, s(:lit, 1)),
145
- :"*baz", :qux, :quuz),
146
- s(:nil))
147
- end
148
-
149
- it 'works with a named argument with a default value' do
150
- 'def foo bar: 1; end'.
151
- must_be_parsed_as s(:defn,
152
- :foo,
153
- s(:args,
154
- s(:kwarg, :bar, s(:lit, 1))),
155
- s(:nil))
156
- end
157
-
158
- it 'works with a named argument with no default value' do
159
- 'def foo bar:; end'.
160
- must_be_parsed_as s(:defn,
161
- :foo,
162
- s(:args,
163
- s(:kwarg, :bar)),
164
- s(:nil))
165
- end
166
-
167
- it 'works with a double splat' do
168
- 'def foo **bar; end'.
169
- must_be_parsed_as s(:defn,
170
- :foo,
171
- s(:args, :'**bar'),
172
- s(:nil))
173
- end
174
-
175
- it 'works with argument destructuring' do
176
- 'def foo((bar, baz)); end'.
177
- must_be_parsed_as s(:defn, :foo,
178
- s(:args, s(:masgn, :bar, :baz)),
179
- s(:nil))
180
- end
181
-
182
- it 'works with argument destructuring including splat' do
183
- 'def foo((bar, *baz)); end'.
184
- must_be_parsed_as s(:defn, :foo,
185
- s(:args, s(:masgn, :bar, :'*baz')),
186
- s(:nil))
187
- end
188
-
189
- it 'works with nested argument destructuring' do
190
- 'def foo((bar, (baz, qux))); end'.
191
- must_be_parsed_as s(:defn, :foo,
192
- s(:args, s(:masgn, :bar, s(:masgn, :baz, :qux))),
193
- s(:nil))
194
- end
195
-
196
- it 'works when the method name is an operator' do
197
- 'def +; end'.
198
- must_be_parsed_as s(:defn, :+, s(:args),
199
- s(:nil))
200
- end
201
-
202
- it 'works when the method name is a keyword' do
203
- 'def for; end'.
204
- must_be_parsed_as s(:defn, :for, s(:args),
205
- s(:nil))
206
- end
207
- end
208
-
209
- describe 'for singleton method definitions' do
210
- it 'works with empty body' do
211
- 'def foo.bar; end'.
212
- must_be_parsed_as s(:defs,
213
- s(:call, nil, :foo),
214
- :bar,
215
- s(:args),
216
- s(:nil))
217
- end
218
-
219
- it 'works with a body with multiple statements' do
220
- 'def foo.bar; baz; qux; end'.
221
- must_be_parsed_as s(:defs,
222
- s(:call, nil, :foo),
223
- :bar,
224
- s(:args),
225
- s(:call, nil, :baz),
226
- s(:call, nil, :qux))
227
- end
228
-
229
- it 'works with a simple splat' do
230
- 'def foo.bar *baz; end'.
231
- must_be_parsed_as s(:defs,
232
- s(:call, nil, :foo),
233
- :bar,
234
- s(:args, :"*baz"),
235
- s(:nil))
236
- end
237
-
238
- it 'works when the method name is a keyword' do
239
- 'def foo.for; end'.
240
- must_be_parsed_as s(:defs,
241
- s(:call, nil, :foo),
242
- :for, s(:args),
243
- s(:nil))
244
- end
245
- end
246
-
247
- describe 'for the alias statement' do
248
- it 'works with regular barewords' do
249
- 'alias foo bar'.
250
- must_be_parsed_as s(:alias,
251
- s(:lit, :foo), s(:lit, :bar))
252
- end
253
-
254
- it 'works with symbols' do
255
- 'alias :foo :bar'.
256
- must_be_parsed_as s(:alias,
257
- s(:lit, :foo), s(:lit, :bar))
258
- end
259
-
260
- it 'works with operator barewords' do
261
- 'alias + -'.
262
- must_be_parsed_as s(:alias,
263
- s(:lit, :+), s(:lit, :-))
264
- end
265
-
266
- it 'treats keywords as symbols' do
267
- 'alias next foo'.
268
- must_be_parsed_as s(:alias, s(:lit, :next), s(:lit, :foo))
269
- end
270
-
271
- it 'works with global variables' do
272
- 'alias $foo $bar'.
273
- must_be_parsed_as s(:valias, :$foo, :$bar)
274
- end
275
- end
276
-
277
- describe 'for the undef statement' do
278
- it 'works with a single bareword identifier' do
279
- 'undef foo'.
280
- must_be_parsed_as s(:undef, s(:lit, :foo))
281
- end
282
-
283
- it 'works with a single symbol' do
284
- 'undef :foo'.
285
- must_be_parsed_as s(:undef, s(:lit, :foo))
286
- end
287
-
288
- it 'works with multiple bareword identifiers' do
289
- 'undef foo, bar'.
290
- must_be_parsed_as s(:block,
291
- s(:undef, s(:lit, :foo)),
292
- s(:undef, s(:lit, :bar)))
293
- end
294
-
295
- it 'works with multiple bareword symbols' do
296
- 'undef :foo, :bar'.
297
- must_be_parsed_as s(:block,
298
- s(:undef, s(:lit, :foo)),
299
- s(:undef, s(:lit, :bar)))
300
- end
301
- end
302
-
303
- describe 'for the return statement' do
304
- it 'works with no arguments' do
305
- 'return'.
306
- must_be_parsed_as s(:return)
307
- end
308
-
309
- it 'works with one argument' do
310
- 'return foo'.
311
- must_be_parsed_as s(:return,
312
- s(:call, nil, :foo))
313
- end
314
-
315
- it 'works with a splat argument' do
316
- 'return *foo'.
317
- must_be_parsed_as s(:return,
318
- s(:svalue,
319
- s(:splat,
320
- s(:call, nil, :foo))))
321
- end
322
-
323
- it 'works with multiple arguments' do
324
- 'return foo, bar'.
325
- must_be_parsed_as s(:return,
326
- s(:array,
327
- s(:call, nil, :foo),
328
- s(:call, nil, :bar)))
329
- end
330
-
331
- it 'works with a regular argument and a splat argument' do
332
- 'return foo, *bar'.
333
- must_be_parsed_as s(:return,
334
- s(:array,
335
- s(:call, nil, :foo),
336
- s(:splat,
337
- s(:call, nil, :bar))))
338
- end
339
-
340
- it 'works with a function call with parentheses' do
341
- 'return foo(bar)'.
342
- must_be_parsed_as s(:return,
343
- s(:call, nil, :foo,
344
- s(:call, nil, :bar)))
345
- end
346
-
347
- it 'works with a function call without parentheses' do
348
- 'return foo bar'.
349
- must_be_parsed_as s(:return,
350
- s(:call, nil, :foo,
351
- s(:call, nil, :bar)))
352
- end
353
- end
354
-
355
- describe 'for yield' do
356
- it 'works with no arguments and no parentheses' do
357
- 'yield'.
358
- must_be_parsed_as s(:yield)
359
- end
360
-
361
- it 'works with parentheses but no arguments' do
362
- 'yield()'.
363
- must_be_parsed_as s(:yield)
364
- end
365
-
366
- it 'works with one argument and no parentheses' do
367
- 'yield foo'.
368
- must_be_parsed_as s(:yield, s(:call, nil, :foo))
369
- end
370
-
371
- it 'works with one argument and parentheses' do
372
- 'yield(foo)'.
373
- must_be_parsed_as s(:yield, s(:call, nil, :foo))
374
- end
375
-
376
- it 'works with multiple arguments and no parentheses' do
377
- 'yield foo, bar'.
378
- must_be_parsed_as s(:yield,
379
- s(:call, nil, :foo),
380
- s(:call, nil, :bar))
381
- end
382
-
383
- it 'works with multiple arguments and parentheses' do
384
- 'yield(foo, bar)'.
385
- must_be_parsed_as s(:yield,
386
- s(:call, nil, :foo),
387
- s(:call, nil, :bar))
388
- end
389
-
390
- it 'works with splat' do
391
- 'yield foo, *bar'.
392
- must_be_parsed_as s(:yield,
393
- s(:call, nil, :foo),
394
- s(:splat, s(:call, nil, :bar)))
395
- end
396
-
397
- it 'works with a function call with parentheses' do
398
- 'yield foo(bar)'.
399
- must_be_parsed_as s(:yield,
400
- s(:call, nil, :foo,
401
- s(:call, nil, :bar)))
402
- end
403
-
404
- it 'works with a function call without parentheses' do
405
- 'yield foo bar'.
406
- must_be_parsed_as s(:yield,
407
- s(:call, nil, :foo,
408
- s(:call, nil, :bar)))
409
- end
410
- end
411
-
412
- describe 'when extra compatibility is turned on' do
413
- it 'still treats block kwargs as lvars' do
414
- 'def foo(**bar); baz { |**qux| bar; qux }; end'.
415
- must_be_parsed_as s(:defn, :foo,
416
- s(:args, :"**bar"),
417
- s(:iter,
418
- s(:call, nil, :baz),
419
- s(:args, :"**qux"),
420
- s(:block,
421
- s(:lvar, :bar),
422
- s(:lvar, :qux)))),
423
- extra_compatible: true
424
- end
425
- end
426
- end
427
- end
@@ -1,399 +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 boolean operators' do
8
- it 'handles :and' do
9
- 'foo and bar'.
10
- must_be_parsed_as s(:and,
11
- s(:call, nil, :foo),
12
- s(:call, nil, :bar))
13
- end
14
-
15
- it 'handles double :and' do
16
- 'foo and bar and baz'.
17
- must_be_parsed_as s(:and,
18
- s(:call, nil, :foo),
19
- s(:and,
20
- s(:call, nil, :bar),
21
- s(:call, nil, :baz)))
22
- end
23
-
24
- it 'handles :or' do
25
- 'foo or bar'.
26
- must_be_parsed_as s(:or,
27
- s(:call, nil, :foo),
28
- s(:call, nil, :bar))
29
- end
30
-
31
- it 'handles double :or' do
32
- 'foo or bar or baz'.
33
- must_be_parsed_as s(:or,
34
- s(:call, nil, :foo),
35
- s(:or,
36
- s(:call, nil, :bar),
37
- s(:call, nil, :baz)))
38
- end
39
-
40
- it 'handles :or after :and' do
41
- 'foo and bar or baz'.
42
- must_be_parsed_as s(:or,
43
- s(:and,
44
- s(:call, nil, :foo),
45
- s(:call, nil, :bar)),
46
- s(:call, nil, :baz))
47
- end
48
-
49
- it 'handles :and after :or' do
50
- 'foo or bar and baz'.
51
- must_be_parsed_as s(:and,
52
- s(:or,
53
- s(:call, nil, :foo),
54
- s(:call, nil, :bar)),
55
- s(:call, nil, :baz))
56
- end
57
-
58
- it 'converts :&& to :and' do
59
- 'foo && bar'.
60
- must_be_parsed_as s(:and,
61
- s(:call, nil, :foo),
62
- s(:call, nil, :bar))
63
- end
64
-
65
- it 'handles :|| after :&&' do
66
- 'foo && bar || baz'.
67
- must_be_parsed_as s(:or,
68
- s(:and,
69
- s(:call, nil, :foo),
70
- s(:call, nil, :bar)),
71
- s(:call, nil, :baz))
72
- end
73
-
74
- it 'handles :&& after :||' do
75
- 'foo || bar && baz'.
76
- must_be_parsed_as s(:or,
77
- s(:call, nil, :foo),
78
- s(:and,
79
- s(:call, nil, :bar),
80
- s(:call, nil, :baz)))
81
- end
82
-
83
- it 'handles :|| with parentheses' do
84
- '(foo || bar) || baz'.
85
- must_be_parsed_as s(:or,
86
- s(:or,
87
- s(:call, nil, :foo),
88
- s(:call, nil, :bar)),
89
- s(:call, nil, :baz))
90
- end
91
-
92
- it 'handles nested :|| with parentheses' do
93
- 'foo || (bar || baz) || qux'.
94
- must_be_parsed_as s(:or,
95
- s(:call, nil, :foo),
96
- s(:or,
97
- s(:or, s(:call, nil, :bar), s(:call, nil, :baz)),
98
- s(:call, nil, :qux)))
99
- end
100
-
101
- it 'converts :|| to :or' do
102
- 'foo || bar'.
103
- must_be_parsed_as s(:or,
104
- s(:call, nil, :foo),
105
- s(:call, nil, :bar))
106
- end
107
-
108
- it 'handles triple :and' do
109
- 'foo and bar and baz and qux'.
110
- must_be_parsed_as s(:and,
111
- s(:call, nil, :foo),
112
- s(:and,
113
- s(:call, nil, :bar),
114
- s(:and,
115
- s(:call, nil, :baz),
116
- s(:call, nil, :qux))))
117
- end
118
-
119
- it 'handles triple :&&' do
120
- 'foo && bar && baz && qux'.
121
- must_be_parsed_as s(:and,
122
- s(:call, nil, :foo),
123
- s(:and,
124
- s(:call, nil, :bar),
125
- s(:and,
126
- s(:call, nil, :baz),
127
- s(:call, nil, :qux))))
128
- end
129
-
130
- it 'handles :!=' do
131
- 'foo != bar'.
132
- must_be_parsed_as s(:call,
133
- s(:call, nil, :foo),
134
- :!=,
135
- s(:call, nil, :bar))
136
- end
137
-
138
- it 'keeps :begin for the first argument of a binary operator' do
139
- 'begin; bar; end + foo'.
140
- must_be_parsed_as s(:call,
141
- s(:begin, s(:call, nil, :bar)),
142
- :+,
143
- s(:call, nil, :foo))
144
- end
145
-
146
- it 'keeps :begin for the second argument of a binary operator' do
147
- 'foo + begin; bar; end'.
148
- must_be_parsed_as s(:call,
149
- s(:call, nil, :foo),
150
- :+,
151
- s(:begin, s(:call, nil, :bar)))
152
- end
153
-
154
- it 'does not keep :begin for the first argument of a boolean operator' do
155
- 'begin; bar; end and foo'.
156
- must_be_parsed_as s(:and,
157
- s(:call, nil, :bar),
158
- s(:call, nil, :foo))
159
- end
160
-
161
- it 'keeps :begin for the second argument of a boolean operator' do
162
- 'foo and begin; bar; end'.
163
- must_be_parsed_as s(:and,
164
- s(:call, nil, :foo),
165
- s(:begin, s(:call, nil, :bar)))
166
- end
167
-
168
- it 'does not keep :begin for the first argument of a shift operator' do
169
- 'begin; bar; end << foo'.
170
- must_be_parsed_as s(:call,
171
- s(:call, nil, :bar),
172
- :<<,
173
- s(:call, nil, :foo))
174
- end
175
-
176
- it 'does not keep :begin for the second argument of a shift operator' do
177
- 'foo >> begin; bar; end'.
178
- must_be_parsed_as s(:call,
179
- s(:call, nil, :foo),
180
- :>>,
181
- s(:call, nil, :bar))
182
- end
183
- end
184
-
185
- describe 'for the range operator' do
186
- it 'handles positive number literals' do
187
- '1..2'.
188
- must_be_parsed_as s(:lit, 1..2)
189
- end
190
-
191
- it 'handles negative number literals' do
192
- '-1..-2'.
193
- must_be_parsed_as s(:lit, -1..-2)
194
- end
195
-
196
- it 'handles float literals' do
197
- '1.0..2.0'.
198
- must_be_parsed_as s(:dot2,
199
- s(:lit, 1.0),
200
- s(:lit, 2.0))
201
- end
202
-
203
- it 'handles string literals' do
204
- "'a'..'z'".
205
- must_be_parsed_as s(:dot2,
206
- s(:str, 'a'),
207
- s(:str, 'z'))
208
- end
209
-
210
- it 'handles non-literal begin' do
211
- 'foo..3'.
212
- must_be_parsed_as s(:dot2,
213
- s(:call, nil, :foo),
214
- s(:lit, 3))
215
- end
216
-
217
- it 'handles non-literal end' do
218
- '3..foo'.
219
- must_be_parsed_as s(:dot2,
220
- s(:lit, 3),
221
- s(:call, nil, :foo))
222
- end
223
-
224
- it 'handles non-literals' do
225
- 'foo..bar'.
226
- must_be_parsed_as s(:dot2,
227
- s(:call, nil, :foo),
228
- s(:call, nil, :bar))
229
- end
230
- end
231
-
232
- describe 'for the exclusive range operator' do
233
- it 'handles positive number literals' do
234
- '1...2'.
235
- must_be_parsed_as s(:lit, 1...2)
236
- end
237
-
238
- it 'handles negative number literals' do
239
- '-1...-2'.
240
- must_be_parsed_as s(:lit, -1...-2)
241
- end
242
-
243
- it 'handles float literals' do
244
- '1.0...2.0'.
245
- must_be_parsed_as s(:dot3,
246
- s(:lit, 1.0),
247
- s(:lit, 2.0))
248
- end
249
-
250
- it 'handles string literals' do
251
- "'a'...'z'".
252
- must_be_parsed_as s(:dot3,
253
- s(:str, 'a'),
254
- s(:str, 'z'))
255
- end
256
-
257
- it 'handles non-literal begin' do
258
- 'foo...3'.
259
- must_be_parsed_as s(:dot3,
260
- s(:call, nil, :foo),
261
- s(:lit, 3))
262
- end
263
-
264
- it 'handles non-literal end' do
265
- '3...foo'.
266
- must_be_parsed_as s(:dot3,
267
- s(:lit, 3),
268
- s(:call, nil, :foo))
269
- end
270
-
271
- it 'handles two non-literals' do
272
- 'foo...bar'.
273
- must_be_parsed_as s(:dot3,
274
- s(:call, nil, :foo),
275
- s(:call, nil, :bar))
276
- end
277
- end
278
-
279
- describe 'for unary operators' do
280
- it 'handles unary minus with an integer literal' do
281
- '- 1'.must_be_parsed_as s(:call, s(:lit, 1), :-@)
282
- end
283
-
284
- it 'handles unary minus with a float literal' do
285
- '- 3.14'.must_be_parsed_as s(:call, s(:lit, 3.14), :-@)
286
- end
287
-
288
- it 'handles unary minus with a non-literal' do
289
- '-foo'.
290
- must_be_parsed_as s(:call,
291
- s(:call, nil, :foo),
292
- :-@)
293
- end
294
-
295
- it 'handles unary minus with a negative number literal' do
296
- '- -1'.must_be_parsed_as s(:call, s(:lit, -1), :-@)
297
- end
298
-
299
- it 'handles unary plus with a number literal' do
300
- '+ 1'.must_be_parsed_as s(:call, s(:lit, 1), :+@)
301
- end
302
-
303
- it 'handles unary plus with a non-literal' do
304
- '+foo'.
305
- must_be_parsed_as s(:call,
306
- s(:call, nil, :foo),
307
- :+@)
308
- end
309
-
310
- it 'handles unary !' do
311
- '!foo'.
312
- must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
313
- end
314
-
315
- it 'converts :not to :!' do
316
- 'not foo'.
317
- must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
318
- end
319
-
320
- it 'handles unary ! with a number literal' do
321
- '!1'.
322
- must_be_parsed_as s(:call, s(:lit, 1), :!)
323
- end
324
-
325
- it 'keeps :begin for the argument' do
326
- '- begin; foo; end'.
327
- must_be_parsed_as s(:call,
328
- s(:begin, s(:call, nil, :foo)),
329
- :-@)
330
- end
331
- end
332
-
333
- describe 'for the ternary operater' do
334
- it 'works in the simple case' do
335
- 'foo ? bar : baz'.
336
- must_be_parsed_as s(:if,
337
- s(:call, nil, :foo),
338
- s(:call, nil, :bar),
339
- s(:call, nil, :baz))
340
- end
341
-
342
- it 'keeps :begin for the first argument' do
343
- 'begin; foo; end ? bar : baz'.
344
- must_be_parsed_as s(:if,
345
- s(:begin, s(:call, nil, :foo)),
346
- s(:call, nil, :bar),
347
- s(:call, nil, :baz))
348
- end
349
-
350
- it 'keeps :begin for the second argument' do
351
- 'foo ? begin; bar; end : baz'.
352
- must_be_parsed_as s(:if,
353
- s(:call, nil, :foo),
354
- s(:begin, s(:call, nil, :bar)),
355
- s(:call, nil, :baz))
356
- end
357
-
358
- it 'keeps :begin for the third argument' do
359
- 'foo ? bar : begin; baz; end'.
360
- must_be_parsed_as s(:if,
361
- s(:call, nil, :foo),
362
- s(:call, nil, :bar),
363
- s(:begin, s(:call, nil, :baz)))
364
- end
365
- end
366
-
367
- describe 'for match operators' do
368
- it 'handles :=~ with two non-literals' do
369
- 'foo =~ bar'.
370
- must_be_parsed_as s(:call,
371
- s(:call, nil, :foo),
372
- :=~,
373
- s(:call, nil, :bar))
374
- end
375
-
376
- it 'handles :=~ with literal regexp on the left hand side' do
377
- '/foo/ =~ bar'.
378
- must_be_parsed_as s(:match2,
379
- s(:lit, /foo/),
380
- s(:call, nil, :bar))
381
- end
382
-
383
- it 'handles :=~ with literal regexp on the right hand side' do
384
- 'foo =~ /bar/'.
385
- must_be_parsed_as s(:match3,
386
- s(:lit, /bar/),
387
- s(:call, nil, :foo))
388
- end
389
-
390
- it 'handles negated match operators' do
391
- 'foo !~ bar'.must_be_parsed_as s(:not,
392
- s(:call,
393
- s(:call, nil, :foo),
394
- :=~,
395
- s(:call, nil, :bar)))
396
- end
397
- end
398
- end
399
- end