ripper_ruby_parser 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
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,18 +1,18 @@
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 regular if" do
6
- it "works with a single statement" do
7
- "if foo; bar; end".
4
+ describe '#parse' do
5
+ describe 'for regular if' do
6
+ it 'works with a single statement' do
7
+ 'if foo; bar; end'.
8
8
  must_be_parsed_as s(:if,
9
9
  s(:call, nil, :foo),
10
10
  s(:call, nil, :bar),
11
11
  nil)
12
12
  end
13
13
 
14
- it "works with multiple statements" do
15
- "if foo; bar; baz; end".
14
+ it 'works with multiple statements' do
15
+ 'if foo; bar; baz; end'.
16
16
  must_be_parsed_as s(:if,
17
17
  s(:call, nil, :foo),
18
18
  s(:block,
@@ -21,16 +21,16 @@ describe RipperRubyParser::Parser do
21
21
  nil)
22
22
  end
23
23
 
24
- it "works with an else clause" do
25
- "if foo; bar; else; baz; end".
24
+ it 'works with an else clause' do
25
+ 'if foo; bar; else; baz; end'.
26
26
  must_be_parsed_as s(:if,
27
27
  s(:call, nil, :foo),
28
28
  s(:call, nil, :bar),
29
29
  s(:call, nil, :baz))
30
30
  end
31
31
 
32
- it "works with an elsif clause" do
33
- "if foo; bar; elsif baz; qux; end".
32
+ it 'works with an elsif clause' do
33
+ 'if foo; bar; elsif baz; qux; end'.
34
34
  must_be_parsed_as s(:if,
35
35
  s(:call, nil, :foo),
36
36
  s(:call, nil, :bar),
@@ -40,16 +40,16 @@ describe RipperRubyParser::Parser do
40
40
  nil))
41
41
  end
42
42
 
43
- it "handles a negative condition correctly" do
44
- "if not foo; bar; end".
43
+ it 'handles a negative condition correctly' do
44
+ 'if not foo; bar; end'.
45
45
  must_be_parsed_as s(:if,
46
46
  s(:call, s(:call, nil, :foo), :!),
47
47
  s(:call, nil, :bar),
48
48
  nil)
49
49
  end
50
50
 
51
- it "handles a negative condition in elsif correctly" do
52
- "if foo; bar; elsif not baz; qux; end".
51
+ it 'handles a negative condition in elsif correctly' do
52
+ 'if foo; bar; elsif not baz; qux; end'.
53
53
  must_be_parsed_as s(:if,
54
54
  s(:call, nil, :foo),
55
55
  s(:call, nil, :bar),
@@ -58,143 +58,175 @@ describe RipperRubyParser::Parser do
58
58
  s(:call, nil, :qux), nil))
59
59
  end
60
60
 
61
- it "handles bare regex literal in condition" do
62
- "if /foo/; bar; end".
61
+ it 'handles bare regex literal in condition' do
62
+ 'if /foo/; bar; end'.
63
63
  must_be_parsed_as s(:if,
64
64
  s(:match, s(:lit, /foo/)),
65
65
  s(:call, nil, :bar),
66
66
  nil)
67
67
  end
68
68
 
69
- it "handles interpolated regex in condition" do
69
+ it 'handles interpolated regex in condition' do
70
70
  'if /#{foo}/; bar; end'.
71
71
  must_be_parsed_as s(:if,
72
- s(:dregx, "", s(:evstr, s(:call, nil, :foo))),
72
+ s(:dregx, '', s(:evstr, s(:call, nil, :foo))),
73
73
  s(:call, nil, :bar),
74
74
  nil)
75
75
  end
76
76
 
77
- it "handles block conditions" do
78
- "if (foo; bar); baz; end".
77
+ it 'handles block conditions' do
78
+ 'if (foo; bar); baz; end'.
79
79
  must_be_parsed_as s(:if,
80
80
  s(:block, s(:call, nil, :foo), s(:call, nil, :bar)),
81
81
  s(:call, nil, :baz),
82
82
  nil)
83
83
  end
84
84
 
85
- it "converts :dot2 to :flip2" do
86
- "if foo..bar; baz; end".
85
+ it 'converts :dot2 to :flip2' do
86
+ 'if foo..bar; baz; end'.
87
87
  must_be_parsed_as s(:if,
88
88
  s(:flip2, s(:call, nil, :foo), s(:call, nil, :bar)),
89
89
  s(:call, nil, :baz),
90
90
  nil)
91
91
  end
92
92
 
