ripper_ruby_parser 1.7.2 → 1.8.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 +28 -0
- data/README.md +4 -4
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +33 -54
- 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/method_calls.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +12 -15
- data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +21 -15
- data/lib/ripper_ruby_parser/sexp_processor.rb +4 -17
- data/lib/ripper_ruby_parser/unescape.rb +36 -12
- data/lib/ripper_ruby_parser/version.rb +1 -1
- metadata +110 -78
- 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,429 +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 kwrest argument 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 kwrest argument 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 kwrest argument 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 kwrest argument as an lvar" 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 with a nameless kwrest argument" do
|
86
|
-
_("def foo **; end")
|
87
|
-
.must_be_parsed_as s(:defn,
|
88
|
-
:foo,
|
89
|
-
s(:args, :"**"),
|
90
|
-
s(:nil))
|
91
|
-
end
|
92
|
-
|
93
|
-
it "works for a simple case with explicit block parameter" do
|
94
|
-
_("def foo &bar; end")
|
95
|
-
.must_be_parsed_as s(:defn,
|
96
|
-
:foo,
|
97
|
-
s(:args, :"&bar"),
|
98
|
-
s(:nil))
|
99
|
-
end
|
100
|
-
|
101
|
-
it "works with a regular argument plus explicit block parameter" do
|
102
|
-
_("def foo bar, &baz; end")
|
103
|
-
.must_be_parsed_as s(:defn,
|
104
|
-
:foo,
|
105
|
-
s(:args, :bar, :"&baz"),
|
106
|
-
s(:nil))
|
107
|
-
end
|
108
|
-
|
109
|
-
it "works with a default value plus explicit block parameter" do
|
110
|
-
_("def foo bar=1, &baz; end")
|
111
|
-
.must_be_parsed_as s(:defn,
|
112
|
-
:foo,
|
113
|
-
s(:args,
|
114
|
-
s(:lasgn, :bar, s(:lit, 1)),
|
115
|
-
:"&baz"),
|
116
|
-
s(:nil))
|
117
|
-
end
|
118
|
-
|
119
|
-
it "works with a default value plus mandatory argument" do
|
120
|
-
_("def foo bar=1, baz; end")
|
121
|
-
.must_be_parsed_as s(:defn,
|
122
|
-
:foo,
|
123
|
-
s(:args,
|
124
|
-
s(:lasgn, :bar, s(:lit, 1)),
|
125
|
-
:baz),
|
126
|
-
s(:nil))
|
127
|
-
end
|
128
|
-
|
129
|
-
it "works with a splat plus explicit block parameter" do
|
130
|
-
_("def foo *bar, &baz; end")
|
131
|
-
.must_be_parsed_as s(:defn,
|
132
|
-
:foo,
|
133
|
-
s(:args, :"*bar", :"&baz"),
|
134
|
-
s(:nil))
|
135
|
-
end
|
136
|
-
|
137
|
-
it "works with a default value plus splat" do
|
138
|
-
_("def foo bar=1, *baz; end")
|
139
|
-
.must_be_parsed_as s(:defn,
|
140
|
-
:foo,
|
141
|
-
s(:args,
|
142
|
-
s(:lasgn, :bar, s(:lit, 1)),
|
143
|
-
:"*baz"),
|
144
|
-
s(:nil))
|
145
|
-
end
|
146
|
-
|
147
|
-
it "works with a default value, splat, plus final mandatory arguments" do
|
148
|
-
_("def foo bar=1, *baz, qux, quuz; end")
|
149
|
-
.must_be_parsed_as s(:defn,
|
150
|
-
:foo,
|
151
|
-
s(:args,
|
152
|
-
s(:lasgn, :bar, s(:lit, 1)),
|
153
|
-
:"*baz", :qux, :quuz),
|
154
|
-
s(:nil))
|
155
|
-
end
|
156
|
-
|
157
|
-
it "works with a named argument with a default value" do
|
158
|
-
_("def foo bar: 1; end")
|
159
|
-
.must_be_parsed_as s(:defn,
|
160
|
-
:foo,
|
161
|
-
s(:args,
|
162
|
-
s(:kwarg, :bar, s(:lit, 1))),
|
163
|
-
s(:nil))
|
164
|
-
end
|
165
|
-
|
166
|
-
it "works with a named argument with no default value" do
|
167
|
-
_("def foo bar:; end")
|
168
|
-
.must_be_parsed_as s(:defn,
|
169
|
-
:foo,
|
170
|
-
s(:args,
|
171
|
-
s(:kwarg, :bar)),
|
172
|
-
s(:nil))
|
173
|
-
end
|
174
|
-
|
175
|
-
it "works with a double splat" do
|
176
|
-
_("def foo **bar; end")
|
177
|
-
.must_be_parsed_as s(:defn,
|
178
|
-
:foo,
|
179
|
-
s(:args, :'**bar'),
|
180
|
-
s(:nil))
|
181
|
-
end
|
182
|
-
|
183
|
-
it "works with argument destructuring" do
|
184
|
-
_("def foo((bar, baz)); end")
|
185
|
-
.must_be_parsed_as s(:defn, :foo,
|
186
|
-
s(:args, s(:masgn, :bar, :baz)),
|
187
|
-
s(:nil))
|
188
|
-
end
|
189
|
-
|
190
|
-
it "works with argument destructuring including splat" do
|
191
|
-
_("def foo((bar, *baz)); end")
|
192
|
-
.must_be_parsed_as s(:defn, :foo,
|
193
|
-
s(:args, s(:masgn, :bar, :'*baz')),
|
194
|
-
s(:nil))
|
195
|
-
end
|
196
|
-
|
197
|
-
it "works with nested argument destructuring" do
|
198
|
-
_("def foo((bar, (baz, qux))); end")
|
199
|
-
.must_be_parsed_as s(:defn, :foo,
|
200
|
-
s(:args, s(:masgn, :bar, s(:masgn, :baz, :qux))),
|
201
|
-
s(:nil))
|
202
|
-
end
|
203
|
-
|
204
|
-
it "works when the method name is an operator" do
|
205
|
-
_("def +; end")
|
206
|
-
.must_be_parsed_as s(:defn, :+, s(:args),
|
207
|
-
s(:nil))
|
208
|
-
end
|
209
|
-
|
210
|
-
it "works when the method name is a keyword" do
|
211
|
-
_("def for; end")
|
212
|
-
.must_be_parsed_as s(:defn, :for, s(:args),
|
213
|
-
s(:nil))
|
214
|
-
end
|
215
|
-
|
216
|
-
it "assigns correct line numbers when the body is empty" do
|
217
|
-
_("def bar\nend")
|
218
|
-
.must_be_parsed_as s(:defn,
|
219
|
-
:bar,
|
220
|
-
s(:args).line(1),
|
221
|
-
s(:nil).line(2)).line(1),
|
222
|
-
with_line_numbers: true
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "for singleton method definitions" do
|
227
|
-
it "works with empty body" do
|
228
|
-
_("def foo.bar; end")
|
229
|
-
.must_be_parsed_as s(:defs,
|
230
|
-
s(:call, nil, :foo),
|
231
|
-
:bar,
|
232
|
-
s(:args),
|
233
|
-
s(:nil))
|
234
|
-
end
|
235
|
-
|
236
|
-
it "works with a body with multiple statements" do
|
237
|
-
_("def foo.bar; baz; qux; end")
|
238
|
-
.must_be_parsed_as s(:defs,
|
239
|
-
s(:call, nil, :foo),
|
240
|
-
:bar,
|
241
|
-
s(:args),
|
242
|
-
s(:call, nil, :baz),
|
243
|
-
s(:call, nil, :qux))
|
244
|
-
end
|
245
|
-
|
246
|
-
it "works with a simple splat" do
|
247
|
-
_("def foo.bar *baz; end")
|
248
|
-
.must_be_parsed_as s(:defs,
|
249
|
-
s(:call, nil, :foo),
|
250
|
-
:bar,
|
251
|
-
s(:args, :"*baz"),
|
252
|
-
s(:nil))
|
253
|
-
end
|
254
|
-
|
255
|
-
it "works when the method name is a keyword" do
|
256
|
-
_("def foo.for; end")
|
257
|
-
.must_be_parsed_as s(:defs,
|
258
|
-
s(:call, nil, :foo),
|
259
|
-
:for, s(:args),
|
260
|
-
s(:nil))
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "for the alias statement" do
|
265
|
-
it "works with regular barewords" do
|
266
|
-
_("alias foo bar")
|
267
|
-
.must_be_parsed_as s(:alias,
|
268
|
-
s(:lit, :foo), s(:lit, :bar))
|
269
|
-
end
|
270
|
-
|
271
|
-
it "works with symbols" do
|
272
|
-
_("alias :foo :bar")
|
273
|
-
.must_be_parsed_as s(:alias,
|
274
|
-
s(:lit, :foo), s(:lit, :bar))
|
275
|
-
end
|
276
|
-
|
277
|
-
it "works with operator barewords" do
|
278
|
-
_("alias + -")
|
279
|
-
.must_be_parsed_as s(:alias,
|
280
|
-
s(:lit, :+), s(:lit, :-))
|
281
|
-
end
|
282
|
-
|
283
|
-
it "treats keywords as symbols" do
|
284
|
-
_("alias next foo")
|
285
|
-
.must_be_parsed_as s(:alias, s(:lit, :next), s(:lit, :foo))
|
286
|
-
end
|
287
|
-
|
288
|
-
it "works with global variables" do
|
289
|
-
_("alias $foo $bar")
|
290
|
-
.must_be_parsed_as s(:valias, :$foo, :$bar)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe "for the undef statement" do
|
295
|
-
it "works with a single bareword identifier" do
|
296
|
-
_("undef foo")
|
297
|
-
.must_be_parsed_as s(:undef, s(:lit, :foo))
|
298
|
-
end
|
299
|
-
|
300
|
-
it "works with a single symbol" do
|
301
|
-
_("undef :foo")
|
302
|
-
.must_be_parsed_as s(:undef, s(:lit, :foo))
|
303
|
-
end
|
304
|
-
|
305
|
-
it "works with multiple bareword identifiers" do
|
306
|
-
_("undef foo, bar")
|
307
|
-
.must_be_parsed_as s(:block,
|
308
|
-
s(:undef, s(:lit, :foo)),
|
309
|
-
s(:undef, s(:lit, :bar)))
|
310
|
-
end
|
311
|
-
|
312
|
-
it "works with multiple bareword symbols" do
|
313
|
-
_("undef :foo, :bar")
|
314
|
-
.must_be_parsed_as s(:block,
|
315
|
-
s(:undef, s(:lit, :foo)),
|
316
|
-
s(:undef, s(:lit, :bar)))
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
describe "for the return statement" do
|
321
|
-
it "works with no arguments" do
|
322
|
-
_("return")
|
323
|
-
.must_be_parsed_as s(:return)
|
324
|
-
end
|
325
|
-
|
326
|
-
it "works with one argument" do
|
327
|
-
_("return foo")
|
328
|
-
.must_be_parsed_as s(:return,
|
329
|
-
s(:call, nil, :foo))
|
330
|
-
end
|
331
|
-
|
332
|
-
it "works with a splat argument" do
|
333
|
-
_("return *foo")
|
334
|
-
.must_be_parsed_as s(:return,
|
335
|
-
s(:svalue,
|
336
|
-
s(:splat,
|
337
|
-
s(:call, nil, :foo))))
|
338
|
-
end
|
339
|
-
|
340
|
-
it "works with multiple arguments" do
|
341
|
-
_("return foo, bar")
|
342
|
-
.must_be_parsed_as s(:return,
|
343
|
-
s(:array,
|
344
|
-
s(:call, nil, :foo),
|
345
|
-
s(:call, nil, :bar)))
|
346
|
-
end
|
347
|
-
|
348
|
-
it "works with a regular argument and a splat argument" do
|
349
|
-
_("return foo, *bar")
|
350
|
-
.must_be_parsed_as s(:return,
|
351
|
-
s(:array,
|
352
|
-
s(:call, nil, :foo),
|
353
|
-
s(:splat,
|
354
|
-
s(:call, nil, :bar))))
|
355
|
-
end
|
356
|
-
|
357
|
-
it "works with a function call with parentheses" do
|
358
|
-
_("return foo(bar)")
|
359
|
-
.must_be_parsed_as s(:return,
|
360
|
-
s(:call, nil, :foo,
|
361
|
-
s(:call, nil, :bar)))
|
362
|
-
end
|
363
|
-
|
364
|
-
it "works with a function call without parentheses" do
|
365
|
-
_("return foo bar")
|
366
|
-
.must_be_parsed_as s(:return,
|
367
|
-
s(:call, nil, :foo,
|
368
|
-
s(:call, nil, :bar)))
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
describe "for yield" do
|
373
|
-
it "works with no arguments and no parentheses" do
|
374
|
-
_("yield")
|
375
|
-
.must_be_parsed_as s(:yield)
|
376
|
-
end
|
377
|
-
|
378
|
-
it "works with parentheses but no arguments" do
|
379
|
-
_("yield()")
|
380
|
-
.must_be_parsed_as s(:yield)
|
381
|
-
end
|
382
|
-
|
383
|
-
it "works with one argument and no parentheses" do
|
384
|
-
_("yield foo")
|
385
|
-
.must_be_parsed_as s(:yield, s(:call, nil, :foo))
|
386
|
-
end
|
387
|
-
|
388
|
-
it "works with one argument and parentheses" do
|
389
|
-
_("yield(foo)")
|
390
|
-
.must_be_parsed_as s(:yield, s(:call, nil, :foo))
|
391
|
-
end
|
392
|
-
|
393
|
-
it "works with multiple arguments and no parentheses" do
|
394
|
-
_("yield foo, bar")
|
395
|
-
.must_be_parsed_as s(:yield,
|
396
|
-
s(:call, nil, :foo),
|
397
|
-
s(:call, nil, :bar))
|
398
|
-
end
|
399
|
-
|
400
|
-
it "works with multiple arguments and parentheses" do
|
401
|
-
_("yield(foo, bar)")
|
402
|
-
.must_be_parsed_as s(:yield,
|
403
|
-
s(:call, nil, :foo),
|
404
|
-
s(:call, nil, :bar))
|
405
|
-
end
|
406
|
-
|
407
|
-
it "works with splat" do
|
408
|
-
_("yield foo, *bar")
|
409
|
-
.must_be_parsed_as s(:yield,
|
410
|
-
s(:call, nil, :foo),
|
411
|
-
s(:splat, s(:call, nil, :bar)))
|
412
|
-
end
|
413
|
-
|
414
|
-
it "works with a function call with parentheses" do
|
415
|
-
_("yield foo(bar)")
|
416
|
-
.must_be_parsed_as s(:yield,
|
417
|
-
s(:call, nil, :foo,
|
418
|
-
s(:call, nil, :bar)))
|
419
|
-
end
|
420
|
-
|
421
|
-
it "works with a function call without parentheses" do
|
422
|
-
_("yield foo bar")
|
423
|
-
.must_be_parsed_as s(:yield,
|
424
|
-
s(:call, nil, :foo,
|
425
|
-
s(:call, nil, :bar)))
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
@@ -1,405 +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
|
-
|
231
|
-
it "handles endless range literals" do
|
232
|
-
skip "This Ruby version does not support endless ranges" if RUBY_VERSION < "2.6.0"
|
233
|
-
_("1..")
|
234
|
-
.must_be_parsed_as s(:dot2, s(:lit, 1), nil)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe "for the exclusive range operator" do
|
239
|
-
it "handles positive number literals" do
|
240
|
-
_("1...2")
|
241
|
-
.must_be_parsed_as s(:lit, 1...2)
|
242
|
-
end
|
243
|
-
|
244
|
-
it "handles negative number literals" do
|
245
|
-
_("-1...-2")
|
246
|
-
.must_be_parsed_as s(:lit, -1...-2)
|
247
|
-
end
|
248
|
-
|
249
|
-
it "handles float literals" do
|
250
|
-
_("1.0...2.0")
|
251
|
-
.must_be_parsed_as s(:dot3,
|
252
|
-
s(:lit, 1.0),
|
253
|
-
s(:lit, 2.0))
|
254
|
-
end
|
255
|
-
|
256
|
-
it "handles string literals" do
|
257
|
-
_("'a'...'z'")
|
258
|
-
.must_be_parsed_as s(:dot3,
|
259
|
-
s(:str, "a"),
|
260
|
-
s(:str, "z"))
|
261
|
-
end
|
262
|
-
|
263
|
-
it "handles non-literal begin" do
|
264
|
-
_("foo...3")
|
265
|
-
.must_be_parsed_as s(:dot3,
|
266
|
-
s(:call, nil, :foo),
|
267
|
-
s(:lit, 3))
|
268
|
-
end
|
269
|
-
|
270
|
-
it "handles non-literal end" do
|
271
|
-
_("3...foo")
|
272
|
-
.must_be_parsed_as s(:dot3,
|
273
|
-
s(:lit, 3),
|
274
|
-
s(:call, nil, :foo))
|
275
|
-
end
|
276
|
-
|
277
|
-
it "handles two non-literals" do
|
278
|
-
_("foo...bar")
|
279
|
-
.must_be_parsed_as s(:dot3,
|
280
|
-
s(:call, nil, :foo),
|
281
|
-
s(:call, nil, :bar))
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe "for unary operators" do
|
286
|
-
it "handles unary minus with an integer literal" do
|
287
|
-
_("- 1").must_be_parsed_as s(:call, s(:lit, 1), :-@)
|
288
|
-
end
|
289
|
-
|
290
|
-
it "handles unary minus with a float literal" do
|
291
|
-
_("- 3.14").must_be_parsed_as s(:call, s(:lit, 3.14), :-@)
|
292
|
-
end
|
293
|
-
|
294
|
-
it "handles unary minus with a non-literal" do
|
295
|
-
_("-foo")
|
296
|
-
.must_be_parsed_as s(:call,
|
297
|
-
s(:call, nil, :foo),
|
298
|
-
:-@)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "handles unary minus with a negative number literal" do
|
302
|
-
_("- -1").must_be_parsed_as s(:call, s(:lit, -1), :-@)
|
303
|
-
end
|
304
|
-
|
305
|
-
it "handles unary plus with a number literal" do
|
306
|
-
_("+ 1").must_be_parsed_as s(:call, s(:lit, 1), :+@)
|
307
|
-
end
|
308
|
-
|
309
|
-
it "handles unary plus with a non-literal" do
|
310
|
-
_("+foo")
|
311
|
-
.must_be_parsed_as s(:call,
|
312
|
-
s(:call, nil, :foo),
|
313
|
-
:+@)
|
314
|
-
end
|
315
|
-
|
316
|
-
it "handles unary !" do
|
317
|
-
_("!foo")
|
318
|
-
.must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "converts :not to :!" do
|
322
|
-
_("not foo")
|
323
|
-
.must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
324
|
-
end
|
325
|
-
|
326
|
-
it "handles unary ! with a number literal" do
|
327
|
-
_("!1")
|
328
|
-
.must_be_parsed_as s(:call, s(:lit, 1), :!)
|
329
|
-
end
|
330
|
-
|
331
|
-
it "keeps :begin for the argument" do
|
332
|
-
_("- begin; foo; end")
|
333
|
-
.must_be_parsed_as s(:call,
|
334
|
-
s(:begin, s(:call, nil, :foo)),
|
335
|
-
:-@)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe "for the ternary operater" do
|
340
|
-
it "works in the simple case" do
|
341
|
-
_("foo ? bar : baz")
|
342
|
-
.must_be_parsed_as s(:if,
|
343
|
-
s(:call, nil, :foo),
|
344
|
-
s(:call, nil, :bar),
|
345
|
-
s(:call, nil, :baz))
|
346
|
-
end
|
347
|
-
|
348
|
-
it "keeps :begin for the first argument" do
|
349
|
-
_("begin; foo; end ? bar : baz")
|
350
|
-
.must_be_parsed_as s(:if,
|
351
|
-
s(:begin, s(:call, nil, :foo)),
|
352
|
-
s(:call, nil, :bar),
|
353
|
-
s(:call, nil, :baz))
|
354
|
-
end
|
355
|
-
|
356
|
-
it "keeps :begin for the second argument" do
|
357
|
-
_("foo ? begin; bar; end : baz")
|
358
|
-
.must_be_parsed_as s(:if,
|
359
|
-
s(:call, nil, :foo),
|
360
|
-
s(:begin, s(:call, nil, :bar)),
|
361
|
-
s(:call, nil, :baz))
|
362
|
-
end
|
363
|
-
|
364
|
-
it "keeps :begin for the third argument" do
|
365
|
-
_("foo ? bar : begin; baz; end")
|
366
|
-
.must_be_parsed_as s(:if,
|
367
|
-
s(:call, nil, :foo),
|
368
|
-
s(:call, nil, :bar),
|
369
|
-
s(:begin, s(:call, nil, :baz)))
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
describe "for match operators" do
|
374
|
-
it "handles :=~ with two non-literals" do
|
375
|
-
_("foo =~ bar")
|
376
|
-
.must_be_parsed_as s(:call,
|
377
|
-
s(:call, nil, :foo),
|
378
|
-
:=~,
|
379
|
-
s(:call, nil, :bar))
|
380
|
-
end
|
381
|
-
|
382
|
-
it "handles :=~ with literal regexp on the left hand side" do
|
383
|
-
_("/foo/ =~ bar")
|
384
|
-
.must_be_parsed_as s(:match2,
|
385
|
-
s(:lit, /foo/),
|
386
|
-
s(:call, nil, :bar))
|
387
|
-
end
|
388
|
-
|
389
|
-
it "handles :=~ with literal regexp on the right hand side" do
|
390
|
-
_("foo =~ /bar/")
|
391
|
-
.must_be_parsed_as s(:match3,
|
392
|
-
s(:lit, /bar/),
|
393
|
-
s(:call, nil, :foo))
|
394
|
-
end
|
395
|
-
|
396
|
-
it "handles negated match operators" do
|
397
|
-
_("foo !~ bar").must_be_parsed_as s(:not,
|
398
|
-
s(:call,
|
399
|
-
s(:call, nil, :foo),
|
400
|
-
:=~,
|
401
|
-
s(:call, nil, :bar)))
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|