ripper_ruby_parser 1.7.2 → 1.10.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 +4 -4
- data/CHANGELOG.md +50 -0
- data/README.md +4 -4
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
- data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
- data/lib/ripper_ruby_parser/unescape.rb +63 -22
- data/lib/ripper_ruby_parser/version.rb +1 -1
- metadata +140 -79
- data/Rakefile +0 -33
- data/test/end_to_end/comments_test.rb +0 -59
- data/test/end_to_end/comparison_test.rb +0 -104
- data/test/end_to_end/lib_comparison_test.rb +0 -18
- data/test/end_to_end/line_numbering_test.rb +0 -31
- data/test/end_to_end/samples_comparison_test.rb +0 -13
- data/test/end_to_end/test_comparison_test.rb +0 -18
- data/test/pt_testcase/pt_test.rb +0 -44
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
- data/test/ripper_ruby_parser/parser_test.rb +0 -576
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
- data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
- data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
- data/test/ripper_ruby_parser/version_test.rb +0 -7
- data/test/samples/assignment.rb +0 -22
- data/test/samples/comments.rb +0 -13
- data/test/samples/conditionals.rb +0 -23
- data/test/samples/lambdas.rb +0 -5
- data/test/samples/loops.rb +0 -36
- data/test/samples/misc.rb +0 -285
- data/test/samples/number.rb +0 -9
- data/test/samples/operators.rb +0 -18
- data/test/samples/strings.rb +0 -147
- data/test/test_helper.rb +0 -111
@@ -1,209 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
describe RipperRubyParser::Parser do
|
6
|
-
describe "#parse" do
|
7
|
-
describe "for the while statement" do
|
8
|
-
it "works with do" do
|
9
|
-
_("while foo do; bar; end")
|
10
|
-
.must_be_parsed_as s(:while,
|
11
|
-
s(:call, nil, :foo),
|
12
|
-
s(:call, nil, :bar), true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "works without do" do
|
16
|
-
_("while foo; bar; end")
|
17
|
-
.must_be_parsed_as s(:while,
|
18
|
-
s(:call, nil, :foo),
|
19
|
-
s(:call, nil, :bar), true)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "works in the single-line postfix case" do
|
23
|
-
_("foo while bar")
|
24
|
-
.must_be_parsed_as s(:while,
|
25
|
-
s(:call, nil, :bar),
|
26
|
-
s(:call, nil, :foo), true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "works in the block postfix case" do
|
30
|
-
_("begin; foo; end while bar")
|
31
|
-
.must_be_parsed_as s(:while,
|
32
|
-
s(:call, nil, :bar),
|
33
|
-
s(:call, nil, :foo), false)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "handles a negative condition" do
|
37
|
-
_("while not foo; bar; end")
|
38
|
-
.must_be_parsed_as s(:while,
|
39
|
-
s(:call, s(:call, nil, :foo), :!),
|
40
|
-
s(:call, nil, :bar), true)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "handles a negative condition in the postfix case" do
|
44
|
-
_("foo while not bar")
|
45
|
-
.must_be_parsed_as s(:while,
|
46
|
-
s(:call, s(:call, nil, :bar), :!),
|
47
|
-
s(:call, nil, :foo), true)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "converts a negated match condition to :until" do
|
51
|
-
_("while foo !~ bar; baz; end")
|
52
|
-
.must_be_parsed_as s(:until,
|
53
|
-
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
54
|
-
s(:call, nil, :baz), true)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "converts a negated match condition to :until in the postfix case" do
|
58
|
-
_("baz while foo !~ bar")
|
59
|
-
.must_be_parsed_as s(:until,
|
60
|
-
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
61
|
-
s(:call, nil, :baz), true)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "cleans up begin..end block in condition" do
|
65
|
-
_("while begin foo end; bar; end")
|
66
|
-
.must_be_parsed_as s(:while,
|
67
|
-
s(:call, nil, :foo),
|
68
|
-
s(:call, nil, :bar), true)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "cleans up begin..end block in condition in the postfix case" do
|
72
|
-
_("foo while begin bar end")
|
73
|
-
.must_be_parsed_as s(:while,
|
74
|
-
s(:call, nil, :bar),
|
75
|
-
s(:call, nil, :foo), true)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "works with do and an empty body" do
|
79
|
-
_("while foo do; end")
|
80
|
-
.must_be_parsed_as s(:while,
|
81
|
-
s(:call, nil, :foo),
|
82
|
-
nil, true)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "works without do and with an empty body" do
|
86
|
-
_("while foo; end")
|
87
|
-
.must_be_parsed_as s(:while,
|
88
|
-
s(:call, nil, :foo),
|
89
|
-
nil, true)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "for the until statement" do
|
94
|
-
it "works in the prefix block case with do" do
|
95
|
-
_("until foo do; bar; end")
|
96
|
-
.must_be_parsed_as s(:until,
|
97
|
-
s(:call, nil, :foo),
|
98
|
-
s(:call, nil, :bar), true)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "works in the prefix block case without do" do
|
102
|
-
_("until foo; bar; end")
|
103
|
-
.must_be_parsed_as s(:until,
|
104
|
-
s(:call, nil, :foo),
|
105
|
-
s(:call, nil, :bar), true)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "works in the single-line postfix case" do
|
109
|
-
_("foo until bar")
|
110
|
-
.must_be_parsed_as s(:until,
|
111
|
-
s(:call, nil, :bar),
|
112
|
-
s(:call, nil, :foo), true)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "works in the block postfix case" do
|
116
|
-
_("begin; foo; end until bar")
|
117
|
-
.must_be_parsed_as s(:until,
|
118
|
-
s(:call, nil, :bar),
|
119
|
-
s(:call, nil, :foo), false)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "handles a negative condition" do
|
123
|
-
_("until not foo; bar; end")
|
124
|
-
.must_be_parsed_as s(:until,
|
125
|
-
s(:call, s(:call, nil, :foo), :!),
|
126
|
-
s(:call, nil, :bar), true)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "handles a negative condition in the postfix case" do
|
130
|
-
_("foo until not bar")
|
131
|
-
.must_be_parsed_as s(:until,
|
132
|
-
s(:call, s(:call, nil, :bar), :!),
|
133
|
-
s(:call, nil, :foo), true)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "converts a negated match condition to :while" do
|
137
|
-
_("until foo !~ bar; baz; end")
|
138
|
-
.must_be_parsed_as s(:while,
|
139
|
-
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
140
|
-
s(:call, nil, :baz), true)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "converts a negated match condition to :while in the postfix case" do
|
144
|
-
_("baz until foo !~ bar")
|
145
|
-
.must_be_parsed_as s(:while,
|
146
|
-
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
147
|
-
s(:call, nil, :baz), true)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "cleans up begin..end block in condition" do
|
151
|
-
_("until begin foo end; bar; end")
|
152
|
-
.must_be_parsed_as s(:until,
|
153
|
-
s(:call, nil, :foo),
|
154
|
-
s(:call, nil, :bar), true)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "cleans up begin..end block in condition in the postfix case" do
|
158
|
-
_("foo until begin bar end")
|
159
|
-
.must_be_parsed_as s(:until,
|
160
|
-
s(:call, nil, :bar),
|
161
|
-
s(:call, nil, :foo), true)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "for the for statement" do
|
166
|
-
it "works with do" do
|
167
|
-
_("for foo in bar do; baz; end")
|
168
|
-
.must_be_parsed_as s(:for,
|
169
|
-
s(:call, nil, :bar),
|
170
|
-
s(:lasgn, :foo),
|
171
|
-
s(:call, nil, :baz))
|
172
|
-
end
|
173
|
-
|
174
|
-
it "works without do" do
|
175
|
-
_("for foo in bar; baz; end")
|
176
|
-
.must_be_parsed_as s(:for,
|
177
|
-
s(:call, nil, :bar),
|
178
|
-
s(:lasgn, :foo),
|
179
|
-
s(:call, nil, :baz))
|
180
|
-
end
|
181
|
-
|
182
|
-
it "works with an empty body" do
|
183
|
-
_("for foo in bar; end")
|
184
|
-
.must_be_parsed_as s(:for,
|
185
|
-
s(:call, nil, :bar),
|
186
|
-
s(:lasgn, :foo))
|
187
|
-
end
|
188
|
-
|
189
|
-
it "works with explicit multiple assignment" do
|
190
|
-
_("for foo, bar in baz; end")
|
191
|
-
.must_be_parsed_as s(:for,
|
192
|
-
s(:call, nil, :baz),
|
193
|
-
s(:masgn,
|
194
|
-
s(:array,
|
195
|
-
s(:lasgn, :foo),
|
196
|
-
s(:lasgn, :bar))))
|
197
|
-
end
|
198
|
-
|
199
|
-
it "works with multiple assignment with trailing comma" do
|
200
|
-
_("for foo, in bar; end")
|
201
|
-
.must_be_parsed_as s(:for,
|
202
|
-
s(:call, nil, :bar),
|
203
|
-
s(:masgn,
|
204
|
-
s(:array,
|
205
|
-
s(:lasgn, :foo))))
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
describe RipperRubyParser::SexpHandlers::MethodCalls do
|
6
|
-
describe "when parsing with RipperRubyParser::Parser#parse" do
|
7
|
-
describe "for method calls" do
|
8
|
-
describe "without a receiver" do
|
9
|
-
it "works without parentheses" do
|
10
|
-
_("foo bar")
|
11
|
-
.must_be_parsed_as s(:call, nil, :foo,
|
12
|
-
s(:call, nil, :bar))
|
13
|
-
end
|
14
|
-
|
15
|
-
it "works with parentheses" do
|
16
|
-
_("foo(bar)")
|
17
|
-
.must_be_parsed_as s(:call, nil, :foo,
|
18
|
-
s(:call, nil, :bar))
|
19
|
-
end
|
20
|
-
|
21
|
-
it "works with an empty parameter list and no parentheses" do
|
22
|
-
_("foo")
|
23
|
-
.must_be_parsed_as s(:call, nil, :foo)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "works with parentheses around an empty parameter list" do
|
27
|
-
_("foo()")
|
28
|
-
.must_be_parsed_as s(:call, nil, :foo)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "works for methods ending in a question mark" do
|
32
|
-
_("foo?")
|
33
|
-
.must_be_parsed_as s(:call, nil, :foo?)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "works with nested calls without parentheses" do
|
37
|
-
_("foo bar baz")
|
38
|
-
.must_be_parsed_as s(:call, nil, :foo,
|
39
|
-
s(:call, nil, :bar,
|
40
|
-
s(:call, nil, :baz)))
|
41
|
-
end
|
42
|
-
|
43
|
-
it "works with a non-final splat argument" do
|
44
|
-
_("foo(bar, *baz, qux)")
|
45
|
-
.must_be_parsed_as s(:call,
|
46
|
-
nil,
|
47
|
-
:foo,
|
48
|
-
s(:call, nil, :bar),
|
49
|
-
s(:splat, s(:call, nil, :baz)),
|
50
|
-
s(:call, nil, :qux))
|
51
|
-
end
|
52
|
-
|
53
|
-
it "works with a splat argument followed by several regular arguments" do
|
54
|
-
_("foo(bar, *baz, qux, quuz)")
|
55
|
-
.must_be_parsed_as s(:call,
|
56
|
-
nil,
|
57
|
-
:foo,
|
58
|
-
s(:call, nil, :bar),
|
59
|
-
s(:splat, s(:call, nil, :baz)),
|
60
|
-
s(:call, nil, :qux),
|
61
|
-
s(:call, nil, :quuz))
|
62
|
-
end
|
63
|
-
|
64
|
-
it "works with a named argument" do
|
65
|
-
_("foo(bar, baz: qux)")
|
66
|
-
.must_be_parsed_as s(:call,
|
67
|
-
nil,
|
68
|
-
:foo,
|
69
|
-
s(:call, nil, :bar),
|
70
|
-
s(:hash, s(:lit, :baz), s(:call, nil, :qux)))
|
71
|
-
end
|
72
|
-
|
73
|
-
it "works with several named arguments" do
|
74
|
-
_("foo(bar, baz: qux, quux: quuz)")
|
75
|
-
.must_be_parsed_as s(:call,
|
76
|
-
nil,
|
77
|
-
:foo,
|
78
|
-
s(:call, nil, :bar),
|
79
|
-
s(:hash,
|
80
|
-
s(:lit, :baz), s(:call, nil, :qux),
|
81
|
-
s(:lit, :quux), s(:call, nil, :quuz)))
|
82
|
-
end
|
83
|
-
|
84
|
-
it "works with a double splat argument" do
|
85
|
-
_("foo(bar, **baz)")
|
86
|
-
.must_be_parsed_as s(:call,
|
87
|
-
nil,
|
88
|
-
:foo,
|
89
|
-
s(:call, nil, :bar),
|
90
|
-
s(:hash,
|
91
|
-
s(:kwsplat, s(:call, nil, :baz))))
|
92
|
-
end
|
93
|
-
|
94
|
-
it "works with a named argument followed by a double splat argument" do
|
95
|
-
_("foo(bar, baz: qux, **quuz)")
|
96
|
-
.must_be_parsed_as s(:call,
|
97
|
-
nil,
|
98
|
-
:foo,
|
99
|
-
s(:call, nil, :bar),
|
100
|
-
s(:hash,
|
101
|
-
s(:lit, :baz), s(:call, nil, :qux),
|
102
|
-
s(:kwsplat, s(:call, nil, :quuz))))
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "with a receiver" do
|
107
|
-
it "works without parentheses" do
|
108
|
-
_("foo.bar baz")
|
109
|
-
.must_be_parsed_as s(:call,
|
110
|
-
s(:call, nil, :foo),
|
111
|
-
:bar,
|
112
|
-
s(:call, nil, :baz))
|
113
|
-
end
|
114
|
-
|
115
|
-
it "works with parentheses" do
|
116
|
-
_("foo.bar(baz)")
|
117
|
-
.must_be_parsed_as s(:call,
|
118
|
-
s(:call, nil, :foo),
|
119
|
-
:bar,
|
120
|
-
s(:call, nil, :baz))
|
121
|
-
end
|
122
|
-
|
123
|
-
it "works with parentheses around a call with no parentheses" do
|
124
|
-
_("foo.bar(baz qux)")
|
125
|
-
.must_be_parsed_as s(:call,
|
126
|
-
s(:call, nil, :foo),
|
127
|
-
:bar,
|
128
|
-
s(:call, nil, :baz,
|
129
|
-
s(:call, nil, :qux)))
|
130
|
-
end
|
131
|
-
|
132
|
-
it "works with nested calls without parentheses" do
|
133
|
-
_("foo.bar baz qux")
|
134
|
-
.must_be_parsed_as s(:call,
|
135
|
-
s(:call, nil, :foo),
|
136
|
-
:bar,
|
137
|
-
s(:call, nil, :baz,
|
138
|
-
s(:call, nil, :qux)))
|
139
|
-
end
|
140
|
-
|
141
|
-
it "does not keep :begin around a method receiver" do
|
142
|
-
_("begin; foo; end.bar")
|
143
|
-
.must_be_parsed_as s(:call, s(:call, nil, :foo), :bar)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "for collection indexing" do
|
148
|
-
it "works in the simple case" do
|
149
|
-
_("foo[bar]")
|
150
|
-
.must_be_parsed_as s(:call,
|
151
|
-
s(:call, nil, :foo),
|
152
|
-
:[],
|
153
|
-
s(:call, nil, :bar))
|
154
|
-
end
|
155
|
-
|
156
|
-
it "works without any indexes" do
|
157
|
-
_("foo[]").must_be_parsed_as s(:call, s(:call, nil, :foo),
|
158
|
-
:[])
|
159
|
-
end
|
160
|
-
|
161
|
-
it "works with self[]" do
|
162
|
-
_("self[foo]").must_be_parsed_as s(:call, s(:self), :[],
|
163
|
-
s(:call, nil, :foo))
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "safe call" do
|
168
|
-
it "works without arguments" do
|
169
|
-
_("foo&.bar").must_be_parsed_as s(:safe_call, s(:call, nil, :foo), :bar)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "works with arguments" do
|
173
|
-
_("foo&.bar baz")
|
174
|
-
.must_be_parsed_as s(:safe_call,
|
175
|
-
s(:call, nil, :foo),
|
176
|
-
:bar,
|
177
|
-
s(:call, nil, :baz))
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "with blocks" do
|
182
|
-
it "works for a do block" do
|
183
|
-
_("foo.bar do baz; end")
|
184
|
-
.must_be_parsed_as s(:iter,
|
185
|
-
s(:call,
|
186
|
-
s(:call, nil, :foo),
|
187
|
-
:bar),
|
188
|
-
0,
|
189
|
-
s(:call, nil, :baz))
|
190
|
-
end
|
191
|
-
|
192
|
-
it "works for a do block with several statements" do
|
193
|
-
_("foo.bar do baz; qux; end")
|
194
|
-
.must_be_parsed_as s(:iter,
|
195
|
-
s(:call,
|
196
|
-
s(:call, nil, :foo),
|
197
|
-
:bar),
|
198
|
-
0,
|
199
|
-
s(:block,
|
200
|
-
s(:call, nil, :baz),
|
201
|
-
s(:call, nil, :qux)))
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "for calls to super" do
|
207
|
-
specify { _("super").must_be_parsed_as s(:zsuper) }
|
208
|
-
specify do
|
209
|
-
_("super foo").must_be_parsed_as s(:super,
|
210
|
-
s(:call, nil, :foo))
|
211
|
-
end
|
212
|
-
specify do
|
213
|
-
_("super foo, bar").must_be_parsed_as s(:super,
|
214
|
-
s(:call, nil, :foo),
|
215
|
-
s(:call, nil, :bar))
|
216
|
-
end
|
217
|
-
specify do
|
218
|
-
_("super foo, *bar").must_be_parsed_as s(:super,
|
219
|
-
s(:call, nil, :foo),
|
220
|
-
s(:splat,
|
221
|
-
s(:call, nil, :bar)))
|
222
|
-
end
|
223
|
-
specify do
|
224
|
-
_("super foo, *bar, &baz")
|
225
|
-
.must_be_parsed_as s(:super,
|
226
|
-
s(:call, nil, :foo),
|
227
|
-
s(:splat, s(:call, nil, :bar)),
|
228
|
-
s(:block_pass, s(:call, nil, :baz)))
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
it "handles calling a proc" do
|
233
|
-
_("foo.()")
|
234
|
-
.must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|