-
Notifications
You must be signed in to change notification settings - Fork 6
/
parser_method_calls_test.rb
151 lines (134 loc) · 5.23 KB
/
parser_method_calls_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
describe RipperRubyParser::Parser do
describe "#parse" do
describe "for method calls" do
describe "without a receiver" do
it "works without brackets" do
"foo bar".
must_be_parsed_as s(:call, nil, :foo,
s(:call, nil, :bar))
end
it "works with brackets" do
"foo(bar)".
must_be_parsed_as s(:call, nil, :foo,
s(:call, nil, :bar))
end
it "works with an empty parameter list and no brackets" do
"foo".
must_be_parsed_as s(:call, nil, :foo)
end
it "works with brackets around an empty parameter list" do
"foo()".
must_be_parsed_as s(:call, nil, :foo)
end
it "works for methods ending in a question mark" do
"foo?".
must_be_parsed_as s(:call, nil, :foo?)
end
it "works with nested calls without brackets" do
"foo bar baz".
must_be_parsed_as s(:call, nil, :foo,
s(:call, nil, :bar,
s(:call, nil, :baz)))
end
it "works with a non-final splat argument" do
"foo(bar, *baz, qux)".
must_be_parsed_as s(:call,
nil,
:foo,
s(:call, nil, :bar),
s(:splat, s(:call, nil, :baz)),
s(:call, nil, :qux))
end
it "works with a splat argument followed by several regular arguments" do
"foo(bar, *baz, qux, quuz)".
must_be_parsed_as s(:call,
nil,
:foo,
s(:call, nil, :bar),
s(:splat, s(:call, nil, :baz)),
s(:call, nil, :qux),
s(:call, nil, :quuz))
end
end
describe "with a receiver" do
it "works without brackets" do
"foo.bar baz".
must_be_parsed_as s(:call,
s(:call, nil, :foo),
:bar,
s(:call, nil, :baz))
end
it "works with brackets" do
"foo.bar(baz)".
must_be_parsed_as s(:call,
s(:call, nil, :foo),
:bar,
s(:call, nil, :baz))
end
it "works with brackets around a call with no brackets" do
"foo.bar(baz qux)".
must_be_parsed_as s(:call,
s(:call, nil, :foo),
:bar,
s(:call, nil, :baz,
s(:call, nil, :qux)))
end
it "works with nested calls without brackets" do
"foo.bar baz qux".
must_be_parsed_as s(:call,
s(:call, nil, :foo),
:bar,
s(:call, nil, :baz,
s(:call, nil, :qux)))
end
end
describe "with blocks" do
it "works for a do block" do
"foo.bar do baz; end".
must_be_parsed_as s(:iter,
s(:call,
s(:call, nil, :foo),
:bar),
s(:args),
s(:call, nil, :baz))
end
it "works for a do block with several statements" do
"foo.bar do baz; qux; end".
must_be_parsed_as s(:iter,
s(:call,
s(:call, nil, :foo),
:bar),
s(:args),
s(:block,
s(:call, nil, :baz),
s(:call, nil, :qux)))
end
end
end
describe "for calls to super" do
specify { "super".must_be_parsed_as s(:zsuper) }
specify { "super foo".must_be_parsed_as s(:super,
s(:call, nil, :foo)) }
specify {
"super foo, bar".must_be_parsed_as s(:super,
s(:call, nil, :foo),
s(:call, nil, :bar)) }
specify {
"super foo, *bar".must_be_parsed_as s(:super,
s(:call, nil, :foo),
s(:splat,
s(:call, nil, :bar))) }
specify {
"super foo, *bar, &baz".
must_be_parsed_as s(:super,
s(:call, nil, :foo),
s(:splat, s(:call, nil, :bar)),
s(:block_pass, s(:call, nil, :baz))) }
end
it "handles calling a proc" do
"foo.()".
must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
end
end
end