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
@@ -22,146 +22,146 @@ describe RipperRubyParser::SexpProcessor do
22
22
  TestProcessor.new
23
23
  end
24
24
 
25
- describe "#process" do
26
- describe "for a :program sexp" do
27
- it "strips off the outer :program node" do
25
+ describe '#process' do
26
+ describe 'for a :program sexp' do
27
+ it 'strips off the outer :program node' do
28
28
  sexp = s(:program, s(s(:foo)))
29
29
  result = processor.process sexp
30
30
  result.must_equal s(:foo_p)
31
31
  end
32
32
 
33
- it "transforms a multi-statement :program into a :block sexp" do
33
+ it 'transforms a multi-statement :program into a :block sexp' do
34
34
  sexp = s(:program, s(s(:foo), s(:bar)))
35
35
  result = processor.process sexp
36
36
  result.must_equal s(:block, s(:foo_p), s(:bar_p))
37
37
  end
38
38
  end
39
39
 
40
- describe "for a :string_literal sexp" do
41
- it "transforms a simple sexp to :str" do
42
- sexp = s(:string_literal, s(:string_content, s(:@tstring_content, "foo")))
40
+ describe 'for a :string_literal sexp' do
41
+ it 'transforms a simple sexp to :str' do
42
+ sexp = s(:string_literal, s(:string_content, s(:@tstring_content, 'foo')))
43
43
  result = processor.process sexp
44
- result.must_equal s(:str, "foo")
44
+ result.must_equal s(:str, 'foo')
45
45
  end
46
46
  end
47
47
 
48
- describe "for an :args_add_block sexp" do
49
- it "transforms a one-argument sexp to an :arglist" do
48
+ describe 'for an :args_add_block sexp' do
49
+ it 'transforms a one-argument sexp to an :arglist' do
50
50
  sexp = s(:args_add_block, s(s(:foo)), false)
51
51
  result = processor.process sexp
52
52
  result.must_equal s(:arglist, s(:foo_p))
53
53
  end
54
54
 
55
- it "transforms a multi-argument sexp to an :arglist" do
55
+ it 'transforms a multi-argument sexp to an :arglist' do
56
56
  sexp = s(:args_add_block, s(s(:foo), s(:bar)), false)
57
57
  result = processor.process sexp
58
58
  result.must_equal s(:arglist, s(:foo_p), s(:bar_p))
59
59
  end
60
60
  end
61
61
 
62
- describe "for a :command sexp" do
63
- it "transforms a sexp to a :call" do
64
- sexp = s(:command, s(:@ident, "foo", s(1, 0)), s(:arglist, s(:foo)))
62
+ describe 'for a :command sexp' do
63
+ it 'transforms a sexp to a :call' do
64
+ sexp = s(:command, s(:@ident, 'foo', s(1, 0)), s(:arglist, s(:foo)))
65
65
  result = processor.process sexp
66
66
  result.must_equal s(:call, nil, :foo, s(:foo_p))
67
67
  end
68
68
  end
69
69
 
70
- describe "for a :var_ref sexp" do
71
- it "transforms the sexp to a :lvar sexp" do
72
- sexp = s(:var_ref, s(:@ident, "bar", s(1, 4)))
70
+ describe 'for a :var_ref sexp' do
71
+ it 'transforms the sexp to a :lvar sexp' do
72
+ sexp = s(:var_ref, s(:@ident, 'bar', s(1, 4)))
73
73
  result = processor.process sexp
74
74
  result.must_equal s(:lvar, :bar)
75
75
  end
76
76
  end
77
77
 
78
- describe "for a :vcall sexp" do
79
- it "transforms the sexp to a :call sexp" do
80
- sexp = s(:vcall, s(:@ident, "bar", s(1, 4)))
78
+ describe 'for a :vcall sexp' do
79
+ it 'transforms the sexp to a :call sexp' do
80
+ sexp = s(:vcall, s(:@ident, 'bar', s(1, 4)))
81
81
  result = processor.process sexp
82
82
  result.must_equal s(:call, nil, :bar)
83
83
  end
84
84
  end
85
85
 
86
- describe "for a :module sexp" do
87
- it "does not create body eleents for an empty definition" do
86
+ describe 'for a :module sexp' do
87
+ it 'does not create body eleents for an empty definition' do
88
88
  sexp = s(:module,
89
- s(:const_ref, s(:@const, "Foo", s(1, 13))),
89
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))),
90
90
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
91
91
  result = processor.process sexp