93
- it "converts :dot3 to :flip3" do
94
- "if foo...bar; baz; end".
93
+ it 'converts :dot3 to :flip3' do
94
+ 'if foo...bar; baz; end'.
95
95
  must_be_parsed_as s(:if,
96
96
  s(:flip3, s(:call, nil, :foo), s(:call, nil, :bar)),
97
97
  s(:call, nil, :baz),
98
98
  nil)
99
99
  end
100
+
101
+ it 'handles negative match operator' do
102
+ 'if foo !~ bar; baz; else; qux; end'.
103
+ must_be_parsed_as s(:if,
104
+ s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
105
+ s(:call, nil, :qux),
106
+ s(:call, nil, :baz))
107
+ end
100
108
  end
101
109
 
102
- describe "for postfix if" do
103
- it "works with a simple condition" do
104
- "foo if bar".
110
+ describe 'for postfix if' do
111
+ it 'works with a simple condition' do
112
+ 'foo if bar'.
105
113
  must_be_parsed_as s(:if,
106
114
  s(:call, nil, :bar),
107
115
  s(:call, nil, :foo),
108
116
  nil)
109
117
  end
110
118
 
111
- it "handles negative conditions" do
112
- "foo if not bar".
119
+ it 'handles negative conditions' do
120
+ 'foo if not bar'.
113
121
  must_be_parsed_as s(:if,
114
122
  s(:call, s(:call, nil, :bar), :!),
115
123
  s(:call, nil, :foo),
116
124
  nil)
117
125
  end
118
126
 
119
- it "handles bare regex literal in condition" do
120
- "foo if /bar/".
127
+ it 'handles bare regex literal in condition' do
128
+ 'foo if /bar/'.
121
129
  must_be_parsed_as s(:if,
122
130
  s(:match, s(:lit, /bar/)),
123
131
  s(:call, nil, :foo),
124
132
  nil)
125
133
  end
126
134
 
127
- it "handles interpolated regex in condition" do
135
+ it 'handles interpolated regex in condition' do
128
136
  'foo if /#{bar}/'.
129
137
  must_be_parsed_as s(:if,
130
- s(:dregx, "", s(:evstr, s(:call, nil, :bar))),
138
+ s(:dregx, '', s(:evstr, s(:call, nil, :bar))),
131
139
  s(:call, nil, :foo),
132
140
  nil)
133
141
  end
142
+
143
+ it 'handles negative match operator' do
144
+ 'baz if foo !~ bar'.
145
+ must_be_parsed_as s(:if,
146
+ s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
147
+ nil,
148
+ s(:call, nil, :baz))
149
+ end
134
150
  end
135
151
 
136
- describe "for regular unless" do
137
- it "works with a single statement" do
138
- "unless bar; foo; end".
152
+ describe 'for regular unless' do
153
+ it 'works with a single statement' do
154
+ 'unless bar; foo; end'.
139
155
  must_be_parsed_as s(:if,
140
156
  s(:call, nil, :bar),
141
157
  nil,
142
158
  s(:call, nil, :foo))
143
159
  end
144
160
 
145
- it "works with an else clause" do
146
- "unless foo; bar; else; baz; end".
161
+ it 'works with an else clause' do
162
+ 'unless foo; bar; else; baz; end'.
147
163
  must_be_parsed_as s(:if,
148
164
  s(:call, nil, :foo),
149
165
  s(:call, nil, :baz),
150
166
  s(:call, nil, :bar))
151
167
  end
152
- it "handles bare regex literal in condition" do
153
- "unless /foo/; bar; end".
168
+ it 'handles bare regex literal in condition' do
169
+ 'unless /foo/; bar; end'.
154
170
  must_be_parsed_as s(:if,
155
171
  s(:match, s(:lit, /foo/)),
156
172
  nil,
157
173
  s(:call, nil, :bar))
158
174
  end
159
175
 
160
- it "handles interpolated regex in condition" do
176
+ it 'handles interpolated regex in condition' do
161
177
  'unless /#{foo}/; bar; end'.
162
178
  must_be_parsed_as s(:if,
163
- s(:dregx, "", s(:evstr, s(:call, nil, :foo))),
179
+ s(:dregx, '', s(:evstr, s(:call, nil, :foo))),
164
180
  nil,
165
181
  s(:call, nil, :bar))
166
182
  end
183
+
184
+ it 'handles negative match operator' do
185
+ 'unless foo !~ bar; baz; else; qux; end'.
186
+ must_be_parsed_as s(:if,
187
+ s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
188
+ s(:call, nil, :baz),
189
+ s(:call, nil, :qux))
190
+ end
167
191
  end
168
192
 
