ripper_ruby_parser 1.1.1 → 1.1.2

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Rakefile +2 -2
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +55 -4
  5. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +20 -13
  6. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +27 -12
  7. data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +25 -12
  8. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +4 -2
  9. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +19 -15
  10. data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +25 -11
  11. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +12 -4
  12. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +8 -4
  13. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +1 -5
  14. data/lib/ripper_ruby_parser/version.rb +1 -1
  15. data/lib/ripper_ruby_parser.rb +2 -2
  16. data/test/end_to_end/comments_test.rb +4 -4
  17. data/test/end_to_end/comparison_test.rb +15 -15
  18. data/test/end_to_end/error_conditions_test.rb +16 -16
  19. data/test/end_to_end/lib_comparison_test.rb +3 -3
  20. data/test/end_to_end/line_numbering_test.rb +4 -4
  21. data/test/end_to_end/samples_comparison_test.rb +4 -4
  22. data/test/end_to_end/test_comparison_test.rb +3 -3
  23. data/test/pt_testcase/pt_test.rb +4 -4
  24. data/test/test_helper.rb +1 -1
  25. data/test/unit/commenting_ripper_parser_test.rb +33 -33
  26. data/test/unit/parser_assignment_test.rb +30 -30
  27. data/test/unit/parser_blocks_test.rb +83 -65
  28. data/test/unit/parser_conditionals_test.rb +96 -64
  29. data/test/unit/parser_literals_test.rb +308 -212
  30. data/test/unit/parser_loops_test.rb +85 -15
  31. data/test/unit/parser_method_calls_test.rb +100 -41
  32. data/test/unit/parser_operators_test.rb +60 -28
  33. data/test/unit/parser_test.rb +435 -410
  34. data/test/unit/sexp_processor_test.rb +82 -82
  35. data/test/unit/version_test.rb +1 -1
  36. metadata +2 -2
@@ -1,10 +1,10 @@
1
1
  require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  describe RipperRubyParser::Parser do
4
- describe "#parse" do
5
- describe "for block parameters" do
4
+ describe '#parse' do
5
+ describe 'for block parameters' do
6
6
  specify do
