ripper_ruby_parser 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -23
- data/Rakefile +12 -12
- data/lib/ripper_ruby_parser.rb +2 -2
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +9 -9
- data/lib/ripper_ruby_parser/parser.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers.rb +9 -9
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +3 -9
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +19 -24
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +14 -18
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_processor.rb +4 -4
- data/lib/ripper_ruby_parser/unescape.rb +11 -11
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/test/end_to_end/comments_test.rb +10 -10
- data/test/end_to_end/comparison_test.rb +28 -28
- data/test/end_to_end/lib_comparison_test.rb +6 -6
- data/test/end_to_end/line_numbering_test.rb +10 -10
- data/test/end_to_end/samples_comparison_test.rb +5 -5
- data/test/end_to_end/test_comparison_test.rb +6 -6
- data/test/pt_testcase/pt_test.rb +7 -7
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +163 -169
- data/test/ripper_ruby_parser/parser_test.rb +338 -338
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +475 -511
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +582 -564
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +469 -469
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +713 -724
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +155 -155
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +181 -181
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +337 -352
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +298 -298
- data/test/ripper_ruby_parser/sexp_processor_test.rb +119 -119
- data/test/ripper_ruby_parser/version_test.rb +2 -2
- data/test/samples/lambdas.rb +5 -0
- data/test/samples/misc.rb +3 -0
- data/test/samples/strings.rb +7 -0
- data/test/test_helper.rb +8 -6
- metadata +12 -10
@@ -1,208 +1,208 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
describe RipperRubyParser::Parser do
|
6
|
-
describe
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
|
10
|
-
must_be_parsed_as s(:while,
|
11
|
-
|
12
|
-
|
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
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
|
17
|
-
must_be_parsed_as s(:while,
|
18
|
-
|
19
|
-
|
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
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
|
24
|
-
must_be_parsed_as s(:while,
|
25
|
-
|
26
|
-
|
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
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
|
31
|
-
must_be_parsed_as s(:while,
|
32
|
-
|
33
|
-
|
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
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
|
38
|
-
must_be_parsed_as s(:while,
|
39
|
-
|
40
|
-
|
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
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
|
45
|
-
must_be_parsed_as s(:while,
|
46
|
-
|
47
|
-
|
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
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
|
52
|
-
must_be_parsed_as s(:until,
|
53
|
-
|
54
|
-
|
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
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
|
59
|
-
must_be_parsed_as s(:until,
|
60
|
-
|
61
|
-
|
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
62
|
end
|
63
63
|
|
64
|
-
it
|
65
|
-
|
66
|
-
must_be_parsed_as s(:while,
|
67
|
-
|
68
|
-
|
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
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
|
73
|
-
must_be_parsed_as s(:while,
|
74
|
-
|
75
|
-
|
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
76
|
end
|
77
77
|
|
78
|
-
it
|
79
|
-
|
80
|
-
must_be_parsed_as s(:while,
|
81
|
-
|
82
|
-
|
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
83
|
end
|
84
84
|
|
85
|
-
it
|
86
|
-
|
87
|
-
must_be_parsed_as s(:while,
|
88
|
-
|
89
|
-
|
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
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe
|
94
|
-
it
|
95
|
-
|
96
|
-
must_be_parsed_as s(:until,
|
97
|
-
|
98
|
-
|
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
99
|
end
|
100
100
|
|
101
|
-
it
|
102
|
-
|
103
|
-
must_be_parsed_as s(:until,
|
104
|
-
|
105
|
-
|
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
106
|
end
|
107
107
|
|
108
|
-
it
|
109
|
-
|
110
|
-
must_be_parsed_as s(:until,
|
111
|
-
|
112
|
-
|
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
113
|
end
|
114
114
|
|
115
|
-
it
|
116
|
-
|
117
|
-
must_be_parsed_as s(:until,
|
118
|
-
|
119
|
-
|
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
120
|
end
|
121
121
|
|
122
|
-
it
|
123
|
-
|
124
|
-
must_be_parsed_as s(:until,
|
125
|
-
|
126
|
-
|
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
127
|
end
|
128
128
|
|
129
|
-
it
|
130
|
-
|
131
|
-
must_be_parsed_as s(:until,
|
132
|
-
|
133
|
-
|
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
134
|
end
|
135
135
|
|
136
|
-
it
|
137
|
-
|
138
|
-
must_be_parsed_as s(:while,
|
139
|
-
|
140
|
-
|
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
141
|
end
|
142
142
|
|
143
|
-
it
|
144
|
-
|
145
|
-
must_be_parsed_as s(:while,
|
146
|
-
|
147
|
-
|
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
148
|
end
|
149
149
|
|
150
|
-
it
|
151
|
-
|
152
|
-
must_be_parsed_as s(:until,
|
153
|
-
|
154
|
-
|
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
155
|
end
|
156
156
|
|
157
|
-
it
|
158
|
-
|
159
|
-
must_be_parsed_as s(:until,
|
160
|
-
|
161
|
-
|
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
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
describe
|
166
|
-
it
|
167
|
-
|
168
|
-
must_be_parsed_as s(:for,
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
it
|
175
|
-
|
176
|
-
must_be_parsed_as s(:for,
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
it
|
183
|
-
|
184
|
-
must_be_parsed_as s(:for,
|
185
|
-
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
it
|
190
|
-
|
191
|
-
must_be_parsed_as s(:for,
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
it
|
200
|
-
|
201
|
-
must_be_parsed_as s(:for,
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
206
|
end
|
207
207
|
end
|
208
208
|
end
|
@@ -1,266 +1,266 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper.rb", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
describe RipperRubyParser::SexpHandlers::MethodCalls do
|
6
|
-
describe
|
7
|
-
describe
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
|
11
|
-
must_be_parsed_as s(:call, nil, :foo,
|
12
|
-
|
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
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
|
17
|
-
must_be_parsed_as s(:call, nil, :foo,
|
18
|
-
|
15
|
+
it "works with parentheses" do
|
16
|
+
_("foo(bar)")
|
17
|
+
.must_be_parsed_as s(:call, nil, :foo,
|
18
|
+
s(:call, nil, :bar))
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
|
23
|
-
must_be_parsed_as s(:call, nil, :foo)
|
21
|
+
it "works with an empty parameter list and no parentheses" do
|
22
|
+
_("foo")
|
23
|
+
.must_be_parsed_as s(:call, nil, :foo)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
|
28
|
-
must_be_parsed_as s(:call, nil, :foo)
|
26
|
+
it "works with parentheses around an empty parameter list" do
|
27
|
+
_("foo()")
|
28
|
+
.must_be_parsed_as s(:call, nil, :foo)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
|
33
|
-
must_be_parsed_as s(:call, nil, :foo?)
|
31
|
+
it "works for methods ending in a question mark" do
|
32
|
+
_("foo?")
|
33
|
+
.must_be_parsed_as s(:call, nil, :foo?)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
|
38
|
-
must_be_parsed_as s(:call, nil, :foo,
|
39
|
-
|
40
|
-
|
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
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
|
45
|
-
must_be_parsed_as s(:call,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
|
55
|
-
must_be_parsed_as s(:call,
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
62
|
end
|
63
63
|
|
64
|
-
it
|
65
|
-
|
66
|
-
must_be_parsed_as s(:call,
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
|
75
|
-
must_be_parsed_as s(:call,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
82
|
end
|
83
83
|
|
84
|
-
it
|
85
|
-
|
86
|
-
must_be_parsed_as s(:call,
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
92
|
end
|
93
93
|
|
94
|
-
it
|
95
|
-
|
96
|
-
must_be_parsed_as s(:call,
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe
|
107
|
-
it
|
108
|
-
|
109
|
-
must_be_parsed_as s(:call,
|
110
|
-
|
111
|
-
|
112
|
-
|
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
113
|
end
|
114
114
|
|
115
|
-
it
|
116
|
-
|
117
|
-
must_be_parsed_as s(:call,
|
118
|
-
|
119
|
-
|
120
|
-
|
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
121
|
end
|
122
122
|
|
123
|
-
it
|
124
|
-
|
125
|
-
must_be_parsed_as s(:call,
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
130
|
end
|
131
131
|
|
132
|
-
it
|
133
|
-
|
134
|
-
must_be_parsed_as s(:call,
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
139
|
end
|
140
140
|
|
141
|
-
it
|
142
|
-
|
143
|
-
must_be_parsed_as s(:call, s(:call, nil, :foo), :bar)
|
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
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
describe
|
148
|
-
it
|
149
|
-
|
150
|
-
must_be_parsed_as s(:call,
|
151
|
-
|
152
|
-
|
153
|
-
|
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
154
|
end
|
155
155
|
|
156
|
-
it
|
157
|
-
|
158
|
-
|
156
|
+
it "works without any indexes" do
|
157
|
+
_("foo[]").must_be_parsed_as s(:call, s(:call, nil, :foo),
|
158
|
+
:[])
|
159
159
|
end
|
160
160
|
|
161
|
-
it
|
162
|
-
|
163
|
-
|
161
|
+
it "works with self[]" do
|
162
|
+
_("self[foo]").must_be_parsed_as s(:call, s(:self), :[],
|
163
|
+
s(:call, nil, :foo))
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
describe
|
168
|
-
it
|
169
|
-
|
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
170
|
end
|
171
171
|
|
172
|
-
it
|
173
|
-
|
174
|
-
must_be_parsed_as s(:safe_call,
|
175
|
-
|
176
|
-
|
177
|
-
|
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
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
describe
|
182
|
-
it
|
183
|
-
|
184
|
-
must_be_parsed_as s(:iter,
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
190
|
end
|
191
191
|
|
192
|
-
it
|
193
|
-
|
194
|
-
must_be_parsed_as s(:iter,
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
202
|
end
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
describe
|
207
|
-
specify {
|
206
|
+
describe "for calls to super" do
|
207
|
+
specify { _("super").must_be_parsed_as s(:zsuper) }
|
208
208
|
specify do
|
209
|
-
|
210
|
-
|
209
|
+
_("super foo").must_be_parsed_as s(:super,
|
210
|
+
s(:call, nil, :foo))
|
211
211
|
end
|
212
212
|
specify do
|
213
|
-
|
214
|
-
|
215
|
-
|
213
|
+
_("super foo, bar").must_be_parsed_as s(:super,
|
214
|
+
s(:call, nil, :foo),
|
215
|
+
s(:call, nil, :bar))
|
216
216
|
end
|
217
217
|
specify do
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
218
|
+
_("super foo, *bar").must_be_parsed_as s(:super,
|
219
|
+
s(:call, nil, :foo),
|
220
|
+
s(:splat,
|
221
|
+
s(:call, nil, :bar)))
|
222
222
|
end
|
223
223
|
specify do
|
224
|
-
|
225
|
-
must_be_parsed_as s(:super,
|
226
|
-
|
227
|
-
|
228
|
-
|
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
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
-
it
|
233
|
-
|
234
|
-
must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
|
232
|
+
it "handles calling a proc" do
|
233
|
+
_("foo.()")
|
234
|
+
.must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
|
-
describe
|
238
|
+
describe "when processing a Sexp" do
|
239
239
|
let(:processor) { RipperRubyParser::SexpProcessor.new }
|
240
240
|
|
241
|
-
describe
|
242
|
-
it
|
241
|
+
describe "#process_command_call" do
|
242
|
+
it "processes a Ruby 2.5 style period Sexp" do
|
243
243
|
sexp = s(:call,
|
244
|
-
s(:vcall, s(:@ident,
|
244
|
+
s(:vcall, s(:@ident, "foo", s(1, 0))),
|
245
245
|
:'.',
|
246
|
-
s(:@ident,
|
247
|
-
processor.process(sexp).must_equal s(:call, s(:call, nil, :foo), :bar)
|
246
|
+
s(:@ident, "bar", s(1, 4)))
|
247
|
+
_(processor.process(sexp)).must_equal s(:call, s(:call, nil, :foo), :bar)
|
248
248
|
end
|
249
249
|
|
250
|
-
it
|
250
|
+
it "processes a Ruby 2.6 style period Sexp" do
|
251
251
|
sexp = s(:call,
|
252
|
-
s(:vcall, s(:@ident,
|
253
|
-
s(:@period,
|
254
|
-
s(:@ident,
|
255
|
-
processor.process(sexp).must_equal s(:call, s(:call, nil, :foo), :bar)
|
252
|
+
s(:vcall, s(:@ident, "foo", s(1, 0))),
|
253
|
+
s(:@period, ".", s(1, 3)),
|
254
|
+
s(:@ident, "bar", s(1, 4)))
|
255
|
+
_(processor.process(sexp)).must_equal s(:call, s(:call, nil, :foo), :bar)
|
256
256
|
end
|
257
257
|
|
258
|
-
it
|
258
|
+
it "raises an error for an unknown call operator" do
|
259
259
|
sexp = s(:call,
|
260
|
-
s(:vcall, s(:@ident,
|
260
|
+
s(:vcall, s(:@ident, "foo", s(1, 0))),
|
261
261
|
:'>.',
|
262
|
-
s(:@ident,
|
263
|
-
-> { processor.process(sexp) }.must_raise
|
262
|
+
s(:@ident, "bar", s(1, 4)))
|
263
|
+
_(-> { processor.process(sexp) }).must_raise KeyError
|
264
264
|
end
|
265
265
|
end
|
266
266
|
end
|