ripper_ruby_parser 1.1.2 → 1.2.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 +5 -5
- data/CHANGELOG.md +19 -0
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/lib/ripper_ruby_parser.rb +0 -7
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +112 -34
- data/lib/ripper_ruby_parser/parser.rb +26 -12
- data/lib/ripper_ruby_parser/sexp_handlers.rb +4 -1
- data/lib/ripper_ruby_parser/sexp_handlers/arguments.rb +7 -6
- data/lib/ripper_ruby_parser/sexp_handlers/arrays.rb +4 -2
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +39 -43
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +93 -69
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +30 -24
- data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +7 -9
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +51 -71
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +72 -56
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +14 -13
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +19 -13
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +19 -22
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +47 -35
- data/lib/ripper_ruby_parser/sexp_processor.rb +72 -85
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/test/end_to_end/line_numbering_test.rb +1 -1
- data/test/end_to_end/samples_comparison_test.rb +0 -1
- data/test/pt_testcase/pt_test.rb +4 -6
- data/test/{unit → ripper_ruby_parser}/commenting_ripper_parser_test.rb +82 -25
- data/test/{unit → ripper_ruby_parser}/parser_test.rb +37 -170
- data/test/{unit/parser_assignment_test.rb → ripper_ruby_parser/sexp_handlers/assignment_test.rb} +1 -1
- data/test/{unit/parser_blocks_test.rb → ripper_ruby_parser/sexp_handlers/blocks_test.rb} +267 -2
- data/test/{unit/parser_conditionals_test.rb → ripper_ruby_parser/sexp_handlers/conditionals_test.rb} +125 -17
- data/test/{unit/parser_literals_test.rb → ripper_ruby_parser/sexp_handlers/literals_test.rb} +10 -12
- data/test/{unit/parser_loops_test.rb → ripper_ruby_parser/sexp_handlers/loops_test.rb} +1 -1
- data/test/{unit/parser_method_calls_test.rb → ripper_ruby_parser/sexp_handlers/method_calls_test.rb} +10 -10
- data/test/{unit/parser_operators_test.rb → ripper_ruby_parser/sexp_handlers/operators_test.rb} +22 -2
- data/test/{unit → ripper_ruby_parser}/sexp_processor_test.rb +49 -48
- data/test/{unit → ripper_ruby_parser}/version_test.rb +0 -0
- data/test/samples/misc.rb +4 -0
- data/test/test_helper.rb +4 -4
- metadata +28 -42
- data/test/end_to_end/error_conditions_test.rb +0 -51
data/test/{unit/parser_literals_test.rb → ripper_ruby_parser/sexp_handlers/literals_test.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
4
|
describe '#parse' do
|
@@ -8,7 +8,7 @@ describe RipperRubyParser::Parser do
|
|
8
8
|
must_be_parsed_as s(:lit, /foo/)
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'works for regex literals with escaped right
|
11
|
+
it 'works for regex literals with escaped right parenthesis' do
|
12
12
|
'/\\)/'.
|
13
13
|
must_be_parsed_as s(:lit, /\)/)
|
14
14
|
end
|
@@ -155,12 +155,12 @@ describe RipperRubyParser::Parser do
|
|
155
155
|
must_be_parsed_as s(:str, '\\n')
|
156
156
|
end
|
157
157
|
|
158
|
-
it 'works for a representation of a regex literal with escaped right
|
158
|
+
it 'works for a representation of a regex literal with escaped right parenthesis' do
|
159
159
|
'"/\\\\)/"'.
|
160
160
|
must_be_parsed_as s(:str, '/\\)/')
|
161
161
|
end
|
162
162
|
|
163
|
-
it 'works for a uselessly escaped right
|
163
|
+
it 'works for a uselessly escaped right parenthesis' do
|
164
164
|
'"/\\)/"'.
|
165
165
|
must_be_parsed_as s(:str, '/)/')
|
166
166
|
end
|
@@ -210,7 +210,6 @@ describe RipperRubyParser::Parser do
|
|
210
210
|
|
211
211
|
# TODO: Implement remaining escape sequence cases.
|
212
212
|
|
213
|
-
# TODO: Behave differently in extra_compatible mode.
|
214
213
|
it 'works with unicode escapes (unlike RubyParser)' do
|
215
214
|
'"foo\\u273bbar"'.must_be_parsed_as s(:str, 'foo✻bar')
|
216
215
|
end
|
@@ -355,12 +354,12 @@ describe RipperRubyParser::Parser do
|
|
355
354
|
end
|
356
355
|
|
357
356
|
describe 'for word list literals' do
|
358
|
-
it 'works for the
|
359
|
-
'%
|
357
|
+
it 'works for the simple case with %w' do
|
358
|
+
'%w(foo bar)'.
|
360
359
|
must_be_parsed_as s(:array, s(:str, 'foo'), s(:str, 'bar'))
|
361
360
|
end
|
362
361
|
|
363
|
-
it 'works for the
|
362
|
+
it 'works for the simple case with %W' do
|
364
363
|
'%W(foo bar)'.
|
365
364
|
must_be_parsed_as s(:array, s(:str, 'foo'), s(:str, 'bar'))
|
366
365
|
end
|
@@ -407,7 +406,7 @@ describe RipperRubyParser::Parser do
|
|
407
406
|
"%I(foo \#{bar} baz)".
|
408
407
|
must_be_parsed_as s(:array,
|
409
408
|
s(:lit, :foo),
|
410
|
-
s(:dsym,
|
409
|
+
s(:dsym, '', s(:evstr, s(:call, nil, :bar))),
|
411
410
|
s(:lit, :baz))
|
412
411
|
end
|
413
412
|
|
@@ -416,9 +415,9 @@ describe RipperRubyParser::Parser do
|
|
416
415
|
must_be_parsed_as s(:array,
|
417
416
|
s(:lit, :foo),
|
418
417
|
s(:dsym,
|
419
|
-
|
418
|
+
'',
|
420
419
|
s(:evstr, s(:call, nil, :bar)),
|
421
|
-
s(:str,
|
420
|
+
s(:str, 'baz')))
|
422
421
|
end
|
423
422
|
end
|
424
423
|
|
@@ -559,7 +558,6 @@ describe RipperRubyParser::Parser do
|
|
559
558
|
end
|
560
559
|
|
561
560
|
it 'works for a hash with dynamic label keys' do
|
562
|
-
skip 'This is not valid syntax below Ruby 2.2' if RUBY_VERSION < '2.2.0'
|
563
561
|
"{'foo': bar}".
|
564
562
|
must_be_parsed_as s(:hash,
|
565
563
|
s(:lit, :foo),
|
data/test/{unit/parser_method_calls_test.rb → ripper_ruby_parser/sexp_handlers/method_calls_test.rb}
RENAMED
@@ -1,27 +1,27 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
4
|
describe '#parse' do
|
5
5
|
describe 'for method calls' do
|
6
6
|
describe 'without a receiver' do
|
7
|
-
it 'works without
|
7
|
+
it 'works without parentheses' do
|
8
8
|
'foo bar'.
|
9
9
|
must_be_parsed_as s(:call, nil, :foo,
|
10
10
|
s(:call, nil, :bar))
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'works with
|
13
|
+
it 'works with parentheses' do
|
14
14
|
'foo(bar)'.
|
15
15
|
must_be_parsed_as s(:call, nil, :foo,
|
16
16
|
s(:call, nil, :bar))
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'works with an empty parameter list and no
|
19
|
+
it 'works with an empty parameter list and no parentheses' do
|
20
20
|
'foo'.
|
21
21
|
must_be_parsed_as s(:call, nil, :foo)
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'works with
|
24
|
+
it 'works with parentheses around an empty parameter list' do
|
25
25
|
'foo()'.
|
26
26
|
must_be_parsed_as s(:call, nil, :foo)
|
27
27
|
end
|
@@ -31,7 +31,7 @@ describe RipperRubyParser::Parser do
|
|
31
31
|
must_be_parsed_as s(:call, nil, :foo?)
|
32
32
|
end
|
33
33
|
|
34
|
-
it 'works with nested calls without
|
34
|
+
it 'works with nested calls without parentheses' do
|
35
35
|
'foo bar baz'.
|
36
36
|
must_be_parsed_as s(:call, nil, :foo,
|
37
37
|
s(:call, nil, :bar,
|
@@ -102,7 +102,7 @@ describe RipperRubyParser::Parser do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
describe 'with a receiver' do
|
105
|
-
it 'works without
|
105
|
+
it 'works without parentheses' do
|
106
106
|
'foo.bar baz'.
|
107
107
|
must_be_parsed_as s(:call,
|
108
108
|
s(:call, nil, :foo),
|
@@ -110,7 +110,7 @@ describe RipperRubyParser::Parser do
|
|
110
110
|
s(:call, nil, :baz))
|
111
111
|
end
|
112
112
|
|
113
|
-
it 'works with
|
113
|
+
it 'works with parentheses' do
|
114
114
|
'foo.bar(baz)'.
|
115
115
|
must_be_parsed_as s(:call,
|
116
116
|
s(:call, nil, :foo),
|
@@ -118,7 +118,7 @@ describe RipperRubyParser::Parser do
|
|
118
118
|
s(:call, nil, :baz))
|
119
119
|
end
|
120
120
|
|
121
|
-
it 'works with
|
121
|
+
it 'works with parentheses around a call with no parentheses' do
|
122
122
|
'foo.bar(baz qux)'.
|
123
123
|
must_be_parsed_as s(:call,
|
124
124
|
s(:call, nil, :foo),
|
@@ -127,7 +127,7 @@ describe RipperRubyParser::Parser do
|
|
127
127
|
s(:call, nil, :qux)))
|
128
128
|
end
|
129
129
|
|
130
|
-
it 'works with nested calls without
|
130
|
+
it 'works with nested calls without parentheses' do
|
131
131
|
'foo.bar baz qux'.
|
132
132
|
must_be_parsed_as s(:call,
|
133
133
|
s(:call, nil, :foo),
|
data/test/{unit/parser_operators_test.rb → ripper_ruby_parser/sexp_handlers/operators_test.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('../../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
4
|
describe '#parse' do
|
@@ -88,7 +88,7 @@ describe RipperRubyParser::Parser do
|
|
88
88
|
s(:call, nil, :baz)))
|
89
89
|
end
|
90
90
|
|
91
|
-
it 'handles
|
91
|
+
it 'handles :|| with parentheses' do
|
92
92
|
'(foo || bar) || baz'.
|
93
93
|
must_be_parsed_as s(:or,
|
94
94
|
s(:or,
|
@@ -97,6 +97,15 @@ describe RipperRubyParser::Parser do
|
|
97
97
|
s(:call, nil, :baz))
|
98
98
|
end
|
99
99
|
|
100
|
+
it 'handles nested :|| with parentheses' do
|
101
|
+
'foo || (bar || baz) || qux'.
|
102
|
+
must_be_parsed_as s(:or,
|
103
|
+
s(:call, nil, :foo),
|
104
|
+
s(:or,
|
105
|
+
s(:or, s(:call, nil, :bar), s(:call, nil, :baz)),
|
106
|
+
s(:call, nil, :qux)))
|
107
|
+
end
|
108
|
+
|
100
109
|
it 'converts :|| to :or' do
|
101
110
|
'foo || bar'.
|
102
111
|
must_be_parsed_as s(:or,
|
@@ -114,6 +123,17 @@ describe RipperRubyParser::Parser do
|
|
114
123
|
s(:call, nil, :baz),
|
115
124
|
s(:call, nil, :qux))))
|
116
125
|
end
|
126
|
+
|
127
|
+
it 'handles triple :&&' do
|
128
|
+
'foo && bar && baz && qux'.
|
129
|
+
must_be_parsed_as s(:and,
|
130
|
+
s(:call, nil, :foo),
|
131
|
+
s(:and,
|
132
|
+
s(:call, nil, :bar),
|
133
|
+
s(:and,
|
134
|
+
s(:call, nil, :baz),
|
135
|
+
s(:call, nil, :qux))))
|
136
|
+
end
|
117
137
|
end
|
118
138
|
|
119
139
|
describe 'for unary numerical operators' do
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class TestProcessor < RipperRubyParser::SexpProcessor
|
4
|
-
def process_foo
|
4
|
+
def process_foo(exp)
|
5
5
|
exp.shift
|
6
6
|
s(:foo_p)
|
7
7
|
end
|
8
8
|
|
9
|
-
def process_bar
|
9
|
+
def process_bar(exp)
|
10
10
|
exp.shift
|
11
11
|
s(:bar_p)
|
12
12
|
end
|
13
13
|
|
14
|
-
def process_baz
|
14
|
+
def process_baz(exp)
|
15
15
|
exp.shift
|
16
16
|
s(:baz_p)
|
17
17
|
end
|
@@ -25,13 +25,13 @@ describe RipperRubyParser::SexpProcessor do
|
|
25
25
|
describe '#process' do
|
26
26
|
describe 'for a :program sexp' do
|
27
27
|
it 'strips off the outer :program node' do
|
28
|
-
sexp = s(:program, s(s(:foo)))
|
28
|
+
sexp = s(:program, s(:stmts, s(:foo)))
|
29
29
|
result = processor.process sexp
|
30
30
|
result.must_equal s(:foo_p)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'transforms a multi-statement :program into a :block sexp' do
|
34
|
-
sexp = s(:program, s(s(:foo), s(:bar)))
|
34
|
+
sexp = s(:program, s(:stmts, 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
|
@@ -47,13 +47,13 @@ describe RipperRubyParser::SexpProcessor do
|
|
47
47
|
|
48
48
|
describe 'for an :args_add_block sexp' do
|
49
49
|
it 'transforms a one-argument sexp to an :arglist' do
|
50
|
-
sexp = s(:args_add_block, s(s(:foo)), false)
|
50
|
+
sexp = s(:args_add_block, s(:args, 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
55
|
it 'transforms a multi-argument sexp to an :arglist' do
|
56
|
-
sexp = s(:args_add_block, s(s(:foo), s(:bar)), false)
|
56
|
+
sexp = s(:args_add_block, s(:args, 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
|
@@ -87,7 +87,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
87
87
|
it 'does not create body eleents for an empty definition' do
|
88
88
|
sexp = s(:module,
|
89
89
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))),
|
90
|
-
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
|
90
|
+
s(:bodystmt, s(:stmts, s(:void_stmt)), nil, nil, nil))
|
91
91
|
result = processor.process sexp
|
92
92
|
result.must_equal s(:module, :Foo)
|
93
93
|
end
|
@@ -95,7 +95,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
95
95
|
it 'creates a single body element for a definition with one statement' do
|
96
96
|
sexp = s(:module,
|
97
97
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))),
|
98
|
-
s(:bodystmt, s(s(:foo)), nil, nil, nil))
|
98
|
+
s(:bodystmt, s(:stmts, 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
|
@@ -103,7 +103,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
103
103
|
it 'creates multiple body elements for a definition with more than one statement' do
|
104
104
|
sexp = s(:module,
|
105
105
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))),
|
106
|
-
s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
|
106
|
+
s(:bodystmt, s(:stmts, 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
|
@@ -113,7 +113,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
113
113
|
it 'does not create body eleents for an empty definition' do
|
114
114
|
sexp = s(:class,
|
115
115
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
|
116
|
-
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
|
116
|
+
s(:bodystmt, s(:stmts, s(:void_stmt)), nil, nil, nil))
|
117
117
|
result = processor.process sexp
|
118
118
|
result.must_equal s(:class, :Foo, nil)
|
119
119
|
end
|
@@ -121,7 +121,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
121
121
|
it 'creates a single body element for a definition with one statement' do
|
122
122
|
sexp = s(:class,
|
123
123
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
|
124
|
-
s(:bodystmt, s(s(:foo)), nil, nil, nil))
|
124
|
+
s(:bodystmt, s(:stmts, 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
|
@@ -129,7 +129,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
129
129
|
it 'creates multiple body elements for a definition with more than one statement' do
|
130
130
|
sexp = s(:class,
|
131
131
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))), nil,
|
132
|
-
s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
|
132
|
+
s(:bodystmt, s(:stmts, 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
|
@@ -138,23 +138,23 @@ describe RipperRubyParser::SexpProcessor do
|
|
138
138
|
sexp = s(:class,
|
139
139
|
s(:const_ref, s(:@const, 'Foo', s(1, 13))),
|
140
140
|
s(:var_ref, s(:@const, 'Bar', s(1, 12))),
|
141
|
-
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
|
141
|
+
s(:bodystmt, s(:stmts, 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
147
|
describe 'for a :bodystmt sexp' do
|
148
|
-
it 'creates a :
|
149
|
-
sexp = s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil)
|
148
|
+
it 'creates a :block sexp when multiple statements are present' do
|
149
|
+
sexp = s(:bodystmt, s(:stmts, s(:foo), s(:bar)), nil, nil, nil)
|
150
150
|
result = processor.process sexp
|
151
|
-
result.must_equal s(
|
151
|
+
result.must_equal s(:block, s(:foo_p), s(:bar_p))
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'removes nested :void_stmt sexps' do
|
155
|
-
sexp = s(:bodystmt, s(s(:void_stmt), s(:foo)), nil, nil, nil)
|
155
|
+
sexp = s(:bodystmt, s(:stmts, s(:void_stmt), s(:foo)), nil, nil, nil)
|
156
156
|
result = processor.process sexp
|
157
|
-
result.must_equal s(
|
157
|
+
result.must_equal s(:foo_p)
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -163,7 +163,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
163
163
|
sexp = s(:def,
|
164
164
|
s(:@ident, 'foo', s(1, 4)),
|
165
165
|
s(:params, nil, nil, nil, nil, nil),
|
166
|
-
s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
|
166
|
+
s(:bodystmt, s(:stmts, s(:void_stmt)), nil, nil, nil))
|
167
167
|
result = processor.process sexp
|
168
168
|
result.must_equal s(:defn, :foo, s(:args), s(:nil))
|
169
169
|
end
|
@@ -177,6 +177,27 @@ describe RipperRubyParser::SexpProcessor do
|
|
177
177
|
result.must_equal s(:args, s(:lvar, :bar))
|
178
178
|
end
|
179
179
|
end
|
180
|
+
|
181
|
+
describe 'with a ruby 2.4-style doublesplat argument' do
|
182
|
+
it 'creates :lvar sexps' do
|
183
|
+
sexp = s(:params,
|
184
|
+
nil, nil, nil, nil, nil,
|
185
|
+
s(:@ident, 'bar', s(1, 8)),
|
186
|
+
nil)
|
187
|
+
result = processor.process sexp
|
188
|
+
result.must_equal s(:args, s(:dsplat, s(:lvar, :bar)))
|
189
|
+
end
|
190
|
+
end
|
191
|
+
describe 'with a ruby 2.5-style kwrest argument' do
|
192
|
+
it 'creates :lvar sexps' do
|
193
|
+
sexp = s(:params,
|
194
|
+
nil, nil, nil, nil, nil,
|
195
|
+
s(:kwrest_param, s(:@ident, 'bar', s(1, 8))),
|
196
|
+
nil)
|
197
|
+
result = processor.process sexp
|
198
|
+
result.must_equal s(:args, s(:dsplat, s(:lvar, :bar)))
|
199
|
+
end
|
200
|
+
end
|
180
201
|
end
|
181
202
|
|
182
203
|
describe 'for an :assign sexp' do
|
@@ -201,7 +222,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
201
222
|
it 'creates an :iter sexp' do
|
202
223
|
sexp = s(:method_add_block,
|
203
224
|
s(:call, s(:foo), :".", s(:@ident, 'baz', s(1, 2))),
|
204
|
-
s(:brace_block, nil, s(s(:bar))))
|
225
|
+
s(:brace_block, nil, s(:stmts, s(:bar))))
|
205
226
|
result = processor.process sexp
|
206
227
|
result.must_equal s(:iter,
|
207
228
|
s(:call, s(:foo_p), :baz), 0,
|
@@ -216,7 +237,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
216
237
|
s(:block_var,
|
217
238
|
s(:params, s(s(:@ident, 'i', s(1, 6))), nil, nil, nil, nil),
|
218
239
|
nil),
|
219
|
-
s(s(:bar))))
|
240
|
+
s(:stmts, s(:bar))))
|
220
241
|
result = processor.process sexp
|
221
242
|
result.must_equal s(:iter,
|
222
243
|
s(:call, s(:foo_p), :baz),
|
@@ -229,7 +250,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
229
250
|
describe 'for an :if sexp' do
|
230
251
|
describe 'with a single statement in the if body' do
|
231
252
|
it 'uses the statement sexp as the body' do
|
232
|
-
sexp = s(:if, s(:foo), s(s(:bar)), nil)
|
253
|
+
sexp = s(:if, s(:foo), s(:stmts, s(:bar)), nil)
|
233
254
|
result = processor.process sexp
|
234
255
|
result.must_equal s(:if, s(:foo_p), s(:bar_p), nil)
|
235
256
|
end
|
@@ -237,7 +258,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
237
258
|
|
238
259
|
describe 'with multiple statements in the if body' do
|
239
260
|
it 'uses a block containing the statement sexps as the body' do
|
240
|
-
sexp = s(:if, s(:foo), s(s(:bar), s(:baz)), nil)
|
261
|
+
sexp = s(:if, s(:foo), s(:stmts, s(:bar), s(:baz)), nil)
|
241
262
|
result = processor.process sexp
|
242
263
|
result.must_equal s(:if, s(:foo_p), s(:block, s(:bar_p), s(:baz_p)), nil)
|
243
264
|
end
|
@@ -246,7 +267,7 @@ describe RipperRubyParser::SexpProcessor do
|
|
246
267
|
|
247
268
|
describe 'for an :array sexp' do
|
248
269
|
it 'pulls up the element sexps' do
|
249
|
-
sexp = s(:array, s(s(:foo), s(:bar), s(:baz)))
|
270
|
+
sexp = s(:array, s(:words, s(:foo), s(:bar), s(:baz)))
|
250
271
|
result = processor.process sexp
|
251
272
|
result.must_equal s(:array, s(:foo_p), s(:bar_p), s(:baz_p))
|
252
273
|
end
|
@@ -264,9 +285,9 @@ describe RipperRubyParser::SexpProcessor do
|
|
264
285
|
|
265
286
|
describe 'for a :when sexp' do
|
266
287
|
it 'turns nested :when clauses into a list' do
|
267
|
-
sexp = s(:when, s(s(:foo)), s(s(:bar)),
|
268
|
-
s(:when, s(s(:foo)), s(s(:bar)),
|
269
|
-
s(:when, s(s(:foo)), s(s(:bar)), nil)))
|
288
|
+
sexp = s(:when, s(:args, s(:foo)), s(:stmts, s(:bar)),
|
289
|
+
s(:when, s(:args, s(:foo)), s(:stmts, s(:bar)),
|
290
|
+
s(:when, s(:args, s(:foo)), s(:stmts, s(:bar)), nil)))
|
270
291
|
result = processor.process sexp
|
271
292
|
result.must_equal s(s(:when, s(:array, s(:foo_p)), s(:bar_p)),
|
272
293
|
s(:when, s(:array, s(:foo_p)), s(:bar_p)),
|
@@ -289,24 +310,4 @@ describe RipperRubyParser::SexpProcessor do
|
|
289
310
|
result.must_equal :Foo
|
290
311
|
end
|
291
312
|
end
|
292
|
-
|
293
|
-
describe '#trickle_up_line_numbers' do
|
294
|
-
it 'works through several nested levels' do
|
295
|
-
inner = s(:foo)
|
296
|
-
outer = s(:bar, s(:baz, s(:qux, inner)))
|
297
|
-
outer.line = 42
|
298
|
-
processor.send :trickle_down_line_numbers, outer
|
299
|
-
inner.line.must_equal 42
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
describe '#trickle_down_line_numbers' do
|
304
|
-
it 'works through several nested levels' do
|
305
|
-
inner = s(:foo)
|
306
|
-
inner.line = 42
|
307
|
-
outer = s(:bar, s(:baz, s(:qux, inner)))
|
308
|
-
processor.send :trickle_up_line_numbers, outer
|
309
|
-
outer.line.must_equal 42
|
310
|
-
end
|
311
|
-
end
|
312
313
|
end
|