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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +4 -23
  4. data/Rakefile +12 -12
  5. data/lib/ripper_ruby_parser.rb +2 -2
  6. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +9 -9
  7. data/lib/ripper_ruby_parser/parser.rb +3 -3
  8. data/lib/ripper_ruby_parser/sexp_handlers.rb +9 -9
  9. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +3 -9
  10. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +19 -24
  11. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +14 -18
  12. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_processor.rb +4 -4
  14. data/lib/ripper_ruby_parser/unescape.rb +11 -11
  15. data/lib/ripper_ruby_parser/version.rb +1 -1
  16. data/test/end_to_end/comments_test.rb +10 -10
  17. data/test/end_to_end/comparison_test.rb +28 -28
  18. data/test/end_to_end/lib_comparison_test.rb +6 -6
  19. data/test/end_to_end/line_numbering_test.rb +10 -10
  20. data/test/end_to_end/samples_comparison_test.rb +5 -5
  21. data/test/end_to_end/test_comparison_test.rb +6 -6
  22. data/test/pt_testcase/pt_test.rb +7 -7
  23. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +163 -169
  24. data/test/ripper_ruby_parser/parser_test.rb +338 -338
  25. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +475 -511
  26. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +582 -564
  27. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +469 -469
  28. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +713 -724
  29. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +155 -155
  30. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +181 -181
  31. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +337 -352
  32. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +298 -298
  33. data/test/ripper_ruby_parser/sexp_processor_test.rb +119 -119
  34. data/test/ripper_ruby_parser/version_test.rb +2 -2
  35. data/test/samples/lambdas.rb +5 -0
  36. data/test/samples/misc.rb +3 -0
  37. data/test/samples/strings.rb +7 -0
  38. data/test/test_helper.rb +8 -6
  39. metadata +12 -10
@@ -1,535 +1,535 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
3
+ require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
4
4
 
5
5
  describe RipperRubyParser::Parser do
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)
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 '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)
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 '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))
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 '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)
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 '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)
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 '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)
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 '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)
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 '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)
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 '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)
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 '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)
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 '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)
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 '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))
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 '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)
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 '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))
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 '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)))
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 '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)
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 '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))
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 '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)
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 '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))
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 '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))
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 '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))
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 '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))
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 '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))
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 '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))
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 '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))
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 '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)
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 '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))
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 '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)))
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