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,535 +1,535 @@
|
|
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(:if,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
it
|
17
|
-
|
18
|
-
must_be_parsed_as s(:if,
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
it
|
27
|
-
|
28
|
-
must_be_parsed_as s(:if,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
it
|
35
|
-
|
36
|
-
must_be_parsed_as s(:if,
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
it
|
43
|
-
|
44
|
-
must_be_parsed_as s(:if,
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
it
|
51
|
-
|
52
|
-
must_be_parsed_as s(:if,
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
it
|
59
|
-
|
60
|
-
must_be_parsed_as s(:if,
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
it
|
67
|
-
|
68
|
-
must_be_parsed_as s(:if,
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
it
|
75
|
-
|
76
|
-
must_be_parsed_as s(:if,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
it
|
83
|
-
|
84
|
-
must_be_parsed_as s(:if,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
it
|
91
|
-
'if /#{foo}/; bar; end'
|
92
|
-
must_be_parsed_as s(:if,
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
it
|
99
|
-
|
100
|
-
must_be_parsed_as s(:if,
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
it
|
107
|
-
|
108
|
-
must_be_parsed_as s(:if,
|
109
|
-
|
110
|
-
|
111
|
-
|
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
112
|
end
|
113
113
|
|
114
|
-
it
|
115
|
-
|
116
|
-
must_be_parsed_as s(:if,
|
117
|
-
|
118
|
-
|
119
|
-
|
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
120
|
end
|
121
121
|
|
122
|
-
it
|
123
|
-
|
124
|
-
must_be_parsed_as s(:if,
|
125
|
-
|
126
|
-
|
127
|
-
|
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
128
|
end
|
129
129
|
|
130
|
-
it
|
131
|
-
|
132
|
-
must_be_parsed_as s(:if,
|
133
|
-
|
134
|
-
|
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
135
|
end
|
136
136
|
|
137
|
-
it
|
138
|
-
|
139
|
-
must_be_parsed_as s(:if,
|
140
|
-
|
141
|
-
|
142
|
-
|
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
143
|
end
|
144
144
|
|
145
|
-
it
|
146
|
-
|
147
|
-
must_be_parsed_as s(:if,
|
148
|
-
|
149
|
-
|
150
|
-
|
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
151
|
end
|
152
152
|
|
153
|
-
it
|
154
|
-
|
155
|
-
must_be_parsed_as s(:if,
|
156
|
-
|
157
|
-
|
158
|
-
|
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
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
-
describe
|
163
|
-
it
|
164
|
-
|
165
|
-
must_be_parsed_as s(:if,
|
166
|
-
|
167
|
-
|
168
|
-
|
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
169
|
end
|
170
170
|
|
171
|
-
it
|
172
|
-
|
173
|
-
must_be_parsed_as s(:if,
|
174
|
-
|
175
|
-
|
176
|
-
|
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
177
|
end
|
178
178
|
|
179
|
-
it
|
180
|
-
|
181
|
-
must_be_parsed_as s(:if,
|
182
|
-
|
183
|
-
|
184
|
-
|
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
185
|
end
|
186
186
|
|
187
|
-
it
|
188
|
-
'foo if /#{bar}/'
|
189
|
-
must_be_parsed_as s(:if,
|
190
|
-
|
191
|
-
|
192
|
-
|
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
193
|
end
|
194
194
|
|
195
|
-
it
|
196
|
-
|
197
|
-
must_be_parsed_as s(:if,
|
198
|
-
|
199
|
-
|
200
|
-
|
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
201
|
end
|
202
202
|
|
203
|
-
it
|
204
|
-
|
205
|
-
must_be_parsed_as s(:if,
|
206
|
-
|
207
|
-
|
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
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
describe
|
212
|
-
it
|
213
|
-
|
214
|
-
must_be_parsed_as s(:if,
|
215
|
-
|
216
|
-
|
217
|
-
|
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
218
|
end
|
219
219
|
|
220
|
-
it
|
221
|
-
|
222
|
-
must_be_parsed_as s(:if,
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
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
228
|
end
|
229
229
|
|
230
|
-
it
|
231
|
-
|
232
|
-
must_be_parsed_as s(:if,
|
233
|
-
|
234
|
-
|
235
|
-
|
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
236
|
end
|
237
237
|
|
238
|
-
it
|
239
|
-
|
240
|
-
must_be_parsed_as s(:if,
|
241
|
-
|
242
|
-
|
243
|
-
|
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
244
|
end
|
245
245
|
|
246
|
-
it
|
247
|
-
|
248
|
-
must_be_parsed_as s(:if,
|
249
|
-
|
250
|
-
|
251
|
-
|
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
252
|
end
|
253
253
|
|
254
|
-
it
|
255
|
-
|
256
|
-
must_be_parsed_as s(:if,
|
257
|
-
|
258
|
-
|
259
|
-
|
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
260
|
end
|
261
261
|
|
262
|
-
it
|
263
|
-
|
264
|
-
must_be_parsed_as s(:if,
|
265
|
-
|
266
|
-
|
267
|
-
|
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
268
|
end
|
269
269
|
|
270
|
-
it
|
271
|
-
'unless /#{foo}/; bar; end'
|
272
|
-
must_be_parsed_as s(:if,
|
273
|
-
|
274
|
-
|
275
|
-
|
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
276
|
end
|
277
277
|
|
278
|
-
it
|
279
|
-
|
280
|
-
must_be_parsed_as s(:if,
|
281
|
-
|
282
|
-
|
283
|
-
|
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
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
describe
|
288
|
-
it
|
289
|
-
|
290
|
-
must_be_parsed_as s(:if,
|
291
|
-
|
292
|
-
|
293
|
-
|
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
294
|
end
|
295
295
|
|
296
|
-
it
|
297
|
-
|
298
|
-
must_be_parsed_as s(:if,
|
299
|
-
|
300
|
-
|
301
|
-
|
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
302
|
end
|
303
303
|
|
304
|
-
it
|
305
|
-
'foo unless /#{bar}/'
|
306
|
-
must_be_parsed_as s(:if,
|
307
|
-
|
308
|
-
|
309
|
-
|
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
310
|
end
|
311
311
|
|
312
|
-
it
|
313
|
-
|
314
|
-
must_be_parsed_as s(:if,
|
315
|
-
|
316
|
-
|
317
|
-
|
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
318
|
end
|
319
319
|
end
|
320
320
|
|
321
|
-
describe
|
322
|
-
it
|
323
|
-
|
324
|
-
must_be_parsed_as s(:if,
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
end
|
332
|
-
|
333
|
-
it
|
334
|
-
|
335
|
-
must_be_parsed_as s(:if,
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
|
-
it
|
345
|
-
|
346
|
-
must_be_parsed_as s(:if,
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
end
|
354
|
-
|
355
|
-
it
|
356
|
-
|
357
|
-
must_be_parsed_as s(:if,
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
end
|
365
|
-
|
366
|
-
it
|
367
|
-
|
368
|
-
must_be_parsed_as s(:if,
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
end
|
375
|
-
|
376
|
-
it
|
377
|
-
|
378
|
-
must_be_parsed_as s(:if,
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
end
|
385
|
-
|
386
|
-
it
|
387
|
-
|
388
|
-
must_be_parsed_as s(:if,
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
end
|
400
|
-
|
401
|
-
it
|
402
|
-
|
403
|
-
must_be_parsed_as s(:if,
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
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
410
|
end
|
411
411
|
end
|
412
412
|
|
413
|
-
describe
|
414
|
-
it
|
415
|
-
|
416
|
-
must_be_parsed_as s(:case,
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
end
|
423
|
-
|
424
|
-
it
|
425
|
-
|
426
|
-
must_be_parsed_as s(:case,
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
end
|
436
|
-
|
437
|
-
it
|
438
|
-
|
439
|
-
must_be_parsed_as s(:case,
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
end
|
447
|
-
|
448
|
-
it
|
449
|
-
|
450
|
-
must_be_parsed_as s(:case,
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
end
|
457
|
-
|
458
|
-
it
|
459
|
-
|
460
|
-
must_be_parsed_as s(:case,
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
end
|
470
|
-
|
471
|
-
it
|
472
|
-
|
473
|
-
must_be_parsed_as s(:case,
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
end
|
478
|
-
|
479
|
-
it
|
480
|
-
|
481
|
-
must_be_parsed_as s(:case,
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
end
|
488
|
-
|
489
|
-
it
|
490
|
-
|
491
|
-
must_be_parsed_as s(:case,
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
|
-
it
|
501
|
-
|
502
|
-
must_be_parsed_as s(:case,
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
end
|
510
|
-
|
511
|
-
it
|
512
|
-
|
513
|
-
must_be_parsed_as s(:case,
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
end
|
522
|
-
|
523
|
-
it
|
524
|
-
|
525
|
-
must_be_parsed_as s(:case,
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
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
533
|
end
|
534
534
|
end
|
535
535
|
end
|