ripper_ruby_parser 1.1.1 → 1.1.2
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 +19 -0
- data/Rakefile +2 -2
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +55 -4
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +20 -13
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +27 -12
- data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +25 -12
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +4 -2
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +19 -15
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +25 -11
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +12 -4
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +8 -4
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +1 -5
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/lib/ripper_ruby_parser.rb +2 -2
- data/test/end_to_end/comments_test.rb +4 -4
- data/test/end_to_end/comparison_test.rb +15 -15
- data/test/end_to_end/error_conditions_test.rb +16 -16
- data/test/end_to_end/lib_comparison_test.rb +3 -3
- data/test/end_to_end/line_numbering_test.rb +4 -4
- data/test/end_to_end/samples_comparison_test.rb +4 -4
- data/test/end_to_end/test_comparison_test.rb +3 -3
- data/test/pt_testcase/pt_test.rb +4 -4
- data/test/test_helper.rb +1 -1
- data/test/unit/commenting_ripper_parser_test.rb +33 -33
- data/test/unit/parser_assignment_test.rb +30 -30
- data/test/unit/parser_blocks_test.rb +83 -65
- data/test/unit/parser_conditionals_test.rb +96 -64
- data/test/unit/parser_literals_test.rb +308 -212
- data/test/unit/parser_loops_test.rb +85 -15
- data/test/unit/parser_method_calls_test.rb +100 -41
- data/test/unit/parser_operators_test.rb +60 -28
- data/test/unit/parser_test.rb +435 -410
- data/test/unit/sexp_processor_test.rb +82 -82
- data/test/unit/version_test.rb +1 -1
- metadata +2 -2
@@ -1,51 +1,121 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
|
4
|
+
describe '#parse' do
|
5
|
+
describe 'for the while statement' do
|
6
|
+
it 'works with do' do
|
7
|
+
'while foo do; bar; end'.
|
8
|
+
must_be_parsed_as s(:while,
|
9
|
+
s(:call, nil, :foo),
|
10
|
+
s(:call, nil, :bar), true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'works without do' do
|
14
|
+
'while foo; bar; end'.
|
15
|
+
must_be_parsed_as s(:while,
|
16
|
+
s(:call, nil, :foo),
|
17
|
+
s(:call, nil, :bar), true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'works in the single-line postfix case' do
|
21
|
+
'foo while bar'.
|
8
22
|
must_be_parsed_as s(:while,
|
9
23
|
s(:call, nil, :bar),
|
10
24
|
s(:call, nil, :foo), true)
|
11
25
|
end
|
12
26
|
|
13
|
-
it
|
14
|
-
|
27
|
+
it 'works in the block postfix case' do
|
28
|
+
'begin; foo; end while bar'.
|
15
29
|
must_be_parsed_as s(:while,
|
16
30
|
s(:call, nil, :bar),
|
17
31
|
s(:call, nil, :foo), false)
|
18
32
|
end
|
19
33
|
|
20
|
-
it
|
21
|
-
|
34
|
+
it 'handles a negative condition' do
|
35
|
+
'while not foo; bar; end'.
|
22
36
|
must_be_parsed_as s(:while,
|
23
37
|
s(:call, s(:call, nil, :foo), :!),
|
24
38
|
s(:call, nil, :bar), true)
|
25
39
|
end
|
26
40
|
|
27
|
-
it
|
28
|
-
|
41
|
+
it 'handles a negative condition in the postfix case' do
|
42
|
+
'foo while not bar'.
|
29
43
|
must_be_parsed_as s(:while,
|
30
44
|
s(:call, s(:call, nil, :bar), :!),
|
31
45
|
s(:call, nil, :foo), true)
|
32
46
|
end
|
47
|
+
|
48
|
+
it 'converts a negated match condition to :until' do
|
49
|
+
'while foo !~ bar; baz; end'.
|
50
|
+
must_be_parsed_as s(:until,
|
51
|
+
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
52
|
+
s(:call, nil, :baz), true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'converts a negated match condition to :until in the postfix case' do
|
56
|
+
'baz while foo !~ bar'.
|
57
|
+
must_be_parsed_as s(:until,
|
58
|
+
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
59
|
+
s(:call, nil, :baz), true)
|
60
|
+
end
|
33
61
|
end
|
34
62
|
|
35
|
-
describe
|
36
|
-
it
|
37
|
-
|
63
|
+
describe 'for the until statement' do
|
64
|
+
it 'works in the prefix block case with do' do
|
65
|
+
'until foo do; bar; end'.
|
66
|
+
must_be_parsed_as s(:until,
|
67
|
+
s(:call, nil, :foo),
|
68
|
+
s(:call, nil, :bar), true)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'works in the prefix block case without do' do
|
72
|
+
'until foo; bar; end'.
|
73
|
+
must_be_parsed_as s(:until,
|
74
|
+
s(:call, nil, :foo),
|
75
|
+
s(:call, nil, :bar), true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'works in the single-line postfix case' do
|
79
|
+
'foo until bar'.
|
80
|
+
must_be_parsed_as s(:until,
|
81
|
+
s(:call, nil, :bar),
|
82
|
+
s(:call, nil, :foo), true)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'works in the block postfix case' do
|
86
|
+
'begin; foo; end until bar'.
|
87
|
+
must_be_parsed_as s(:until,
|
88
|
+
s(:call, nil, :bar),
|
89
|
+
s(:call, nil, :foo), false)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'handles a negative condition' do
|
93
|
+
'until not foo; bar; end'.
|
38
94
|
must_be_parsed_as s(:until,
|
39
95
|
s(:call, s(:call, nil, :foo), :!),
|
40
96
|
s(:call, nil, :bar), true)
|
41
97
|
end
|
42
98
|
|
43
|
-
it
|
44
|
-
|
99
|
+
it 'handles a negative condition in the postfix case' do
|
100
|
+
'foo until not bar'.
|
45
101
|
must_be_parsed_as s(:until,
|
46
102
|
s(:call, s(:call, nil, :bar), :!),
|
47
103
|
s(:call, nil, :foo), true)
|
48
104
|
end
|
105
|
+
|
106
|
+
it 'converts a negated match condition to :while' do
|
107
|
+
'until foo !~ bar; baz; end'.
|
108
|
+
must_be_parsed_as s(:while,
|
109
|
+
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
110
|
+
s(:call, nil, :baz), true)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'converts a negated match condition to :while in the postfix case' do
|
114
|
+
'baz until foo !~ bar'.
|
115
|
+
must_be_parsed_as s(:while,
|
116
|
+
s(:call, s(:call, nil, :foo), :=~, s(:call, nil, :bar)),
|
117
|
+
s(:call, nil, :baz), true)
|
118
|
+
end
|
49
119
|
end
|
50
120
|
end
|
51
121
|
end
|
@@ -1,45 +1,45 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
|
4
|
+
describe '#parse' do
|
5
|
+
describe 'for method calls' do
|
6
|
+
describe 'without a receiver' do
|
7
|
+
it 'works without brackets' do
|
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
|
14
|
-
|
13
|
+
it 'works with brackets' do
|
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
|
20
|
-
|
19
|
+
it 'works with an empty parameter list and no brackets' do
|
20
|
+
'foo'.
|
21
21
|
must_be_parsed_as s(:call, nil, :foo)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
|
24
|
+
it 'works with brackets around an empty parameter list' do
|
25
|
+
'foo()'.
|
26
26
|
must_be_parsed_as s(:call, nil, :foo)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
|
29
|
+
it 'works for methods ending in a question mark' do
|
30
|
+
'foo?'.
|
31
31
|
must_be_parsed_as s(:call, nil, :foo?)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
|
34
|
+
it 'works with nested calls without brackets' do
|
35
|
+
'foo bar baz'.
|
36
36
|
must_be_parsed_as s(:call, nil, :foo,
|
37
37
|
s(:call, nil, :bar,
|
38
38
|
s(:call, nil, :baz)))
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
|
41
|
+
it 'works with a non-final splat argument' do
|
42
|
+
'foo(bar, *baz, qux)'.
|
43
43
|
must_be_parsed_as s(:call,
|
44
44
|
nil,
|
45
45
|
:foo,
|
@@ -48,8 +48,8 @@ describe RipperRubyParser::Parser do
|
|
48
48
|
s(:call, nil, :qux))
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
|
51
|
+
it 'works with a splat argument followed by several regular arguments' do
|
52
|
+
'foo(bar, *baz, qux, quuz)'.
|
53
53
|
must_be_parsed_as s(:call,
|
54
54
|
nil,
|
55
55
|
:foo,
|
@@ -58,27 +58,68 @@ describe RipperRubyParser::Parser do
|
|
58
58
|
s(:call, nil, :qux),
|
59
59
|
s(:call, nil, :quuz))
|
60
60
|
end
|
61
|
+
|
62
|
+
it 'works with a named argument' do
|
63
|
+
'foo(bar, baz: qux)'.
|
64
|
+
must_be_parsed_as s(:call,
|
65
|
+
nil,
|
66
|
+
:foo,
|
67
|
+
s(:call, nil, :bar),
|
68
|
+
s(:hash, s(:lit, :baz), s(:call, nil, :qux)))
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'works with several named arguments' do
|
72
|
+
'foo(bar, baz: qux, quux: quuz)'.
|
73
|
+
must_be_parsed_as s(:call,
|
74
|
+
nil,
|
75
|
+
:foo,
|
76
|
+
s(:call, nil, :bar),
|
77
|
+
s(:hash,
|
78
|
+
s(:lit, :baz), s(:call, nil, :qux),
|
79
|
+
s(:lit, :quux), s(:call, nil, :quuz)))
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'works with a double splat argument' do
|
83
|
+
'foo(bar, **baz)'.
|
84
|
+
must_be_parsed_as s(:call,
|
85
|
+
nil,
|
86
|
+
:foo,
|
87
|
+
s(:call, nil, :bar),
|
88
|
+
s(:hash,
|
89
|
+
s(:kwsplat, s(:call, nil, :baz))))
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'works with a named argument followed by a double splat argument' do
|
93
|
+
'foo(bar, baz: qux, **quuz)'.
|
94
|
+
must_be_parsed_as s(:call,
|
95
|
+
nil,
|
96
|
+
:foo,
|
97
|
+
s(:call, nil, :bar),
|
98
|
+
s(:hash,
|
99
|
+
s(:lit, :baz), s(:call, nil, :qux),
|
100
|
+
s(:kwsplat, s(:call, nil, :quuz))))
|
101
|
+
end
|
61
102
|
end
|
62
103
|
|
63
|
-
describe
|
64
|
-
it
|
65
|
-
|
104
|
+
describe 'with a receiver' do
|
105
|
+
it 'works without brackets' do
|
106
|
+
'foo.bar baz'.
|
66
107
|
must_be_parsed_as s(:call,
|
67
108
|
s(:call, nil, :foo),
|
68
109
|
:bar,
|
69
110
|
s(:call, nil, :baz))
|
70
111
|
end
|
71
112
|
|
72
|
-
it
|
73
|
-
|
113
|
+
it 'works with brackets' do
|
114
|
+
'foo.bar(baz)'.
|
74
115
|
must_be_parsed_as s(:call,
|
75
116
|
s(:call, nil, :foo),
|
76
117
|
:bar,
|
77
118
|
s(:call, nil, :baz))
|
78
119
|
end
|
79
120
|
|
80
|
-
it
|
81
|
-
|
121
|
+
it 'works with brackets around a call with no brackets' do
|
122
|
+
'foo.bar(baz qux)'.
|
82
123
|
must_be_parsed_as s(:call,
|
83
124
|
s(:call, nil, :foo),
|
84
125
|
:bar,
|
@@ -86,8 +127,8 @@ describe RipperRubyParser::Parser do
|
|
86
127
|
s(:call, nil, :qux)))
|
87
128
|
end
|
88
129
|
|
89
|
-
it
|
90
|
-
|
130
|
+
it 'works with nested calls without brackets' do
|
131
|
+
'foo.bar baz qux'.
|
91
132
|
must_be_parsed_as s(:call,
|
92
133
|
s(:call, nil, :foo),
|
93
134
|
:bar,
|
@@ -96,9 +137,27 @@ describe RipperRubyParser::Parser do
|
|
96
137
|
end
|
97
138
|
end
|
98
139
|
|
99
|
-
describe
|
100
|
-
|
101
|
-
|
140
|
+
describe 'safe call' do
|
141
|
+
before do
|
142
|
+
skip 'This is not valid syntax below Ruby 2.3' if RUBY_VERSION < '2.3.0'
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'works without arguments' do
|
146
|
+
'foo&.bar'.must_be_parsed_as s(:safe_call, s(:call, nil, :foo), :bar)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'works with arguments' do
|
150
|
+
'foo&.bar baz'.
|
151
|
+
must_be_parsed_as s(:safe_call,
|
152
|
+
s(:call, nil, :foo),
|
153
|
+
:bar,
|
154
|
+
s(:call, nil, :baz))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'with blocks' do
|
159
|
+
it 'works for a do block' do
|
160
|
+
'foo.bar do baz; end'.
|
102
161
|
must_be_parsed_as s(:iter,
|
103
162
|
s(:call,
|
104
163
|
s(:call, nil, :foo),
|
@@ -107,8 +166,8 @@ describe RipperRubyParser::Parser do
|
|
107
166
|
s(:call, nil, :baz))
|
108
167
|
end
|
109
168
|
|
110
|
-
it
|
111
|
-
|
169
|
+
it 'works for a do block with several statements' do
|
170
|
+
'foo.bar do baz; qux; end'.
|
112
171
|
must_be_parsed_as s(:iter,
|
113
172
|
s(:call,
|
114
173
|
s(:call, nil, :foo),
|
@@ -121,25 +180,25 @@ describe RipperRubyParser::Parser do
|
|
121
180
|
end
|
122
181
|
end
|
123
182
|
|
124
|
-
describe
|
125
|
-
specify {
|
183
|
+
describe 'for calls to super' do
|
184
|
+
specify { 'super'.must_be_parsed_as s(:zsuper) }
|
126
185
|
specify do
|
127
|
-
|
186
|
+
'super foo'.must_be_parsed_as s(:super,
|
128
187
|
s(:call, nil, :foo))
|
129
188
|
end
|
130
189
|
specify do
|
131
|
-
|
190
|
+
'super foo, bar'.must_be_parsed_as s(:super,
|
132
191
|
s(:call, nil, :foo),
|
133
192
|
s(:call, nil, :bar))
|
134
193
|
end
|
135
194
|
specify do
|
136
|
-
|
195
|
+
'super foo, *bar'.must_be_parsed_as s(:super,
|
137
196
|
s(:call, nil, :foo),
|
138
197
|
s(:splat,
|
139
198
|
s(:call, nil, :bar)))
|
140
199
|
end
|
141
200
|
specify do
|
142
|
-
|
201
|
+
'super foo, *bar, &baz'.
|
143
202
|
must_be_parsed_as s(:super,
|
144
203
|
s(:call, nil, :foo),
|
145
204
|
s(:splat, s(:call, nil, :bar)),
|
@@ -147,8 +206,8 @@ describe RipperRubyParser::Parser do
|
|
147
206
|
end
|
148
207
|
end
|
149
208
|
|
150
|
-
it
|
151
|
-
|
209
|
+
it 'handles calling a proc' do
|
210
|
+
'foo.()'.
|
152
211
|
must_be_parsed_as s(:call, s(:call, nil, :foo), :call)
|
153
212
|
end
|
154
213
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe RipperRubyParser::Parser do
|
4
|
-
describe
|
5
|
-
describe
|
4
|
+
describe '#parse' do
|
5
|
+
describe 'for negated operators' do
|
6
6
|
specify do
|
7
|
-
|
7
|
+
'foo !~ bar'.must_be_parsed_as s(:not,
|
8
8
|
s(:call,
|
9
9
|
s(:call, nil, :foo),
|
10
10
|
:=~,
|
@@ -12,16 +12,16 @@ describe RipperRubyParser::Parser do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
16
|
-
it
|
17
|
-
|
15
|
+
describe 'for boolean operators' do
|
16
|
+
it 'handles :and' do
|
17
|
+
'foo and bar'.
|
18
18
|
must_be_parsed_as s(:and,
|
19
19
|
s(:call, nil, :foo),
|
20
20
|
s(:call, nil, :bar))
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
|
23
|
+
it 'handles double :and' do
|
24
|
+
'foo and bar and baz'.
|
25
25
|
must_be_parsed_as s(:and,
|
26
26
|
s(:call, nil, :foo),
|
27
27
|
s(:and,
|
@@ -29,15 +29,15 @@ describe RipperRubyParser::Parser do
|
|
29
29
|
s(:call, nil, :baz)))
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
|
32
|
+
it 'handles :or' do
|
33
|
+
'foo or bar'.
|
34
34
|
must_be_parsed_as s(:or,
|
35
35
|
s(:call, nil, :foo),
|
36
36
|
s(:call, nil, :bar))
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
|
39
|
+
it 'handles double :or' do
|
40
|
+
'foo or bar or baz'.
|
41
41
|
must_be_parsed_as s(:or,
|
42
42
|
s(:call, nil, :foo),
|
43
43
|
s(:or,
|
@@ -45,8 +45,8 @@ describe RipperRubyParser::Parser do
|
|
45
45
|
s(:call, nil, :baz)))
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
49
|
-
|
48
|
+
it 'handles :or after :and' do
|
49
|
+
'foo and bar or baz'.
|
50
50
|
must_be_parsed_as s(:or,
|
51
51
|
s(:and,
|
52
52
|
s(:call, nil, :foo),
|
@@ -54,8 +54,8 @@ describe RipperRubyParser::Parser do
|
|
54
54
|
s(:call, nil, :baz))
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
|
57
|
+
it 'handles :and after :or' do
|
58
|
+
'foo or bar and baz'.
|
59
59
|
must_be_parsed_as s(:and,
|
60
60
|
s(:or,
|
61
61
|
s(:call, nil, :foo),
|
@@ -63,15 +63,15 @@ describe RipperRubyParser::Parser do
|
|
63
63
|
s(:call, nil, :baz))
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
|
66
|
+
it 'converts :&& to :and' do
|
67
|
+
'foo && bar'.
|
68
68
|
must_be_parsed_as s(:and,
|
69
69
|
s(:call, nil, :foo),
|
70
70
|
s(:call, nil, :bar))
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
|
73
|
+
it 'handles :|| after :&&' do
|
74
|
+
'foo && bar || baz'.
|
75
75
|
must_be_parsed_as s(:or,
|
76
76
|
s(:and,
|
77
77
|
s(:call, nil, :foo),
|
@@ -79,8 +79,8 @@ describe RipperRubyParser::Parser do
|
|
79
79
|
s(:call, nil, :baz))
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
83
|
-
|
82
|
+
it 'handles :&& after :||' do
|
83
|
+
'foo || bar && baz'.
|
84
84
|
must_be_parsed_as s(:or,
|
85
85
|
s(:call, nil, :foo),
|
86
86
|
s(:and,
|
@@ -88,8 +88,8 @@ describe RipperRubyParser::Parser do
|
|
88
88
|
s(:call, nil, :baz)))
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
92
|
-
|
91
|
+
it 'handles bracketed :||' do
|
92
|
+
'(foo || bar) || baz'.
|
93
93
|
must_be_parsed_as s(:or,
|
94
94
|
s(:or,
|
95
95
|
s(:call, nil, :foo),
|
@@ -97,15 +97,15 @@ describe RipperRubyParser::Parser do
|
|
97
97
|
s(:call, nil, :baz))
|
98
98
|
end
|
99
99
|
|
100
|
-
it
|
101
|
-
|
100
|
+
it 'converts :|| to :or' do
|
101
|
+
'foo || bar'.
|
102
102
|
must_be_parsed_as s(:or,
|
103
103
|
s(:call, nil, :foo),
|
104
104
|
s(:call, nil, :bar))
|
105
105
|
end
|
106
106
|
|
107
|
-
it
|
108
|
-
|
107
|
+
it 'handles triple :and' do
|
108
|
+
'foo and bar and baz and qux'.
|
109
109
|
must_be_parsed_as s(:and,
|
110
110
|
s(:call, nil, :foo),
|
111
111
|
s(:and,
|
@@ -115,5 +115,37 @@ describe RipperRubyParser::Parser do
|
|
115
115
|
s(:call, nil, :qux))))
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
describe 'for unary numerical operators' do
|
120
|
+
it 'handles unary minus with an integer literal' do
|
121
|
+
'- 1'.must_be_parsed_as s(:call, s(:lit, 1), :-@)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'handles unary minus with a float literal' do
|
125
|
+
'- 3.14'.must_be_parsed_as s(:call, s(:lit, 3.14), :-@)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'handles unary minus with a non-literal' do
|
129
|
+
'-foo'.
|
130
|
+
must_be_parsed_as s(:call,
|
131
|
+
s(:call, nil, :foo),
|
132
|
+
:-@)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'handles unary minus with a negative number literal' do
|
136
|
+
'- -1'.must_be_parsed_as s(:call, s(:lit, -1), :-@)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'handles unary plus with a number literal' do
|
140
|
+
'+ 1'.must_be_parsed_as s(:call, s(:lit, 1), :+@)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'handles unary plus with a non-literal' do
|
144
|
+
'+foo'.
|
145
|
+
must_be_parsed_as s(:call,
|
146
|
+
s(:call, nil, :foo),
|
147
|
+
:+@)
|
148
|
+
end
|
149
|
+
end
|
118
150
|
end
|
119
151
|
end
|