unparser 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +6 -0
- data/circle.yml +1 -1
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/reek.yml +1 -0
- data/lib/unparser/ast.rb +1 -1
- data/lib/unparser/ast/local_variable_scope.rb +1 -1
- data/lib/unparser/cli/differ.rb +1 -1
- data/lib/unparser/cli/source.rb +2 -0
- data/lib/unparser/constants.rb +0 -11
- data/lib/unparser/dsl.rb +1 -1
- data/lib/unparser/emitter.rb +41 -13
- data/lib/unparser/emitter/argument.rb +22 -34
- data/lib/unparser/emitter/assignment.rb +29 -6
- data/lib/unparser/emitter/begin.rb +10 -8
- data/lib/unparser/emitter/binary.rb +3 -12
- data/lib/unparser/emitter/block.rb +1 -0
- data/lib/unparser/emitter/case.rb +4 -2
- data/lib/unparser/emitter/cbase.rb +1 -0
- data/lib/unparser/emitter/class.rb +2 -1
- data/lib/unparser/emitter/def.rb +1 -1
- data/lib/unparser/emitter/defined.rb +2 -1
- data/lib/unparser/emitter/flipflop.rb +3 -2
- data/lib/unparser/emitter/flow_modifier.rb +22 -5
- data/lib/unparser/emitter/for.rb +2 -1
- data/lib/unparser/emitter/if.rb +10 -3
- data/lib/unparser/emitter/literal.rb +1 -0
- data/lib/unparser/emitter/literal/dynamic_body.rb +1 -1
- data/lib/unparser/emitter/literal/hash.rb +1 -1
- data/lib/unparser/emitter/literal/primitive.rb +83 -1
- data/lib/unparser/emitter/literal/range.rb +3 -2
- data/lib/unparser/emitter/match.rb +1 -0
- data/lib/unparser/emitter/module.rb +1 -1
- data/lib/unparser/emitter/op_assign.rb +3 -1
- data/lib/unparser/emitter/redo.rb +1 -0
- data/lib/unparser/emitter/repetition.rb +5 -3
- data/lib/unparser/emitter/resbody.rb +2 -2
- data/lib/unparser/emitter/rescue.rb +2 -1
- data/lib/unparser/emitter/retry.rb +1 -0
- data/lib/unparser/emitter/send.rb +13 -14
- data/lib/unparser/emitter/send/arguments.rb +1 -2
- data/lib/unparser/emitter/send/attribute_assignment.rb +3 -2
- data/lib/unparser/emitter/send/binary.rb +3 -2
- data/lib/unparser/emitter/send/index.rb +16 -2
- data/lib/unparser/emitter/send/regular.rb +2 -1
- data/lib/unparser/emitter/send/unary.rb +2 -1
- data/lib/unparser/emitter/splat.rb +2 -0
- data/lib/unparser/emitter/super.rb +2 -0
- data/lib/unparser/emitter/undef.rb +1 -0
- data/lib/unparser/emitter/variable.rb +4 -0
- data/lib/unparser/emitter/yield.rb +1 -0
- data/lib/unparser/preprocessor.rb +19 -12
- data/spec/integration/unparser/corpus_spec.rb +3 -2
- data/spec/integrations.yml +11 -1
- data/spec/unit/unparser_spec.rb +190 -183
- data/unparser.gemspec +2 -2
- metadata +5 -4
@@ -4,8 +4,9 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe 'Unparser on ruby corpus' do
|
6
6
|
before do
|
7
|
-
if RUBY_VERSION
|
8
|
-
|
7
|
+
if RUBY_VERSION < '2.1.0'
|
8
|
+
# Limits in encodings and complex/rational literals
|
9
|
+
skip 'Corpus test not active for < 2.1.0'
|
9
10
|
end
|
10
11
|
if RUBY_ENGINE == 'jruby'
|
11
12
|
skip 'Corpus test exhausts jruby heap space on travis'
|
data/spec/integrations.yml
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
- name: anima
|
3
|
+
repo_uri: 'https://github.com/mbj/anima.git'
|
4
|
+
exclude: []
|
5
|
+
- name: mutant
|
6
|
+
repo_uri: 'https://github.com/mbj/mutant.git'
|
7
|
+
exclude: []
|
8
|
+
- name: yaks
|
9
|
+
repo_uri: 'https://github.com/plexus/yaks.git'
|
10
|
+
exclude: []
|
3
11
|
- name: chassis
|
4
12
|
repo_uri: 'https://github.com/ahawkins/chassis.git'
|
5
13
|
exclude: []
|
@@ -18,6 +26,8 @@
|
|
18
26
|
- core/io/readpartial_spec.rb
|
19
27
|
- core/env/element_reference_spec.rb
|
20
28
|
- core/dir/pwd_spec.rb
|
29
|
+
- core/regexp/shared/new_ascii_8bit.rb
|
30
|
+
- core/regexp/encoding_spec.rb
|
21
31
|
- core/string/casecmp_spec.rb
|
22
32
|
- core/string/unpack/{b,c,h,m,u,w}_spec.rb
|
23
33
|
- core/string/unpack/b_spec.rb
|
data/spec/unit/unparser_spec.rb
CHANGED
@@ -46,10 +46,21 @@ describe Unparser do
|
|
46
46
|
Unparser.unparse(ast, comments).should eql(expected)
|
47
47
|
end
|
48
48
|
|
49
|
+
def self.assert_unterminated(expression)
|
50
|
+
assert_source(expression)
|
51
|
+
assert_source("(#{expression}).foo")
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.assert_terminated(expression, rubies = RUBIES)
|
55
|
+
assert_source(expression, rubies)
|
56
|
+
assert_source("foo(#{expression})", rubies)
|
57
|
+
assert_source("#{expression}.foo", rubies)
|
58
|
+
end
|
59
|
+
|
49
60
|
def self.assert_generates(ast_or_string, expected, versions = RUBIES)
|
50
61
|
with_versions(versions) do |parser|
|
51
62
|
it "should generate #{ast_or_string} as #{expected} under #{parser.inspect}" do
|
52
|
-
if ast_or_string.
|
63
|
+
if ast_or_string.is_a?(String)
|
53
64
|
expected = strip(expected)
|
54
65
|
assert_generates_from_string(parser, ast_or_string, expected)
|
55
66
|
else
|
@@ -88,11 +99,11 @@ describe Unparser do
|
|
88
99
|
end
|
89
100
|
|
90
101
|
context 'literal' do
|
91
|
-
context '
|
92
|
-
assert_generates
|
93
|
-
assert_generates s(:int, -1), '-1'
|
94
|
-
assert_source '1'
|
102
|
+
context 'int' do
|
103
|
+
assert_generates '-0', '0'
|
95
104
|
assert_source '++1'
|
105
|
+
assert_terminated '1'
|
106
|
+
assert_unterminated '-1'
|
96
107
|
assert_generates '0x1', '1'
|
97
108
|
assert_generates '1_000', '1000'
|
98
109
|
assert_generates '1e10', '10000000000.0'
|
@@ -100,20 +111,42 @@ describe Unparser do
|
|
100
111
|
assert_generates '-10e10000000000', '-Float::INFINITY'
|
101
112
|
end
|
102
113
|
|
114
|
+
context 'rational' do
|
115
|
+
assert_terminated '1r', %w(2.1)
|
116
|
+
assert_generates '1.0r', '1r', %w(2.1)
|
117
|
+
assert_generates '-0r', '0r', %w(2.1)
|
118
|
+
|
119
|
+
assert_terminated '1.5r', %w(2.1)
|
120
|
+
assert_terminated '1.3r', %w(2.1)
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'rational' do
|
124
|
+
%w(
|
125
|
+
5i
|
126
|
+
-5i
|
127
|
+
0.6i
|
128
|
+
-0.6i
|
129
|
+
1000000000000000000000000000000i
|
130
|
+
1ri
|
131
|
+
).each do |expression|
|
132
|
+
assert_terminated(expression, %w(2.1))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
103
136
|
context 'string' do
|
104
137
|
assert_generates '?c', '"c"'
|
105
|
-
assert_generates
|
106
|
-
assert_generates %
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
138
|
+
assert_generates '"foo" "bar"', '"foobar"'
|
139
|
+
assert_generates '%Q(foo"#{@bar})', '"foo\\"#{@bar}"'
|
140
|
+
assert_terminated '"\""'
|
141
|
+
assert_terminated '"foo#{1}bar"'
|
142
|
+
assert_terminated '"\"#{@a}"'
|
143
|
+
assert_terminated '"\\\\#{}"'
|
144
|
+
assert_terminated '"foo bar"'
|
145
|
+
assert_terminated '"foo\nbar"'
|
146
|
+
assert_terminated '"foo bar #{}"'
|
147
|
+
assert_terminated '"foo\nbar #{}"'
|
148
|
+
assert_terminated '"#{}\#{}"'
|
149
|
+
assert_terminated '"\#{}#{}"'
|
117
150
|
# Within indentation
|
118
151
|
assert_generates <<-'RUBY', <<-'RUBY'
|
119
152
|
if foo
|
@@ -127,36 +160,38 @@ describe Unparser do
|
|
127
160
|
end
|
128
161
|
RUBY
|
129
162
|
|
130
|
-
|
131
|
-
|
163
|
+
assert_terminated '"foo#{@bar}"'
|
164
|
+
assert_terminated '"fo\no#{bar}b\naz"'
|
132
165
|
end
|
133
166
|
|
134
167
|
context 'execute string' do
|
135
|
-
|
136
|
-
|
168
|
+
assert_terminated '`foo`'
|
169
|
+
assert_terminated '`foo#{@bar}`'
|
137
170
|
assert_generates '%x(\))', '`)`'
|
138
171
|
# FIXME: Research into this one!
|
139
172
|
# assert_generates '%x(`)', '`\``'
|
140
|
-
|
173
|
+
assert_terminated '`"`'
|
141
174
|
end
|
142
175
|
|
143
176
|
context 'symbol' do
|
144
177
|
assert_generates s(:sym, :foo), ':foo'
|
145
178
|
assert_generates s(:sym, :"A B"), ':"A B"'
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
179
|
+
assert_terminated ':foo'
|
180
|
+
assert_terminated ':"A B"'
|
181
|
+
assert_terminated ':"A\"B"'
|
182
|
+
assert_terminated ':""'
|
150
183
|
end
|
151
184
|
|
152
185
|
context 'regexp' do
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
186
|
+
assert_terminated '/foo/'
|
187
|
+
assert_terminated %q(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/)
|
188
|
+
assert_terminated '/foo#{@bar}/'
|
189
|
+
assert_terminated '/foo#{@bar}/imx'
|
190
|
+
assert_terminated '/#{"\x00"}/', %w(1.9)
|
191
|
+
assert_terminated '/#{"\u0000"}/', %w(2.0 2.1)
|
192
|
+
assert_terminated "/\n/"
|
193
|
+
assert_terminated '/\n/'
|
194
|
+
assert_terminated "/\n/x"
|
160
195
|
# Within indentation
|
161
196
|
assert_source <<-RUBY
|
162
197
|
if foo
|
@@ -167,31 +202,32 @@ describe Unparser do
|
|
167
202
|
assert_generates '%r(/)', '/\//'
|
168
203
|
assert_generates '%r(\))', '/)/'
|
169
204
|
assert_generates '%r(#{@bar}baz)', '/#{@bar}baz/'
|
170
|
-
|
205
|
+
assert_terminated '/\/\//x'
|
171
206
|
end
|
172
207
|
|
173
208
|
context 'dynamic symbol' do
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
209
|
+
assert_terminated ':"foo#{bar}baz"'
|
210
|
+
assert_terminated ':"fo\no#{bar}b\naz"'
|
211
|
+
assert_terminated ':"#{bar}foo"'
|
212
|
+
assert_terminated ':"#{"foo"}"'
|
213
|
+
assert_terminated ':"foo#{bar}"'
|
178
214
|
end
|
179
215
|
|
180
216
|
context 'irange' do
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
217
|
+
assert_unterminated '1..2'
|
218
|
+
assert_unterminated '(0.0 / 0.0)..1'
|
219
|
+
assert_unterminated '1..(0.0 / 0.0)'
|
220
|
+
assert_unterminated '(0.0 / 0.0)..100'
|
185
221
|
end
|
186
222
|
|
187
223
|
context 'erange' do
|
188
|
-
|
224
|
+
assert_unterminated '1...2'
|
189
225
|
end
|
190
226
|
|
191
227
|
context 'float' do
|
192
228
|
assert_source '-0.1'
|
193
|
-
|
194
|
-
|
229
|
+
assert_terminated '0.1'
|
230
|
+
assert_terminated '0.1'
|
195
231
|
assert_generates '10.2e10000000000', 'Float::INFINITY'
|
196
232
|
assert_generates '-10.2e10000000000', '-Float::INFINITY'
|
197
233
|
assert_generates s(:float, -0.1), '-0.1'
|
@@ -199,18 +235,18 @@ describe Unparser do
|
|
199
235
|
end
|
200
236
|
|
201
237
|
context 'array' do
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
assert_generates '%w(foo bar)',
|
238
|
+
assert_terminated '[1, 2]'
|
239
|
+
assert_terminated '[1, (), n2]'
|
240
|
+
assert_terminated '[1]'
|
241
|
+
assert_terminated '[]'
|
242
|
+
assert_terminated '[1, *@foo]'
|
243
|
+
assert_terminated '[*@foo, 1]'
|
244
|
+
assert_terminated '[*@foo, *@baz]'
|
245
|
+
assert_generates '%w(foo bar)', '["foo", "bar"]'
|
210
246
|
end
|
211
247
|
|
212
248
|
context 'hash' do
|
213
|
-
|
249
|
+
assert_terminated '{}'
|
214
250
|
assert_source '{ () => () }'
|
215
251
|
assert_source '{ 1 => 2 }'
|
216
252
|
assert_source '{ 1 => 2, 3 => 4 }'
|
@@ -219,7 +255,7 @@ describe Unparser do
|
|
219
255
|
assert_source "{ foo: (if true\nend) }"
|
220
256
|
|
221
257
|
context 'with symbol keys' do
|
222
|
-
assert_source '{ a: (1 rescue
|
258
|
+
assert_source '{ a: (1 rescue foo), b: 2 }'
|
223
259
|
assert_source '{ a: 1, b: 2 }'
|
224
260
|
assert_source '{ a: :a }'
|
225
261
|
assert_source '{ :"a b" => 1 }'
|
@@ -229,30 +265,21 @@ describe Unparser do
|
|
229
265
|
end
|
230
266
|
|
231
267
|
context 'access' do
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
assert_source '$1'
|
236
|
-
assert_source '$`'
|
237
|
-
assert_source 'CONST'
|
238
|
-
assert_source 'SCOPED::CONST'
|
239
|
-
assert_source '::TOPLEVEL'
|
240
|
-
assert_source '::TOPLEVEL::CONST'
|
241
|
-
end
|
242
|
-
|
243
|
-
context 'retry' do
|
244
|
-
assert_source 'retry'
|
268
|
+
%w(@a @@a $a $1 $` CONST SCOPED::CONST ::TOPLEVEL ::TOPLEVEL::CONST).each do |expression|
|
269
|
+
assert_terminated(expression)
|
270
|
+
end
|
245
271
|
end
|
246
272
|
|
247
|
-
context '
|
248
|
-
|
273
|
+
context 'control keywords' do
|
274
|
+
%w(retry redo).each do |expression|
|
275
|
+
assert_terminated(expression)
|
276
|
+
end
|
249
277
|
end
|
250
278
|
|
251
279
|
context 'singletons' do
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
assert_source 'nil'
|
280
|
+
%w(self true false nil).each do |expression|
|
281
|
+
assert_terminated(expression)
|
282
|
+
end
|
256
283
|
end
|
257
284
|
|
258
285
|
context 'magic keywords' do
|
@@ -263,17 +290,17 @@ describe Unparser do
|
|
263
290
|
|
264
291
|
context 'assignment' do
|
265
292
|
context 'single' do
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
293
|
+
assert_unterminated 'a = 1'
|
294
|
+
assert_unterminated '@a = 1'
|
295
|
+
assert_unterminated '@@a = 1'
|
296
|
+
assert_unterminated '$a = 1'
|
297
|
+
assert_unterminated 'CONST = 1'
|
298
|
+
assert_unterminated 'Name::Spaced::CONST = 1'
|
299
|
+
assert_unterminated '::Foo = ::Bar'
|
273
300
|
end
|
274
301
|
|
275
302
|
context 'lvar assigned from method with same name' do
|
276
|
-
|
303
|
+
assert_unterminated 'foo = foo()'
|
277
304
|
end
|
278
305
|
|
279
306
|
context 'lvar introduction from condition' do
|
@@ -339,32 +366,33 @@ describe Unparser do
|
|
339
366
|
end
|
340
367
|
|
341
368
|
context 'multiple' do
|
342
|
-
assert_source 'a, b = [1, 2]'
|
343
|
-
assert_source 'a, *foo = [1, 2]'
|
344
369
|
assert_source 'a, * = [1, 2]'
|
345
|
-
assert_source '*foo = [1, 2]'
|
370
|
+
assert_source 'a, *foo = [1, 2]'
|
346
371
|
assert_source '*a = []'
|
347
|
-
assert_source '
|
348
|
-
assert_source 'a.foo, a.bar = [1, 2]'
|
349
|
-
assert_source 'a[0, 2]'
|
350
|
-
assert_source 'a[0], a[1] = [1, 2]'
|
351
|
-
assert_source 'a[*foo], a[1] = [1, 2]'
|
352
|
-
assert_source '@@a, @@b = [1, 2]'
|
353
|
-
assert_source '$a, $b = [1, 2]'
|
354
|
-
assert_source 'a, b = foo'
|
355
|
-
assert_source 'a, (b, c) = [1, [2, 3]]'
|
372
|
+
assert_source '*foo = [1, 2]'
|
356
373
|
assert_source 'a, = foo'
|
374
|
+
assert_unterminated 'a, b = [1, 2]'
|
375
|
+
assert_unterminated '@a, @b = [1, 2]'
|
376
|
+
assert_unterminated 'a.foo, a.bar = [1, 2]'
|
377
|
+
assert_unterminated 'a[0], a[1] = [1, 2]'
|
378
|
+
assert_unterminated 'a[*foo], a[1] = [1, 2]'
|
379
|
+
assert_unterminated '@@a, @@b = [1, 2]'
|
380
|
+
assert_unterminated '$a, $b = [1, 2]'
|
381
|
+
assert_unterminated 'a, b = foo'
|
382
|
+
assert_unterminated 'a, (b, c) = [1, [2, 3]]'
|
383
|
+
assert_unterminated 'a = (b, c = 1)'
|
384
|
+
assert_unterminated '(a,), b = 1'
|
357
385
|
end
|
358
386
|
end
|
359
387
|
|
360
388
|
%w(next return break).each do |keyword|
|
361
389
|
|
362
390
|
context keyword do
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
391
|
+
assert_terminated "#{keyword}"
|
392
|
+
assert_unterminated "#{keyword} 1"
|
393
|
+
assert_unterminated "#{keyword} 2, 3"
|
394
|
+
assert_unterminated "#{keyword} *nil"
|
395
|
+
assert_unterminated "#{keyword} *foo, bar"
|
368
396
|
|
369
397
|
assert_generates <<-RUBY, <<-RUBY
|
370
398
|
foo do |bar|
|
@@ -391,19 +419,19 @@ describe Unparser do
|
|
391
419
|
end
|
392
420
|
|
393
421
|
context 'send' do
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
422
|
+
assert_terminated 'foo'
|
423
|
+
assert_terminated 'self.foo'
|
424
|
+
assert_terminated 'a.foo'
|
425
|
+
assert_terminated 'A.foo'
|
426
|
+
assert_terminated 'foo[]'
|
427
|
+
assert_terminated 'foo[1]'
|
428
|
+
assert_terminated 'foo[*baz]'
|
429
|
+
assert_terminated 'foo(1)'
|
430
|
+
assert_terminated 'foo(bar)'
|
431
|
+
assert_terminated 'foo(&block)'
|
432
|
+
assert_terminated 'foo(&(foo || bar))'
|
433
|
+
assert_terminated 'foo(*arguments)'
|
434
|
+
assert_terminated 'foo(*arguments)'
|
407
435
|
assert_source <<-'RUBY'
|
408
436
|
foo do
|
409
437
|
end
|
@@ -493,40 +521,11 @@ describe Unparser do
|
|
493
521
|
end.baz
|
494
522
|
RUBY
|
495
523
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
assert_source '$var.bar'
|
502
|
-
assert_source '"".bar'
|
503
|
-
assert_source 'defined?(@foo).bar'
|
504
|
-
assert_source 'break.foo'
|
505
|
-
assert_source 'next.foo'
|
506
|
-
assert_source 'super(a).foo'
|
507
|
-
assert_source 'a || return'
|
508
|
-
assert_source 'super.foo'
|
509
|
-
assert_source 'nil.foo'
|
510
|
-
assert_source ':sym.foo'
|
511
|
-
assert_source '1.foo'
|
512
|
-
assert_source '1.0.foo'
|
513
|
-
assert_source '[].foo'
|
514
|
-
assert_source '{}.foo'
|
515
|
-
assert_source 'false.foo'
|
516
|
-
assert_source 'true.foo'
|
517
|
-
assert_source 'self.foo'
|
518
|
-
assert_source 'yield(a).foo'
|
519
|
-
assert_source 'yield.foo'
|
520
|
-
assert_source 'Foo::Bar.foo'
|
521
|
-
assert_source '::BAZ.foo'
|
522
|
-
assert_source 'foo[i].foo'
|
523
|
-
assert_source '(foo[i] = 1).foo'
|
524
|
-
assert_source 'foo[1..2].foo'
|
525
|
-
assert_source '(a.attribute ||= foo).bar'
|
526
|
-
assert_source 'foo.bar = baz[1]'
|
527
|
-
assert_source 'foo.bar = (baz || foo)'
|
528
|
-
assert_source 'foo.bar = baz.bar'
|
529
|
-
assert_source 'foo << (bar * baz)'
|
524
|
+
assert_terminated '(1..2).max'
|
525
|
+
assert_terminated '1..2.max'
|
526
|
+
assert_unterminated 'a || return'
|
527
|
+
assert_unterminated 'foo << (bar * baz)'
|
528
|
+
|
530
529
|
assert_source <<-'RUBY'
|
531
530
|
foo ||= (a, _ = b)
|
532
531
|
RUBY
|
@@ -601,28 +600,25 @@ describe Unparser do
|
|
601
600
|
local.bar
|
602
601
|
RUBY
|
603
602
|
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
603
|
+
assert_terminated 'foo.bar(*args)'
|
604
|
+
assert_terminated 'foo.bar(*arga, foo, *argb)'
|
605
|
+
assert_terminated 'foo.bar(*args, foo)'
|
606
|
+
assert_terminated 'foo.bar(foo, *args)'
|
607
|
+
assert_terminated 'foo.bar(foo, *args, &block)'
|
609
608
|
assert_source <<-'RUBY'
|
610
609
|
foo(bar, *args)
|
611
610
|
RUBY
|
612
611
|
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
assert_source 'foo.bar(:baz, &baz)'
|
619
|
-
assert_source 'foo.bar = :baz'
|
620
|
-
assert_source 'self.foo = :bar'
|
612
|
+
assert_terminated 'foo(*args, &block)'
|
613
|
+
assert_terminated 'foo.bar(&baz)'
|
614
|
+
assert_terminated 'foo.bar(:baz, &baz)'
|
615
|
+
assert_terminated 'foo.bar = :baz'
|
616
|
+
assert_unterminated 'self.foo = :bar'
|
621
617
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
618
|
+
assert_terminated 'foo.bar(baz: boz)'
|
619
|
+
assert_terminated 'foo.bar(foo, "baz" => boz)'
|
620
|
+
assert_terminated 'foo.bar({ foo: boz }, boz)'
|
621
|
+
assert_terminated 'foo.bar(foo, {})'
|
626
622
|
end
|
627
623
|
|
628
624
|
context 'begin; end' do
|
@@ -679,7 +675,7 @@ describe Unparser do
|
|
679
675
|
|
680
676
|
assert_source <<-'RUBY'
|
681
677
|
begin
|
682
|
-
raise(Exception) rescue
|
678
|
+
raise(Exception) rescue foo = bar
|
683
679
|
rescue Exception
|
684
680
|
end
|
685
681
|
RUBY
|
@@ -720,19 +716,19 @@ describe Unparser do
|
|
720
716
|
|
721
717
|
assert_source <<-'RUBY'
|
722
718
|
class << self
|
723
|
-
undef :bar rescue
|
719
|
+
undef :bar rescue nil
|
724
720
|
end
|
725
721
|
RUBY
|
726
722
|
|
727
723
|
assert_source <<-'RUBY'
|
728
724
|
module Foo
|
729
|
-
undef :bar rescue
|
725
|
+
undef :bar rescue nil
|
730
726
|
end
|
731
727
|
RUBY
|
732
728
|
|
733
729
|
assert_source <<-'RUBY'
|
734
730
|
class Foo
|
735
|
-
undef :bar rescue
|
731
|
+
undef :bar rescue nil
|
736
732
|
end
|
737
733
|
RUBY
|
738
734
|
|
@@ -811,34 +807,34 @@ describe Unparser do
|
|
811
807
|
end
|
812
808
|
RUBY
|
813
809
|
|
814
|
-
assert_source 'foo rescue
|
815
|
-
assert_source 'foo rescue
|
816
|
-
assert_source 'x = foo rescue
|
810
|
+
assert_source 'foo rescue bar'
|
811
|
+
assert_source 'foo rescue return bar'
|
812
|
+
assert_source 'x = (foo rescue return bar)'
|
817
813
|
|
818
814
|
%w(while until if).each do |keyword|
|
819
815
|
assert_source <<-RUBY
|
820
816
|
#{keyword} (
|
821
|
-
foo rescue
|
817
|
+
foo rescue false
|
822
818
|
)
|
823
819
|
end
|
824
820
|
RUBY
|
825
821
|
|
826
822
|
assert_generates <<-RUBY, <<-GENERATED
|
827
|
-
foo rescue
|
823
|
+
foo rescue false #{keyword} true
|
828
824
|
RUBY
|
829
825
|
#{keyword} true
|
830
|
-
foo rescue
|
826
|
+
foo rescue false
|
831
827
|
end
|
832
828
|
GENERATED
|
833
829
|
end
|
834
830
|
|
835
831
|
assert_generates <<-'RUBY', <<-GENERATED
|
836
|
-
case (foo rescue
|
832
|
+
case (foo rescue false)
|
837
833
|
when true
|
838
834
|
end
|
839
835
|
RUBY
|
840
836
|
case (
|
841
|
-
foo rescue
|
837
|
+
foo rescue false
|
842
838
|
)
|
843
839
|
when true
|
844
840
|
end
|
@@ -1022,7 +1018,7 @@ describe Unparser do
|
|
1022
1018
|
begin
|
1023
1019
|
foo
|
1024
1020
|
ensure
|
1025
|
-
bar rescue
|
1021
|
+
bar rescue nil
|
1026
1022
|
end
|
1027
1023
|
RUBY
|
1028
1024
|
|
@@ -1304,6 +1300,7 @@ describe Unparser do
|
|
1304
1300
|
%w(|= ||= &= &&= += -= *= /= **= %=).each do |op|
|
1305
1301
|
assert_source "self.foo #{op} bar"
|
1306
1302
|
assert_source "foo[key] #{op} bar"
|
1303
|
+
assert_source "a #{op} (true\nfalse)"
|
1307
1304
|
end
|
1308
1305
|
end
|
1309
1306
|
|
@@ -1351,13 +1348,12 @@ describe Unparser do
|
|
1351
1348
|
end
|
1352
1349
|
|
1353
1350
|
context 'match operators' do
|
1354
|
-
assert_source
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
assert_source
|
1359
|
-
|
1360
|
-
RUBY
|
1351
|
+
assert_source '/bar/ =~ foo'
|
1352
|
+
assert_source '/bar/ =~ :foo'
|
1353
|
+
assert_source '(/bar/ =~ :foo).foo'
|
1354
|
+
assert_source 'foo =~ /bar/'
|
1355
|
+
assert_source 'foo(foo =~ /bar/)'
|
1356
|
+
assert_source '(foo =~ /bar/).foo'
|
1361
1357
|
end
|
1362
1358
|
|
1363
1359
|
context 'binary operator methods' do
|
@@ -1480,6 +1476,11 @@ describe Unparser do
|
|
1480
1476
|
end
|
1481
1477
|
|
1482
1478
|
context 'for' do
|
1479
|
+
assert_source <<-'RUBY'
|
1480
|
+
bar(for a in bar do
|
1481
|
+
baz
|
1482
|
+
end)
|
1483
|
+
RUBY
|
1483
1484
|
assert_source <<-'RUBY'
|
1484
1485
|
for a in bar do
|
1485
1486
|
baz
|
@@ -1519,6 +1520,12 @@ describe Unparser do
|
|
1519
1520
|
end
|
1520
1521
|
|
1521
1522
|
context 'post conditions' do
|
1523
|
+
assert_source <<-'RUBY'
|
1524
|
+
x = (begin
|
1525
|
+
foo
|
1526
|
+
end while baz)
|
1527
|
+
RUBY
|
1528
|
+
|
1522
1529
|
assert_source <<-'RUBY'
|
1523
1530
|
begin
|
1524
1531
|
foo
|