ripper_ruby_parser 1.6.1 → 1.7.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 +8 -0
- data/README.md +4 -23
- data/Rakefile +12 -12
- data/lib/ripper_ruby_parser.rb +2 -2
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +9 -9
- data/lib/ripper_ruby_parser/parser.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers.rb +9 -9
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +3 -9
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +19 -24
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +14 -18
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_processor.rb +4 -4
- data/lib/ripper_ruby_parser/unescape.rb +11 -11
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/test/end_to_end/comments_test.rb +10 -10
- data/test/end_to_end/comparison_test.rb +28 -28
- data/test/end_to_end/lib_comparison_test.rb +6 -6
- data/test/end_to_end/line_numbering_test.rb +10 -10
- data/test/end_to_end/samples_comparison_test.rb +5 -5
- data/test/end_to_end/test_comparison_test.rb +6 -6
- data/test/pt_testcase/pt_test.rb +7 -7
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +163 -169
- data/test/ripper_ruby_parser/parser_test.rb +338 -338
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +475 -511
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +582 -564
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +469 -469
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +713 -724
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +155 -155
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +181 -181
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +337 -352
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +298 -298
- data/test/ripper_ruby_parser/sexp_processor_test.rb +119 -119
- data/test/ripper_ruby_parser/version_test.rb +2 -2
- data/test/samples/lambdas.rb +5 -0
- data/test/samples/misc.rb +3 -0
- data/test/samples/strings.rb +7 -0
- data/test/test_helper.rb +8 -6
- metadata +12 -10
@@ -1,660 +1,678 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
describe RipperRubyParser::Parser do
|
6
|
-
describe
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
|
10
|
-
must_be_parsed_as s(:iter,
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
it
|
16
|
-
|
17
|
-
must_be_parsed_as s(:iter,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
it
|
24
|
-
|
25
|
-
must_be_parsed_as s(:iter,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
it
|
32
|
-
|
33
|
-
must_be_parsed_as s(:iter,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
44
|
-
|
45
|
-
must_be_parsed_as s(:iter,
|
46
|
-
|
47
|
-
|
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
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
51
|
+
describe "for block parameters" do
|
52
52
|
specify do
|
53
|
-
|
54
|
-
must_be_parsed_as s(:iter,
|
55
|
-
|
56
|
-
|
57
|
-
|
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
58
|
end
|
59
59
|
|
60
60
|
specify do
|
61
|
-
|
62
|
-
must_be_parsed_as s(:iter,
|
63
|
-
|
64
|
-
|
65
|
-
|
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
66
|
end
|
67
67
|
|
68
68
|
specify do
|
69
|
-
|
70
|
-
must_be_parsed_as s(:iter,
|
71
|
-
|
72
|
-
|
69
|
+
_("foo do |bar,*| end")
|
70
|
+
.must_be_parsed_as s(:iter,
|
71
|
+
s(:call, nil, :foo),
|
72
|
+
s(:args, :bar, :"*"))
|
73
73
|
end
|
74
74
|
|
75
75
|
specify do
|
76
|
-
|
77
|
-
must_be_parsed_as s(:iter,
|
78
|
-
|
79
|
-
|
76
|
+
_("foo do |bar, &baz| end")
|
77
|
+
.must_be_parsed_as s(:iter,
|
78
|
+
s(:call, nil, :foo),
|
79
|
+
s(:args, :bar, :"&baz"))
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
83
|
-
|
84
|
-
must_be_parsed_as s(:iter,
|
85
|
-
|
86
|
-
|
87
|
-
|
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
88
|
end
|
89
89
|
|
90
|
-
it
|
91
|
-
|
92
|
-
must_be_parsed_as s(:iter,
|
93
|
-
|
94
|
-
|
95
|
-
|
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
96
|
end
|
97
97
|
|
98
|
-
it
|
99
|
-
|
100
|
-
must_be_parsed_as s(:iter,
|
101
|
-
|
102
|
-
|
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
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
|
107
|
-
must_be_parsed_as s(:iter,
|
108
|
-
|
109
|
-
|
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
110
|
end
|
111
111
|
|
112
|
-
it
|
113
|
-
|
114
|
-
must_be_parsed_as s(:iter,
|
115
|
-
|
116
|
-
|
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
117
|
end
|
118
118
|
|
119
|
-
it
|
120
|
-
|
121
|
-
must_be_parsed_as s(:iter,
|
122
|
-
|
123
|
-
|
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
124
|
end
|
125
125
|
|
126
|
-
it
|
127
|
-
|
128
|
-
must_be_parsed_as s(:iter,
|
129
|
-
|
130
|
-
|
131
|
-
|
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
132
|
end
|
133
133
|
|
134
|
-
it
|
135
|
-
|
136
|
-
must_be_parsed_as s(:iter,
|
137
|
-
|
138
|
-
|
139
|
-
|
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
140
|
end
|
141
141
|
|
142
|
-
it
|
143
|
-
|
144
|
-
must_be_parsed_as s(:iter,
|
145
|
-
|
146
|
-
|
147
|
-
|
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
148
|
end
|
149
149
|
|
150
|
-
it
|
151
|
-
|
152
|
-
must_be_parsed_as s(:iter,
|
153
|
-
|
154
|
-
|
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
155
|
end
|
156
156
|
|
157
|
-
it
|
158
|
-
|
159
|
-
must_be_parsed_as s(:iter,
|
160
|
-
|
161
|
-
|
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
162
|
end
|
163
163
|
|
164
|
-
it
|
165
|
-
|
166
|
-
must_be_parsed_as s(:iter,
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
171
|
end
|
172
172
|
|
173
|
-
it
|
174
|
-
|
175
|
-
must_be_parsed_as s(:iter,
|
176
|
-
|
177
|
-
|
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
178
|
end
|
179
179
|
|
180
|
-
it
|
181
|
-
|
182
|
-
must_be_parsed_as s(:iter,
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
describe
|
192
|
-
it
|
193
|
-
|
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
194
|
end
|
195
195
|
|
196
|
-
it
|
197
|
-
|
196
|
+
it "works for a simple begin..end block" do
|
197
|
+
_("begin; foo; end").must_be_parsed_as s(:call, nil, :foo)
|
198
198
|
end
|
199
199
|
|
200
|
-
it
|
201
|
-
|
202
|
-
must_be_parsed_as s(:block,
|
203
|
-
|
204
|
-
|
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
205
|
end
|
206
206
|
|
207
|
-
it
|
208
|
-
|
209
|
-
must_be_parsed_as s(:if,
|
210
|
-
|
211
|
-
|
212
|
-
|
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
213
|
end
|
214
214
|
|
215
|
-
it
|
216
|
-
|
217
|
-
must_be_parsed_as s(:if,
|
218
|
-
|
219
|
-
|
220
|
-
|
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
221
|
end
|
222
222
|
end
|
223
223
|
|
224
|
-
describe
|
225
|
-
it
|
226
|
-
|
227
|
-
must_be_parsed_as s(:rescue,
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
it
|
238
|
-
|
239
|
-
must_be_parsed_as s(:rescue,
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
it
|
248
|
-
|
249
|
-
must_be_parsed_as s(:block,
|
250
|
-
|
251
|
-
|
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
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
-
describe
|
256
|
-
it
|
257
|
-
|
258
|
-
must_be_parsed_as s(:rescue,
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
end
|
265
|
-
|
266
|
-
it
|
267
|
-
|
268
|
-
must_be_parsed_as s(:rescue,
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
end
|
275
|
-
|
276
|
-
it
|
277
|
-
|
278
|
-
must_be_parsed_as s(:rescue,
|
279
|
-
|
280
|
-
end
|
281
|
-
|
282
|
-
it
|
283
|
-
|
284
|
-
must_be_parsed_as s(:rescue,
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
it
|
292
|
-
|
293
|
-
must_be_parsed_as s(:rescue,
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
it
|
304
|
-
|
305
|
-
must_be_parsed_as s(:rescue,
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
it
|
313
|
-
|
314
|
-
must_be_parsed_as s(:rescue,
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
end
|
320
|
-
|
321
|
-
it
|
322
|
-
|
323
|
-
must_be_parsed_as s(:rescue,
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
it
|
333
|
-
|
334
|
-
must_be_parsed_as s(:rescue,
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
end
|
340
|
-
|
341
|
-
it
|
342
|
-
|
343
|
-
must_be_parsed_as s(:rescue,
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
end
|
349
|
-
|
350
|
-
it
|
351
|
-
|
352
|
-
must_be_parsed_as s(:rescue,
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
end
|
360
|
-
|
361
|
-
it
|
362
|
-
|
363
|
-
must_be_parsed_as s(:rescue,
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
end
|
368
|
-
|
369
|
-
it
|
370
|
-
|
371
|
-
must_be_parsed_as s(:defn,
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
end
|
380
|
-
|
381
|
-
it
|
382
|
-
|
383
|
-
must_be_parsed_as s(:defn,
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
end
|
392
|
-
|
393
|
-
it
|
394
|
-
|
395
|
-
must_be_parsed_as s(:defn,
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
end
|
404
|
-
|
405
|
-
it
|
406
|
-
|
407
|
-
must_be_parsed_as s(:defn,
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
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
412
|
end
|
413
413
|
end
|
414
414
|
|
415
|
-
describe
|
416
|
-
it
|
417
|
-
|
418
|
-
must_be_parsed_as s(:rescue,
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
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
423
|
end
|
424
424
|
|
425
|
-
it
|
426
|
-
|
427
|
-
must_be_parsed_as s(:rescue,
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
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
432
|
end
|
433
433
|
end
|
434
434
|
|
435
|
-
describe
|
436
|
-
it
|
437
|
-
|
438
|
-
must_be_parsed_as s(:ensure,
|
439
|
-
|
440
|
-
|
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
441
|
end
|
442
442
|
|
443
|
-
it
|
444
|
-
|
445
|
-
must_be_parsed_as s(:ensure,
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
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
452
|
end
|
453
453
|
|
454
|
-
it
|
455
|
-
|
456
|
-
must_be_parsed_as s(:ensure,
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
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
463
|
end
|
464
464
|
|
465
|
-
it
|
466
|
-
|
467
|
-
must_be_parsed_as s(:ensure, s(:nil))
|
465
|
+
it "works with empty main and ensure bodies" do
|
466
|
+
_("begin; ensure; end")
|
467
|
+
.must_be_parsed_as s(:ensure, s(:nil))
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
471
|
-
describe
|
472
|
-
it
|
473
|
-
|
474
|
-
must_be_parsed_as s(:iter,
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
end
|
479
|
-
|
480
|
-
it
|
481
|
-
|
482
|
-
must_be_parsed_as s(:iter,
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
end
|
487
|
-
|
488
|
-
it
|
489
|
-
|
490
|
-
must_be_parsed_as s(:iter,
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
end
|
498
|
-
|
499
|
-
it
|
500
|
-
|
501
|
-
must_be_parsed_as s(:iter,
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
end
|
509
|
-
|
510
|
-
it
|
511
|
-
|
512
|
-
must_be_parsed_as s(:iter,
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
end
|
519
|
-
|
520
|
-
it
|
521
|
-
|
522
|
-
must_be_parsed_as s(:iter,
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
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
528
|
end
|
529
529
|
end
|
530
530
|
|
531
|
-
describe
|
532
|
-
it
|
533
|
-
|
534
|
-
must_be_parsed_as s(:iter,
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
end
|
539
|
-
|
540
|
-
it
|
541
|
-
|
542
|
-
must_be_parsed_as s(:iter,
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
end
|
547
|
-
|
548
|
-
it
|
549
|
-
|
550
|
-
must_be_parsed_as s(:iter,
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
end
|
558
|
-
|
559
|
-
it
|
560
|
-
|
561
|
-
must_be_parsed_as s(:iter,
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
end
|
569
|
-
|
570
|
-
it
|
571
|
-
|
572
|
-
must_be_parsed_as s(:iter,
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
end
|
579
|
-
|
580
|
-
it
|
581
|
-
|
582
|
-
must_be_parsed_as s(:iter,
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
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
588
|
end
|
589
589
|
end
|
590
590
|
|
591
|
-
describe
|
592
|
-
it
|
593
|
-
|
594
|
-
must_be_parsed_as s(:block,
|
595
|
-
|
596
|
-
|
597
|
-
|
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
598
|
end
|
599
599
|
|
600
|
-
it
|
601
|
-
|
602
|
-
must_be_parsed_as s(:block,
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
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
607
|
end
|
608
608
|
end
|
609
609
|
|
610
|
-
describe
|
611
|
-
it
|
612
|
-
|
613
|
-
must_be_parsed_as s(:iter,
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
end
|
618
|
-
|
619
|
-
it
|
620
|
-
|
621
|
-
must_be_parsed_as s(:iter,
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
end
|
626
|
-
|
627
|
-
it
|
628
|
-
|
629
|
-
must_be_parsed_as s(:iter,
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
end
|
634
|
-
|
635
|
-
it
|
636
|
-
|
637
|
-
must_be_parsed_as s(:iter,
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
end
|
642
|
-
|
643
|
-
it
|
644
|
-
|
645
|
-
must_be_parsed_as s(:iter,
|
646
|
-
|
647
|
-
|
648
|
-
end
|
649
|
-
|
650
|
-
it
|
651
|
-
|
652
|
-
must_be_parsed_as s(:iter,
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
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))
|
658
676
|
end
|
659
677
|
end
|
660
678
|
end
|