7
- "foo do |(bar, baz)| end".
7
+ 'foo do |(bar, baz)| end'.
8
8
  must_be_parsed_as s(:iter,
9
9
  s(:call, nil, :foo),
10
10
  s(:args,
@@ -12,7 +12,7 @@ describe RipperRubyParser::Parser do
12
12
  end
13
13
 
14
14
  specify do
15
- "foo do |(bar, *baz)| end".
15
+ 'foo do |(bar, *baz)| end'.
16
16
  must_be_parsed_as s(:iter,
17
17
  s(:call, nil, :foo),
18
18
  s(:args,
@@ -20,46 +20,46 @@ describe RipperRubyParser::Parser do
20
20
  end
21
21
 
22
22
  specify do
23
- "foo do |bar,*| end".
23
+ 'foo do |bar,*| end'.
24
24
  must_be_parsed_as s(:iter,
25
25
  s(:call, nil, :foo),
26
26
  s(:args, :bar, :"*"))
27
27
  end
28
28
 
29
29
  specify do
30
- "foo do |bar, &baz| end".
30
+ 'foo do |bar, &baz| end'.
31
31
  must_be_parsed_as s(:iter,
32
32
  s(:call, nil, :foo),
33
33
  s(:args, :bar, :"&baz"))
34
34
  end
35
35
 
36
- it "handles absent parameter specs" do
37
- "foo do; bar; end".
36
+ it 'handles absent parameter specs' do
37
+ 'foo do; bar; end'.
38
38
  must_be_parsed_as s(:iter,
39
39
  s(:call, nil, :foo),
40
40
  0,
41
41
  s(:call, nil, :bar))
42
42
  end
43
43
 
44
- it "handles empty parameter specs" do
45
- "foo do ||; bar; end".
44
+ it 'handles empty parameter specs' do
45
+ 'foo do ||; bar; end'.
46
46
  must_be_parsed_as s(:iter,
47
47
  s(:call, nil, :foo),
48
48
  s(:args),
49
49
  s(:call, nil, :bar))
50
50
  end
51
51
 
52
- it "ignores a trailing comma in the block parameters" do
53
- "foo do |bar, | end".
52
+ it 'ignores a trailing comma in the block parameters' do
53
+ 'foo do |bar, | end'.
54
54
  must_be_parsed_as s(:iter,
55
55
  s(:call, nil, :foo),
56
56
  s(:args, :bar))
57
57
  end
58
58
  end
59
59
 
60
- describe "for rescue/else" do
61
- it "works for a block with multiple rescue statements" do
62
- "begin foo; rescue; bar; rescue; baz; end".
60
+ describe 'for rescue/else' do
61
+ it 'works for a block with multiple rescue statements' do
62
+ 'begin foo; rescue; bar; rescue; baz; end'.
63
63
  must_be_parsed_as s(:rescue,
64
64
  s(:call, nil, :foo),
65
65
  s(:resbody,
@@ -70,8 +70,8 @@ describe RipperRubyParser::Parser do
70
70
  s(:call, nil, :baz)))
71
71
  end
72
72
 
73
- it "works for a block with rescue and else" do
74
- "begin; foo; rescue; bar; else; baz; end".
73
+ it 'works for a block with rescue and else' do
74
+ 'begin; foo; rescue; bar; else; baz; end'.
75
75
  must_be_parsed_as s(:rescue,
76
76
  s(:call, nil, :foo),
77
77
  s(:resbody,
@@ -80,17 +80,17 @@ describe RipperRubyParser::Parser do
80
80
  s(:call, nil, :baz))
81
81
  end
82
82
 
83
- it "works for a block with only else" do
84
- "begin; foo; else; bar; end".
83
+ it 'works for a block with only else' do
84
+ 'begin; foo; else; bar; end'.
85
85
  must_be_parsed_as s(:block,
86
86
  s(:call, nil, :foo),
87
87
  s(:call, nil, :bar))
88
88
  end
89
89
  end
90
90
 
91
- describe "for the rescue statement" do
92
- it "works with assignment to an error variable" do
93
- "begin; foo; rescue => bar; baz; end".
91
+ describe 'for the rescue statement' do
92
+ it 'works with assignment to an error variable' do
93
+ 'begin; foo; rescue => bar; baz; end'.
94
94
  must_be_parsed_as s(:rescue,
95
95
  s(:call, nil, :foo),
96
96
  s(:resbody,
@@ -99,8 +99,8 @@ describe RipperRubyParser::Parser do
99
99
  s(:call, nil, :baz)))
100
100
  end
101
101
 
102
- it "works with assignment of the exception to an instance variable" do
103
- "begin; foo; rescue => @bar; baz; end".
102
+ it 'works with assignment of the exception to an instance variable' do
103
+ 'begin; foo; rescue => @bar; baz; end'.
104
104
  must_be_parsed_as s(:rescue,
105
105
  s(:call, nil, :foo),
106
106
  s(:resbody,
@@ -109,14 +109,14 @@ describe RipperRubyParser::Parser do
109
109
  s(:call, nil, :baz)))
110
110
  end
111
111
 
112
- it "works with empty main and rescue bodies" do
113
- "begin; rescue; end".
112
+ it 'works with empty main and rescue bodies' do
113
+ 'begin; rescue; end'.
114
114
  must_be_parsed_as s(:rescue,
115
115
  s(:resbody, s(:array), nil))
116
116
  end
117
117
 
118
- it "works with single statement main and rescue bodies" do
119
- "begin; foo; rescue; bar; end".
118
+ it 'works with single statement main and rescue bodies' do
119
+ 'begin; foo; rescue; bar; end'.
120
120
  must_be_parsed_as s(:rescue,
121
121
  s(:call, nil, :foo),
122
122
  s(:resbody,
@@ -124,8 +124,8 @@ describe RipperRubyParser::Parser do
124
124
  s(:call, nil, :bar)))
125
125
  end
126
126
 
127
- it "works with multi-statement main and rescue bodies" do
128
- "begin; foo; bar; rescue; baz; qux; end".
127
+ it 'works with multi-statement main and rescue bodies' do
128
+ 'begin; foo; bar; rescue; baz; qux; end'.
129
129
  must_be_parsed_as s(:rescue,
130
130
  s(:block,
131
131
  s(:call, nil, :foo),
@@ -136,8 +136,8 @@ describe RipperRubyParser::Parser do
136
136
  s(:call, nil, :qux)))
137
137
  end
138
138
 
139
- it "works with assignment to an error variable" do
140
- "begin; foo; rescue => e; bar; end".
139
+ it 'works with assignment to an error variable' do
140
+ 'begin; foo; rescue => e; bar; end'.
141
141
  must_be_parsed_as s(:rescue,
142
142
  s(:call, nil, :foo),
143
143
  s(:resbody,
@@ -145,8 +145,8 @@ describe RipperRubyParser::Parser do
145
145
  s(:call, nil, :bar)))
146
146
  end
147
147
 
148
- it "works with filtering of the exception type" do
149
- "begin; foo; rescue Bar; baz; end".
148
+ it 'works with filtering of the exception type' do
149
+ 'begin; foo; rescue Bar; baz; end'.
150
150
  must_be_parsed_as s(:rescue,
151
151
  s(:call, nil, :foo),
152
152
  s(:resbody,
@@ -154,8 +154,8 @@ describe RipperRubyParser::Parser do
154
154
  s(:call, nil, :baz)))
155
155
  end
156
156
 
157
- it "works with filtering of the exception type and assignment to an error variable" do
158
- "begin; foo; rescue Bar => e; baz; end".
157
+ it 'works with filtering of the exception type and assignment to an error variable' do
158
+ 'begin; foo; rescue Bar => e; baz; end'.
159
159
  must_be_parsed_as s(:rescue,
160
160
  s(:call, nil, :foo),
161
161
  s(:resbody,
@@ -165,8 +165,8 @@ describe RipperRubyParser::Parser do
165
165
  s(:call, nil, :baz)))
166
166
  end
167
167
 
168
- it "works rescuing multiple exception types" do
169
- "begin; foo; rescue Bar, Baz; qux; end".
168
+ it 'works rescuing multiple exception types' do
169
+ 'begin; foo; rescue Bar, Baz; qux; end'.
170
170
  must_be_parsed_as s(:rescue,
171
171
  s(:call, nil, :foo),
172
172
  s(:resbody,
@@ -174,8 +174,8 @@ describe RipperRubyParser::Parser do
174
174
  s(:call, nil, :qux)))
175
175
  end
176
176
 
177
- it "works in the postfix case" do
178
- "foo rescue bar".
177
+ it 'works in the postfix case' do
178
+ 'foo rescue bar'.
179
179
  must_be_parsed_as s(:rescue,
180
180
  s(:call, nil, :foo),
181
181
  s(:resbody,
@@ -183,8 +183,8 @@ describe RipperRubyParser::Parser do
183
183
  s(:call, nil, :bar)))
184
184
  end
185
185
 
186
- it "works in a plain method body" do
187
- "def foo; bar; rescue; baz; end".
186
+ it 'works in a plain method body' do
187
+ 'def foo; bar; rescue; baz; end'.
188
188
  must_be_parsed_as s(:defn,
189
189
  :foo,
190
190
  s(:args),
@@ -195,8 +195,8 @@ describe RipperRubyParser::Parser do
195
195
  s(:call, nil, :baz))))
196
196
  end
197
197
 
198
- it "works in a method body inside begin..end" do
199
- "def foo; bar; begin; baz; rescue; qux; end; quuz; end".
198
+ it 'works in a method body inside begin..end' do
199
+ 'def foo; bar; begin; baz; rescue; qux; end; quuz; end'.
200
200
  must_be_parsed_as s(:defn,
201
201
  :foo,
202
202
  s(:args),
@@ -208,16 +208,16 @@ describe RipperRubyParser::Parser do
208
208
  end
209
209
  end
210
210
 
211
- describe "for the ensure statement" do
212
- it "works with single statement main and ensure bodies" do
213
- "begin; foo; ensure; bar; end".
211
+ describe 'for the ensure statement' do
212
+ it 'works with single statement main and ensure bodies' do
213
+ 'begin; foo; ensure; bar; end'.
214
214
  must_be_parsed_as s(:ensure,
215
215
  s(:call, nil, :foo),
216
216
  s(:call, nil, :bar))
217
217
  end
218
218
 
219
- it "works with multi-statement main and ensure bodies" do
220
- "begin; foo; bar; ensure; baz; qux; end".
219
+ it 'works with multi-statement main and ensure bodies' do
220
+ 'begin; foo; bar; ensure; baz; qux; end'.
221
221
  must_be_parsed_as s(:ensure,
222
222
  s(:block,
223
223
  s(:call, nil, :foo),
@@ -227,8 +227,8 @@ describe RipperRubyParser::Parser do
227
227
  s(:call, nil, :qux)))
228
228
  end
229
229
 
230
- it "works together with rescue" do
231
- "begin; foo; rescue; bar; ensure; baz; end".
230
+ it 'works together with rescue' do
231
+ 'begin; foo; rescue; bar; ensure; baz; end'.
232
232
  must_be_parsed_as s(:ensure,
233
233
  s(:rescue,
234
234
  s(:call, nil, :foo),
@@ -238,23 +238,23 @@ describe RipperRubyParser::Parser do
238
238
  s(:call, nil, :baz))
239
239
  end
240
240
 
241
- it "works with empty main and ensure bodies" do
242
- "begin; ensure; end".
241
+ it 'works with empty main and ensure bodies' do
242
+ 'begin; ensure; end'.
243
243
  must_be_parsed_as s(:ensure, s(:nil))
244
244
  end
245
245
  end
246
246
 
247
- describe "for lists of consecutive statments" do
248
- it "removes extra blocks for grouped statements at the start of the list" do
249
- "(foo; bar); baz".
247
+ describe 'for lists of consecutive statments' do
248
+ it 'removes extra blocks for grouped statements at the start of the list' do
249
+ '(foo; bar); baz'.
250
250
  must_be_parsed_as s(:block,
251
251
  s(:call, nil, :foo),
252
252
  s(:call, nil, :bar),
253
253
  s(:call, nil, :baz))
254
254
  end
255
255
 
256
- it "keeps extra blocks for grouped statements at the end of the list" do
257
- "foo; (bar; baz)".
256
+ it 'keeps extra blocks for grouped statements at the end of the list' do
257
+ 'foo; (bar; baz)'.
258
258
  must_be_parsed_as s(:block,
259
259
  s(:call, nil, :foo),
260
260
  s(:block,
@@ -263,30 +263,48 @@ describe RipperRubyParser::Parser do
263
263
  end
264
264
  end
265
265
 
266
- describe "for stabby lambda" do
267
- it "works in the simple case" do
268
- "->(foo) { bar }".
266
+ describe 'for stabby lambda' do
267
+ it 'works in the simple case' do
268
+ '->(foo) { bar }'.
269
269
  must_be_parsed_as s(:iter,
270
270
  s(:call, nil, :lambda),
271
271
  s(:args, :foo),
272
272
  s(:call, nil, :bar))
273
273
  end
274
274
 
275
- it "works when there are zero arguments" do
276
- "->() { bar }".
275
+ it 'works when there are zero arguments' do
276
+ '->() { bar }'.
277
277
  must_be_parsed_as s(:iter,
278
278
  s(:call, nil, :lambda),
279
279
  s(:args),
280
280
  s(:call, nil, :bar))
281
281
  end
282
282
 
283
- it "works when there are no arguments" do
284
- "-> { bar }".
283
+ it 'works when there are no arguments' do
284
+ '-> { bar }'.
285
285
  must_be_parsed_as s(:iter,
286
286
  s(:call, nil, :lambda),
287
287
  0,
288
288
  s(:call, nil, :bar))
289
289
  end
290
+
291
+ it 'works when there are no statements in the body' do
292
+ '->(foo) { }'.
293
+ must_be_parsed_as s(:iter,
294
+ s(:call, nil, :lambda),
295
+ s(:args, :foo))
296
+ end
297
+
298
+ it 'works when there are several statements in the body' do
299
+ '->(foo) { bar; baz }'.
300
+ must_be_parsed_as s(:iter,
301
+ s(:call, nil, :lambda),
302
+ s(:args, :foo),
303
+ s(:block,
304
+ s(:call, nil, :bar),
305
+ s(:call, nil, :baz)))
306
+ end
307
+
290
308
  end
291
309
  end
292
310
  end