92
92
  result.must_equal s(:module, :Foo)
93
93
  end
94
94
 
95
- it "creates a single body element for a definition with one statement" do
95
+ it 'creates a single body element for a definition with one statement' do
96
96
  sexp = s(:module,
97
- s(:const_ref, s(:@const, "Foo", s(1, 13))),
97
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))),
98
98
  s(:bodystmt, s(s(:foo)), nil, nil, nil))
99
99
  result = processor.process sexp
100
100
  result.must_equal s(:module, :Foo, s(:foo_p))
101
101
  end
102
102
 
103
- it "creates multiple body elements for a definition with more than one statement" do
103
+ it 'creates multiple body elements for a definition with more than one statement' do
104
104
  sexp = s(:module,
105
- s(:const_ref, s(:@const, "Foo", s(1, 13))),
105
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))),
106
106
  s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
107
107
  result = processor.process sexp
108
108
  result.must_equal s(:module, :Foo, s(:foo_p), s(:bar_p))
109
109
  end
110
110
  end
111
111
 
112
- describe "for a :class sexp" do
113
- it "does not create body eleents for an empty definition" do
112
+ describe 'for a :class sexp' do
113
+ it 'does not create body eleents for an empty definition' do
114
114
  sexp = s(:class,
115
- s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
115
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
116
116
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
117
117
  result = processor.process sexp
118
118
  result.must_equal s(:class, :Foo, nil)
119
119
  end
120
120
 
121
- it "creates a single body element for a definition with one statement" do
121
+ it 'creates a single body element for a definition with one statement' do
122
122
  sexp = s(:class,
123
- s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
123
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
124
124
  s(:bodystmt, s(s(:foo)), nil, nil, nil))
125
125
  result = processor.process sexp
126
126
  result.must_equal s(:class, :Foo, nil, s(:foo_p))
127
127
  end
128
128
 
129
- it "creates multiple body elements for a definition with more than one statement" do
129
+ it 'creates multiple body elements for a definition with more than one statement' do
130
130
  sexp = s(:class,
131
- s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
131
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
132
132
  s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
133
133
  result = processor.process sexp
134
134
  result.must_equal s(:class, :Foo, nil, s(:foo_p), s(:bar_p))
135
135
  end
136
136
 
137
- it "passes on the given ancestor" do
137
+ it 'passes on the given ancestor' do
138
138
  sexp = s(:class,
139
- s(:const_ref, s(:@const, "Foo", s(1, 13))),
140
- s(:var_ref, s(:@const, "Bar", s(1, 12))),
139
+ s(:const_ref, s(:@const, 'Foo', s(1, 13))),
140
+ s(:var_ref, s(:@const, 'Bar', s(1, 12))),
141
141
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
142
142
  result = processor.process sexp
143
143
  result.must_equal s(:class, :Foo, s(:const, :Bar))
144
144
  end
145
145
  end
146
146
 
147
- describe "for a :bodystmt sexp" do
148
- it "creates a :scope sexp with nested :block" do
147
+ describe 'for a :bodystmt sexp' do
148
+ it 'creates a :scope sexp with nested :block' do
149
149
  sexp = s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil)
150
150
  result = processor.process sexp
151
151
  result.must_equal s(s(:block, s(:foo_p), s(:bar_p)))
152
152
  end
153
153
 
154
- it "removes nested :void_stmt sexps" do
154
+ it 'removes nested :void_stmt sexps' do
155
155
  sexp = s(:bodystmt, s(s(:void_stmt), s(:foo)), nil, nil, nil)
156
156
  result = processor.process sexp
157
157
  result.must_equal s(s(:foo_p))
158
158
  end
159
159
  end
160
160
 
161
- describe "for a :def sexp" do
162
- it "transforms the sexp for a basic function definition" do
161
+ describe 'for a :def sexp' do
162
+ it 'transforms the sexp for a basic function definition' do
163
163
  sexp = s(:def,
164
- s(:@ident, "foo", s(1, 4)),
164
+ s(:@ident, 'foo', s(1, 4)),
165
165
  s(:params, nil, nil, nil, nil, nil),
166
166
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
167
167
  result = processor.process sexp
@@ -169,38 +169,38 @@ describe RipperRubyParser::SexpProcessor do
169
169
  end
170
170
  end
171
171
 
172
- describe "for a :params sexp" do
173
- describe "with a normal arguments" do
174
- it "creates :lvar sexps" do
175
- sexp = s(:params, s(s(:@ident, "bar", s(1, 8))), nil, nil, nil, nil)
172
+ describe 'for a :params sexp' do
173
+ describe 'with a normal arguments' do
174
+ it 'creates :lvar sexps' do
175
+ sexp = s(:params, s(s(:@ident, 'bar', s(1, 8))), nil, nil, nil, nil)
176
176
  result = processor.process sexp
177
177
  result.must_equal s(:args, s(:lvar, :bar))
178
178
  end
179
179
  end
180
180
  end
181
181
 
182
- describe "for an :assign sexp" do
183
- it "creates a :lasgn sexp" do
182
+ describe 'for an :assign sexp' do
183
+ it 'creates a :lasgn sexp' do
184
184
  sexp = s(:assign,
185
- s(:var_field, s(:@ident, "a", s(1, 0))),
186
- s(:@int, "1", s(1, 4)))
185
+ s(:var_field, s(:@ident, 'a', s(1, 0))),
186
+ s(:@int, '1', s(1, 4)))
187
187
  result = processor.process sexp
188
188
  result.must_equal s(:lasgn, :a, s(:lit, 1))
189
189
  end
190
190
  end
191
191
 
192
- describe "for a :binary sexp" do
193
- it "creates a :call sexp" do
192
+ describe 'for a :binary sexp' do
193
+ it 'creates a :call sexp' do
194
194
  sexp = s(:binary, s(:bar), :==, s(:foo))
195
195
  result = processor.process sexp
196
196
  result.must_equal s(:call, s(:bar_p), :==, s(:foo_p))
197
197
  end
198
198
  end
199
199
 
200
- describe "for a :method_add_block sexp" do
201
- it "creates an :iter sexp" do
200
+ describe 'for a :method_add_block sexp' do
201
+ it 'creates an :iter sexp' do
202
202
  sexp = s(:method_add_block,
203
- s(:call, s(:foo), :".", s(:@ident, "baz", s(1, 2))),
203
+ s(:call, s(:foo), :".", s(:@ident, 'baz', s(1, 2))),
204
204
  s(:brace_block, nil, s(s(:bar))))
205
205
  result = processor.process sexp
206
206
  result.must_equal s(:iter,
@@ -208,13 +208,13 @@ describe RipperRubyParser::SexpProcessor do
208
208
  s(:bar_p))
209
209
  end
210
210
 
211
- describe "with a block parameter" do
212
- it "creates an :iter sexp with an :args sexp for the block parameter" do
211
+ describe 'with a block parameter' do
212
+ it 'creates an :iter sexp with an :args sexp for the block parameter' do
213
213
  sexp = s(:method_add_block,
214
- s(:call, s(:foo), :".", s(:@ident, "baz", s(1, 2))),
214
+ s(:call, s(:foo), :".", s(:@ident, 'baz', s(1, 2))),
215
215
  s(:brace_block,
216
216
  s(:block_var,
217
- s(:params, s(s(:@ident, "i", s(1, 6))), nil, nil, nil, nil),
217
+ s(:params, s(s(:@ident, 'i', s(1, 6))), nil, nil, nil, nil),
218
218
  nil),
219
219
  s(s(:bar))))
220
220
  result = processor.process sexp
@@ -226,17 +226,17 @@ describe RipperRubyParser::SexpProcessor do
226
226
  end
227
227
  end
228
228
 
229
- describe "for an :if sexp" do
230
- describe "with a single statement in the if body" do
231
- it "uses the statement sexp as the body" do
229
+ describe 'for an :if sexp' do
230
+ describe 'with a single statement in the if body' do
231
+ it 'uses the statement sexp as the body' do
232
232
  sexp = s(:if, s(:foo), s(s(:bar)), nil)
233
233
  result = processor.process sexp
234
234
  result.must_equal s(:if, s(:foo_p), s(:bar_p), nil)
235
235
  end
236
236
  end
237
237
 
238
- describe "with multiple statements in the if body" do
239
- it "uses a block containing the statement sexps as the body" do
238
+ describe 'with multiple statements in the if body' do
239
+ it 'uses a block containing the statement sexps as the body' do
240
240
  sexp = s(:if, s(:foo), s(s(:bar), s(:baz)), nil)
241
241
  result = processor.process sexp
242
242
  result.must_equal s(:if, s(:foo_p), s(:block, s(:bar_p), s(:baz_p)), nil)
@@ -244,26 +244,26 @@ describe RipperRubyParser::SexpProcessor do
244
244
  end
245
245
  end
246
246
 
247
- describe "for an :array sexp" do
248
- it "pulls up the element sexps" do
247
+ describe 'for an :array sexp' do
248
+ it 'pulls up the element sexps' do
249
249
  sexp = s(:array, s(s(:foo), s(:bar), s(:baz)))
250
250
  result = processor.process sexp
251
251
  result.must_equal s(:array, s(:foo_p), s(:bar_p), s(:baz_p))
252
252
  end
253
253
  end
254
254
 
255
- describe "for a :const_path_ref sexp" do
256
- it "returns a :colon2 sexp" do
255
+ describe 'for a :const_path_ref sexp' do
256
+ it 'returns a :colon2 sexp' do
257
257
  sexp = s(:const_path_ref,
258
- s(:var_ref, s(:@const, "Foo", s(1, 0))),
259
- s(:@const, "Bar", s(1, 5)))
258
+ s(:var_ref, s(:@const, 'Foo', s(1, 0))),
259
+ s(:@const, 'Bar', s(1, 5)))
260
260
  result = processor.process sexp
261
261
  result.must_equal s(:colon2, s(:const, :Foo), :Bar)
262
262
  end
263
263
  end
264
264
 
265
- describe "for a :when sexp" do
266
- it "turns nested :when clauses into a list" do
265
+ describe 'for a :when sexp' do
266
+ it 'turns nested :when clauses into a list' do
267
267
  sexp = s(:when, s(s(:foo)), s(s(:bar)),
268
268
  s(:when, s(s(:foo)), s(s(:bar)),
269
269
  s(:when, s(s(:foo)), s(s(:bar)), nil)))
@@ -276,22 +276,22 @@ describe RipperRubyParser::SexpProcessor do
276
276
  end
277
277
  end
278
278
 
279
- describe "#extract_node_symbol" do
280
- it "processes an identifier sexp to a bare symbol" do
281
- sexp = s(:@ident, "foo", s(1, 0))
279
+ describe '#extract_node_symbol' do
280
+ it 'processes an identifier sexp to a bare symbol' do
281
+ sexp = s(:@ident, 'foo', s(1, 0))
282
282
  result = processor.send :extract_node_symbol, sexp
283
283
  result.must_equal :foo
284
284
  end
285
285
 
286
- it "processes a const sexp to a bare symbol" do
287
- sexp = s(:@const, "Foo", s(1, 0))
286
+ it 'processes a const sexp to a bare symbol' do
287
+ sexp = s(:@const, 'Foo', s(1, 0))
288
288
  result = processor.send :extract_node_symbol, sexp
289
289
  result.must_equal :Foo
290
290
  end
291
291
  end
292
292
 
293
- describe "#trickle_up_line_numbers" do
294
- it "works through several nested levels" do
293
+ describe '#trickle_up_line_numbers' do
294
+ it 'works through several nested levels' do
295
295
  inner = s(:foo)
296
296
  outer = s(:bar, s(:baz, s(:qux, inner)))
297
297
  outer.line = 42
@@ -300,8 +300,8 @@ describe RipperRubyParser::SexpProcessor do
300
300
  end
301
301
  end
302
302
 
303
- describe "#trickle_down_line_numbers" do
304
- it "works through several nested levels" do
303
+ describe '#trickle_down_line_numbers' do
304
+ it 'works through several nested levels' do
305
305
  inner = s(:foo)
306
306
  inner.line = 42
307
307
  outer = s(:bar, s(:baz, s(:qux, inner)))
@@ -1,5 +1,5 @@
1
1
  describe RipperRubyParser do
2
- it "knows its own version" do
2
+ it 'knows its own version' do
3
3
  RipperRubyParser::VERSION.wont_be_nil
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor