ripper_ruby_parser 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,398 +1,398 @@
|
|
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(:and,
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
it
|
16
|
-
|
17
|
-
must_be_parsed_as s(:and,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
it
|
25
|
-
|
26
|
-
must_be_parsed_as s(:or,
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
it
|
32
|
-
|
33
|
-
must_be_parsed_as s(:or,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
it
|
41
|
-
|
42
|
-
must_be_parsed_as s(:or,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
it
|
50
|
-
|
51
|
-
must_be_parsed_as s(:and,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
it
|
59
|
-
|
60
|
-
must_be_parsed_as s(:and,
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
it
|
66
|
-
|
67
|
-
must_be_parsed_as s(:or,
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
it
|
75
|
-
|
76
|
-
must_be_parsed_as s(:or,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
it
|
84
|
-
|
85
|
-
must_be_parsed_as s(:or,
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
it
|
93
|
-
|
94
|
-
must_be_parsed_as
|
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
95
|
s(:call, nil, :foo),
|
96
96
|
s(:or,
|
97
97
|
s(:or, s(:call, nil, :bar), s(:call, nil, :baz)),
|
98
98
|
s(:call, nil, :qux)))
|
99
99
|
end
|
100
100
|
|
101
|
-
it
|
102
|
-
|
103
|
-
must_be_parsed_as s(:or,
|
104
|
-
|
105
|
-
|
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
106
|
end
|
107
107
|
|
108
|
-
it
|
109
|
-
|
110
|
-
must_be_parsed_as s(:and,
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
117
|
end
|
118
118
|
|
119
|
-
it
|
120
|
-
|
121
|
-
must_be_parsed_as s(:and,
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
128
|
end
|
129
129
|
|
130
|
-
it
|
131
|
-
|
132
|
-
must_be_parsed_as s(:call,
|
133
|
-
|
134
|
-
|
135
|
-
|
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
136
|
end
|
137
137
|
|
138
|
-
it
|
139
|
-
|
140
|
-
must_be_parsed_as s(:call,
|
141
|
-
|
142
|
-
|
143
|
-
|
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
144
|
end
|
145
145
|
|
146
|
-
it
|
147
|
-
|
148
|
-
must_be_parsed_as s(:call,
|
149
|
-
|
150
|
-
|
151
|
-
|
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
152
|
end
|
153
153
|
|
154
|
-
it
|
155
|
-
|
156
|
-
must_be_parsed_as s(:and,
|
157
|
-
|
158
|
-
|
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
159
|
end
|
160
160
|
|
161
|
-
it
|
162
|
-
|
163
|
-
must_be_parsed_as s(:and,
|
164
|
-
|
165
|
-
|
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
166
|
end
|
167
167
|
|
168
|
-
it
|
169
|
-
|
170
|
-
must_be_parsed_as s(:call,
|
171
|
-
|
172
|
-
|
173
|
-
|
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
174
|
end
|
175
175
|
|
176
|
-
it
|
177
|
-
|
178
|
-
must_be_parsed_as s(:call,
|
179
|
-
|
180
|
-
|
181
|
-
|
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
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
-
describe
|
186
|
-
it
|
187
|
-
|
188
|
-
must_be_parsed_as s(:lit, 1..2)
|
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
189
|
end
|
190
190
|
|
191
|
-
it
|
192
|
-
|
193
|
-
must_be_parsed_as s(:lit, -1..-2)
|
191
|
+
it "handles negative number literals" do
|
192
|
+
_("-1..-2")
|
193
|
+
.must_be_parsed_as s(:lit, -1..-2)
|
194
194
|
end
|
195
195
|
|
196
|
-
it
|
197
|
-
|
198
|
-
must_be_parsed_as s(:dot2,
|
199
|
-
|
200
|
-
|
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
201
|
end
|
202
202
|
|
203
|
-
it
|
204
|
-
"'a'..'z'"
|
205
|
-
must_be_parsed_as s(:dot2,
|
206
|
-
|
207
|
-
|
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
208
|
end
|
209
209
|
|
210
|
-
it
|
211
|
-
|
212
|
-
must_be_parsed_as s(:dot2,
|
213
|
-
|
214
|
-
|
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
215
|
end
|
216
216
|
|
217
|
-
it
|
218
|
-
|
219
|
-
must_be_parsed_as s(:dot2,
|
220
|
-
|
221
|
-
|
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
222
|
end
|
223
223
|
|
224
|
-
it
|
225
|
-
|
226
|
-
must_be_parsed_as s(:dot2,
|
227
|
-
|
228
|
-
|
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
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
-
describe
|
233
|
-
it
|
234
|
-
|
235
|
-
must_be_parsed_as s(:lit, 1...2)
|
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
236
|
end
|
237
237
|
|
238
|
-
it
|
239
|
-
|
240
|
-
must_be_parsed_as s(:lit, -1...-2)
|
238
|
+
it "handles negative number literals" do
|
239
|
+
_("-1...-2")
|
240
|
+
.must_be_parsed_as s(:lit, -1...-2)
|
241
241
|
end
|
242
242
|
|
243
|
-
it
|
244
|
-
|
245
|
-
must_be_parsed_as s(:dot3,
|
246
|
-
|
247
|
-
|
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
248
|
end
|
249
249
|
|
250
|
-
it
|
251
|
-
"'a'...'z'"
|
252
|
-
must_be_parsed_as s(:dot3,
|
253
|
-
|
254
|
-
|
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
255
|
end
|
256
256
|
|
257
|
-
it
|
258
|
-
|
259
|
-
must_be_parsed_as s(:dot3,
|
260
|
-
|
261
|
-
|
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
262
|
end
|
263
263
|
|
264
|
-
it
|
265
|
-
|
266
|
-
must_be_parsed_as s(:dot3,
|
267
|
-
|
268
|
-
|
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
269
|
end
|
270
270
|
|
271
|
-
it
|
272
|
-
|
273
|
-
must_be_parsed_as s(:dot3,
|
274
|
-
|
275
|
-
|
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
276
|
end
|
277
277
|
end
|
278
278
|
|
279
|
-
describe
|
280
|
-
it
|
281
|
-
|
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
282
|
end
|
283
283
|
|
284
|
-
it
|
285
|
-
|
284
|
+
it "handles unary minus with a float literal" do
|
285
|
+
_("- 3.14").must_be_parsed_as s(:call, s(:lit, 3.14), :-@)
|
286
286
|
end
|
287
287
|
|
288
|
-
it
|
289
|
-
|
290
|
-
must_be_parsed_as s(:call,
|
291
|
-
|
292
|
-
|
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
293
|
end
|
294
294
|
|
295
|
-
it
|
296
|
-
|
295
|
+
it "handles unary minus with a negative number literal" do
|
296
|
+
_("- -1").must_be_parsed_as s(:call, s(:lit, -1), :-@)
|
297
297
|
end
|
298
298
|
|
299
|
-
it
|
300
|
-
|
299
|
+
it "handles unary plus with a number literal" do
|
300
|
+
_("+ 1").must_be_parsed_as s(:call, s(:lit, 1), :+@)
|
301
301
|
end
|
302
302
|
|
303
|
-
it
|
304
|
-
|
305
|
-
must_be_parsed_as s(:call,
|
306
|
-
|
307
|
-
|
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
308
|
end
|
309
309
|
|
310
|
-
it
|
311
|
-
|
312
|
-
must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
310
|
+
it "handles unary !" do
|
311
|
+
_("!foo")
|
312
|
+
.must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
313
313
|
end
|
314
314
|
|
315
|
-
it
|
316
|
-
|
317
|
-
must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
315
|
+
it "converts :not to :!" do
|
316
|
+
_("not foo")
|
317
|
+
.must_be_parsed_as s(:call, s(:call, nil, :foo), :!)
|
318
318
|
end
|
319
319
|
|
320
|
-
it
|
321
|
-
|
322
|
-
must_be_parsed_as s(:call, s(:lit, 1), :!)
|
320
|
+
it "handles unary ! with a number literal" do
|
321
|
+
_("!1")
|
322
|
+
.must_be_parsed_as s(:call, s(:lit, 1), :!)
|
323
323
|
end
|
324
324
|
|
325
|
-
it
|
326
|
-
|
327
|
-
must_be_parsed_as s(:call,
|
328
|
-
|
329
|
-
|
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
330
|
end
|
331
331
|
end
|
332
332
|
|
333
|
-
describe
|
334
|
-
it
|
335
|
-
|
336
|
-
must_be_parsed_as s(:if,
|
337
|
-
|
338
|
-
|
339
|
-
|
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
340
|
end
|
341
341
|
|
342
|
-
it
|
343
|
-
|
344
|
-
must_be_parsed_as s(:if,
|
345
|
-
|
346
|
-
|
347
|
-
|
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
348
|
end
|
349
349
|
|
350
|
-
it
|
351
|
-
|
352
|
-
must_be_parsed_as s(:if,
|
353
|
-
|
354
|
-
|
355
|
-
|
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
356
|
end
|
357
357
|
|
358
|
-
it
|
359
|
-
|
360
|
-
must_be_parsed_as s(:if,
|
361
|
-
|
362
|
-
|
363
|
-
|
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
364
|
end
|
365
365
|
end
|
366
366
|
|
367
|
-
describe
|
368
|
-
it
|
369
|
-
|
370
|
-
must_be_parsed_as s(:call,
|
371
|
-
|
372
|
-
|
373
|
-
|
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
374
|
end
|
375
375
|
|
376
|
-
it
|
377
|
-
|
378
|
-
must_be_parsed_as s(:match2,
|
379
|
-
|
380
|
-
|
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
381
|
end
|
382
382
|
|
383
|
-
it
|
384
|
-
|
385
|
-
must_be_parsed_as s(:match3,
|
386
|
-
|
387
|
-
|
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
388
|
end
|
389
389
|
|
390
|
-
it
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
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
396
|
end
|
397
397
|
end
|
398
398
|
end
|