169
- describe "for postfix unless" do
170
- it "works with a simple condition" do
171
- "foo unless bar".
193
+ describe 'for postfix unless' do
194
+ it 'works with a simple condition' do
195
+ 'foo unless bar'.
172
196
  must_be_parsed_as s(:if,
173
197
  s(:call, nil, :bar),
174
198
  nil,
175
199
  s(:call, nil, :foo))
176
200
  end
177
201
 
178
- it "handles bare regex literal in condition" do
179
- "foo unless /bar/".
202
+ it 'handles bare regex literal in condition' do
203
+ 'foo unless /bar/'.
180
204
  must_be_parsed_as s(:if,
181
205
  s(:match, s(:lit, /bar/)),
182
206
  nil,
183
207
  s(:call, nil, :foo))
184
208
  end
185
209
 
186
- it "handles interpolated regex in condition" do
210
+ it 'handles interpolated regex in condition' do
187
211
  'foo unless /#{bar}/'.
188
212
  must_be_parsed_as s(:if,
189
- s(:dregx, "", s(:evstr, s(:call, nil, :bar))),
213
+ s(:dregx, '', s(:evstr, s(:call, nil, :bar))),
190
214
  nil,
191
215
  s(:call, nil, :foo))
192
216
  end
217
+
218
+ it 'handles negative match operator' do
219
+ 'baz unless foo !~ bar'.
220
+ must_be_parsed_as s(:if,
221
+ s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
222
+ s(:call, nil, :baz),
223
+ nil)
224
+ end
193
225
  end
194
226
 
195
- describe "for case block" do
196
- it "works with a single when clause" do
197
- "case foo; when bar; baz; end".
227
+ describe 'for case block' do
228
+ it 'works with a single when clause' do
229
+ 'case foo; when bar; baz; end'.
198
230
  must_be_parsed_as s(:case,
199
231
  s(:call, nil, :foo),
200
232
  s(:when,
@@ -203,8 +235,8 @@ describe RipperRubyParser::Parser do
203
235
  nil)
204
236
  end
205
237
 
206
- it "works with multiple when clauses" do
207
- "case foo; when bar; baz; when qux; quux; end".
238
+ it 'works with multiple when clauses' do
239
+ 'case foo; when bar; baz; when qux; quux; end'.
208
240
  must_be_parsed_as s(:case,
209
241
  s(:call, nil, :foo),
210
242
  s(:when,
@@ -216,8 +248,8 @@ describe RipperRubyParser::Parser do
216
248
  nil)
217
249
  end
218
250
 
219
- it "works with multiple statements in the when block" do
220
- "case foo; when bar; baz; qux; end".
251
+ it 'works with multiple statements in the when block' do
252
+ 'case foo; when bar; baz; qux; end'.
221
253
  must_be_parsed_as s(:case,
222
254
  s(:call, nil, :foo),
223
255
  s(:when,
@@ -227,8 +259,8 @@ describe RipperRubyParser::Parser do
227
259
  nil)
228
260
  end
229
261
 
230
- it "works with an else clause" do
231
- "case foo; when bar; baz; else; qux; end".
262
+ it 'works with an else clause' do
263
+ 'case foo; when bar; baz; else; qux; end'.
232
264
  must_be_parsed_as s(:case,
233
265
  s(:call, nil, :foo),
234
266
  s(:when,
@@ -237,16 +269,16 @@ describe RipperRubyParser::Parser do
237
269
  s(:call, nil, :qux))
238
270
  end
239
271
 
240
- it "works with an empty when block" do
241
- "case foo; when bar; end".
272
+ it 'works with an empty when block' do
273
+ 'case foo; when bar; end'.
242
274
  must_be_parsed_as s(:case,
243
275
  s(:call, nil, :foo),
244
276
  s(:when, s(:array, s(:call, nil, :bar)), nil),
245
277
  nil)
246
278
  end
247
279
 
248
- it "works with an empty else block" do
249
- "case foo; when bar; baz; else; end".
280
+ it 'works with an empty else block' do
281
+ 'case foo; when bar; baz; else; end'.
250
282
  must_be_parsed_as s(:case,
251
283
  s(:call, nil, :foo),
252
284
  s(:when,
@@ -255,8 +287,8 @@ describe RipperRubyParser::Parser do
255
287
  nil)
256
288
  end
257
289
 
258
- it "works with a splat in the when clause" do
259
- "case foo; when *bar; baz; end".
290
+ it 'works with a splat in the when clause' do
291
+ 'case foo; when *bar; baz; end'.
260
292
  must_be_parsed_as s(:case,
261
293
  s(:call, nil, :foo),
262
294
  s(:when,