unparser 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +5 -0
- data/Gemfile +1 -1
- data/Gemfile.devtools +5 -5
- data/README.md +1 -1
- data/bin/test-unparser +6 -6
- data/config/flay.yml +1 -1
- data/config/reek.yml +4 -5
- data/config/rubocop.yml +88 -0
- data/lib/unparser.rb +2 -0
- data/lib/unparser/buffer.rb +5 -3
- data/lib/unparser/comments.rb +18 -16
- data/lib/unparser/constants.rb +0 -1
- data/lib/unparser/emitter.rb +11 -39
- data/lib/unparser/emitter/assignment.rb +1 -2
- data/lib/unparser/emitter/binary.rb +2 -2
- data/lib/unparser/emitter/break.rb +1 -1
- data/lib/unparser/emitter/flipflop.rb +2 -2
- data/lib/unparser/emitter/hookexe.rb +2 -2
- data/lib/unparser/emitter/literal/dynamic_body.rb +5 -5
- data/lib/unparser/emitter/literal/primitive.rb +1 -1
- data/lib/unparser/emitter/literal/range.rb +2 -2
- data/lib/unparser/emitter/next.rb +1 -1
- data/lib/unparser/emitter/op_assign.rb +2 -2
- data/lib/unparser/emitter/repetition.rb +4 -4
- data/spec/unit/unparser/comments/skip_eol_comment_spec.rb +2 -2
- data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +1 -1
- data/spec/unit/unparser_spec.rb +135 -134
- data/unparser.gemspec +6 -6
- metadata +9 -10
- data/spec/unit/unparser/emitter/source_map/class_methods/emit_spec.rb +0 -20
@@ -60,7 +60,6 @@ module Unparser
|
|
60
60
|
# Constant assignment emitter
|
61
61
|
class Constant < self
|
62
62
|
|
63
|
-
|
64
63
|
handle :casgn
|
65
64
|
|
66
65
|
children :base, :name, :right_node
|
@@ -134,7 +133,7 @@ module Unparser
|
|
134
133
|
# @api private
|
135
134
|
#
|
136
135
|
def dispatch
|
137
|
-
|
136
|
+
conditional_parentheses(parent_type == :mlhs) do
|
138
137
|
delimited(children)
|
139
138
|
end
|
140
139
|
end
|
@@ -16,7 +16,7 @@ module Unparser
|
|
16
16
|
# @api private
|
17
17
|
#
|
18
18
|
def dispatch
|
19
|
-
|
19
|
+
conditional_parentheses(parent_type == :or || parent_type == :and) do
|
20
20
|
write(K_BREAK)
|
21
21
|
return unless arguments
|
22
22
|
visit_parentheses(arguments)
|
@@ -77,11 +77,11 @@ module Unparser
|
|
77
77
|
#
|
78
78
|
def emit_str_segment(node)
|
79
79
|
util = self.class
|
80
|
-
|
81
|
-
|
82
|
-
gsub(util::DELIMITER, util::REPLACEMENT)
|
83
|
-
gsub(REPLACEMENTS, ESCAPES)
|
84
|
-
write(
|
80
|
+
string = node.children.first
|
81
|
+
segment = string
|
82
|
+
.gsub(util::DELIMITER, util::REPLACEMENT)
|
83
|
+
.gsub(REPLACEMENTS, ESCAPES)
|
84
|
+
write(segment)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Emit interpolated segment
|
@@ -14,7 +14,7 @@ module Unparser
|
|
14
14
|
# @api private
|
15
15
|
#
|
16
16
|
def dispatch
|
17
|
-
|
17
|
+
conditional_parentheses(parent_type == :or || parent_type == :and) do
|
18
18
|
write(K_NEXT)
|
19
19
|
return if children.empty?
|
20
20
|
visit_parentheses(children.first)
|
@@ -9,8 +9,8 @@ module Unparser
|
|
9
9
|
children :condition, :body
|
10
10
|
|
11
11
|
MAP = {
|
12
|
-
:
|
13
|
-
:
|
12
|
+
while_post: K_WHILE,
|
13
|
+
until_post: K_UNTIL
|
14
14
|
}.freeze
|
15
15
|
|
16
16
|
handle(*MAP.keys)
|
@@ -32,8 +32,8 @@ module Unparser
|
|
32
32
|
class Repetition < self
|
33
33
|
|
34
34
|
MAP = {
|
35
|
-
:
|
36
|
-
:
|
35
|
+
while: K_WHILE,
|
36
|
+
until: K_UNTIL
|
37
37
|
}.freeze
|
38
38
|
|
39
39
|
handle(*MAP.keys)
|
@@ -15,14 +15,14 @@ describe Unparser::Comments, '#skip_eol_comment' do
|
|
15
15
|
|
16
16
|
it 'should skip the specified comment only for one subsequent take' do
|
17
17
|
object.consume(ast, :name)
|
18
|
-
object.skip_eol_comment(
|
18
|
+
object.skip_eol_comment('# comment')
|
19
19
|
expect(object.take_eol_comments).to eql([])
|
20
20
|
object.consume(ast, :end)
|
21
21
|
expect(object.take_eol_comments).to eql([comments[1]])
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should not skip comments with different text' do
|
25
|
-
object.skip_eol_comment(
|
25
|
+
object.skip_eol_comment('# not the comment')
|
26
26
|
object.consume(ast, :end)
|
27
27
|
expect(object.take_eol_comments).to eql(comments)
|
28
28
|
end
|
@@ -12,6 +12,6 @@ describe Unparser::Emitter, '.handle' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should register emitter' do
|
15
|
-
expect { subject }.to change { Unparser::Emitter::REGISTRY }.from({}).to(:
|
15
|
+
expect { subject }.to change { Unparser::Emitter::REGISTRY }.from({}).to(foo: class_under_test)
|
16
16
|
end
|
17
17
|
end
|
data/spec/unit/unparser_spec.rb
CHANGED
@@ -27,8 +27,7 @@ describe Unparser do
|
|
27
27
|
def self.strip(ruby)
|
28
28
|
return ruby if ruby.empty?
|
29
29
|
lines = ruby.lines
|
30
|
-
|
31
|
-
match = /\A[ ]*/.match(line)
|
30
|
+
match = /\A[ ]*/.match(lines.first)
|
32
31
|
length = match[0].length
|
33
32
|
source = lines.map do |line|
|
34
33
|
line[(length..-1)]
|
@@ -108,7 +107,8 @@ describe Unparser do
|
|
108
107
|
assert_source '`foo`'
|
109
108
|
assert_source '`foo#{@bar}`'
|
110
109
|
assert_generates '%x(\))', '`)`'
|
111
|
-
|
110
|
+
# FIXME: Research into this one!
|
111
|
+
# assert_generates '%x(`)', '`\``'
|
112
112
|
assert_source '`"`'
|
113
113
|
end
|
114
114
|
|
@@ -252,11 +252,11 @@ describe Unparser do
|
|
252
252
|
end
|
253
253
|
|
254
254
|
context 'return' do
|
255
|
-
assert_source <<-RUBY
|
255
|
+
assert_source <<-'RUBY'
|
256
256
|
return
|
257
257
|
RUBY
|
258
258
|
|
259
|
-
assert_source <<-RUBY
|
259
|
+
assert_source <<-'RUBY'
|
260
260
|
return(1)
|
261
261
|
RUBY
|
262
262
|
end
|
@@ -273,58 +273,58 @@ describe Unparser do
|
|
273
273
|
assert_source 'foo(&block)'
|
274
274
|
assert_source 'foo(*arguments)'
|
275
275
|
assert_source 'foo(*arguments)'
|
276
|
-
assert_source <<-RUBY
|
276
|
+
assert_source <<-'RUBY'
|
277
277
|
foo do
|
278
278
|
end
|
279
279
|
RUBY
|
280
280
|
|
281
|
-
assert_source <<-RUBY
|
281
|
+
assert_source <<-'RUBY'
|
282
282
|
foo(1) do
|
283
283
|
nil
|
284
284
|
end
|
285
285
|
RUBY
|
286
286
|
|
287
|
-
assert_source <<-RUBY
|
287
|
+
assert_source <<-'RUBY'
|
288
288
|
foo do |a, b|
|
289
289
|
nil
|
290
290
|
end
|
291
291
|
RUBY
|
292
292
|
|
293
|
-
assert_source <<-RUBY
|
293
|
+
assert_source <<-'RUBY'
|
294
294
|
foo do |a, *b|
|
295
295
|
nil
|
296
296
|
end
|
297
297
|
RUBY
|
298
298
|
|
299
|
-
assert_source <<-RUBY
|
299
|
+
assert_source <<-'RUBY'
|
300
300
|
foo do |a, *|
|
301
301
|
nil
|
302
302
|
end
|
303
303
|
RUBY
|
304
304
|
|
305
|
-
assert_source <<-RUBY
|
305
|
+
assert_source <<-'RUBY'
|
306
306
|
foo do
|
307
307
|
bar
|
308
308
|
end
|
309
309
|
RUBY
|
310
310
|
|
311
|
-
assert_source <<-RUBY
|
311
|
+
assert_source <<-'RUBY'
|
312
312
|
foo.bar(*args)
|
313
313
|
RUBY
|
314
314
|
|
315
|
-
assert_source <<-RUBY
|
315
|
+
assert_source <<-'RUBY'
|
316
316
|
foo.bar do |(a, b), c|
|
317
317
|
d
|
318
318
|
end
|
319
319
|
RUBY
|
320
320
|
|
321
|
-
assert_source <<-RUBY
|
321
|
+
assert_source <<-'RUBY'
|
322
322
|
foo.bar do |(a, b)|
|
323
323
|
d
|
324
324
|
end
|
325
325
|
RUBY
|
326
326
|
|
327
|
-
assert_source <<-RUBY
|
327
|
+
assert_source <<-'RUBY'
|
328
328
|
foo.bar do
|
329
329
|
end.baz
|
330
330
|
RUBY
|
@@ -360,64 +360,64 @@ describe Unparser do
|
|
360
360
|
assert_source 'array[1..2].foo'
|
361
361
|
assert_source '(a.attribute ||= foo).bar'
|
362
362
|
|
363
|
-
assert_source <<-RUBY
|
363
|
+
assert_source <<-'RUBY'
|
364
364
|
begin
|
365
365
|
rescue
|
366
366
|
end.bar
|
367
367
|
RUBY
|
368
368
|
|
369
|
-
assert_source <<-RUBY
|
369
|
+
assert_source <<-'RUBY'
|
370
370
|
case foo
|
371
371
|
when bar
|
372
372
|
end.baz
|
373
373
|
RUBY
|
374
374
|
|
375
|
-
assert_source <<-RUBY
|
375
|
+
assert_source <<-'RUBY'
|
376
376
|
class << self
|
377
377
|
end.bar
|
378
378
|
RUBY
|
379
379
|
|
380
|
-
assert_source <<-RUBY
|
380
|
+
assert_source <<-'RUBY'
|
381
381
|
def self.foo
|
382
382
|
end.bar
|
383
383
|
RUBY
|
384
384
|
|
385
|
-
assert_source <<-RUBY
|
385
|
+
assert_source <<-'RUBY'
|
386
386
|
def foo
|
387
387
|
end.bar
|
388
388
|
RUBY
|
389
389
|
|
390
|
-
assert_source <<-RUBY
|
390
|
+
assert_source <<-'RUBY'
|
391
391
|
until foo
|
392
392
|
end.bar
|
393
393
|
RUBY
|
394
394
|
|
395
|
-
assert_source <<-RUBY
|
395
|
+
assert_source <<-'RUBY'
|
396
396
|
while foo
|
397
397
|
end.bar
|
398
398
|
RUBY
|
399
399
|
|
400
|
-
assert_source <<-RUBY
|
400
|
+
assert_source <<-'RUBY'
|
401
401
|
loop do
|
402
402
|
end.bar
|
403
403
|
RUBY
|
404
404
|
|
405
|
-
assert_source <<-RUBY
|
405
|
+
assert_source <<-'RUBY'
|
406
406
|
class Foo
|
407
407
|
end.bar
|
408
408
|
RUBY
|
409
409
|
|
410
|
-
assert_source <<-RUBY
|
410
|
+
assert_source <<-'RUBY'
|
411
411
|
module Foo
|
412
412
|
end.bar
|
413
413
|
RUBY
|
414
414
|
|
415
|
-
assert_source <<-RUBY
|
415
|
+
assert_source <<-'RUBY'
|
416
416
|
if foo
|
417
417
|
end.baz
|
418
418
|
RUBY
|
419
419
|
|
420
|
-
assert_source <<-RUBY
|
420
|
+
assert_source <<-'RUBY'
|
421
421
|
local = 1
|
422
422
|
local.bar
|
423
423
|
RUBY
|
@@ -427,11 +427,11 @@ describe Unparser do
|
|
427
427
|
assert_source 'foo.bar(*args, foo)'
|
428
428
|
assert_source 'foo.bar(foo, *args)'
|
429
429
|
assert_source 'foo.bar(foo, *args, &block)'
|
430
|
-
assert_source <<-RUBY
|
430
|
+
assert_source <<-'RUBY'
|
431
431
|
foo(bar, *args)
|
432
432
|
RUBY
|
433
433
|
|
434
|
-
assert_source <<-RUBY
|
434
|
+
assert_source <<-'RUBY'
|
435
435
|
foo(*args, &block)
|
436
436
|
RUBY
|
437
437
|
|
@@ -444,12 +444,12 @@ describe Unparser do
|
|
444
444
|
context 'begin; end' do
|
445
445
|
assert_generates s(:begin), ''
|
446
446
|
|
447
|
-
assert_source <<-RUBY
|
447
|
+
assert_source <<-'RUBY'
|
448
448
|
foo
|
449
449
|
bar
|
450
450
|
RUBY
|
451
451
|
|
452
|
-
assert_source <<-RUBY
|
452
|
+
assert_source <<-'RUBY'
|
453
453
|
begin
|
454
454
|
foo
|
455
455
|
bar
|
@@ -458,7 +458,7 @@ describe Unparser do
|
|
458
458
|
end
|
459
459
|
|
460
460
|
context 'begin / rescue / ensure' do
|
461
|
-
assert_source <<-RUBY
|
461
|
+
assert_source <<-'RUBY'
|
462
462
|
begin
|
463
463
|
foo
|
464
464
|
ensure
|
@@ -467,7 +467,7 @@ describe Unparser do
|
|
467
467
|
end
|
468
468
|
RUBY
|
469
469
|
|
470
|
-
assert_source <<-RUBY
|
470
|
+
assert_source <<-'RUBY'
|
471
471
|
begin
|
472
472
|
foo
|
473
473
|
rescue
|
@@ -475,7 +475,7 @@ describe Unparser do
|
|
475
475
|
end
|
476
476
|
RUBY
|
477
477
|
|
478
|
-
assert_source <<-RUBY
|
478
|
+
assert_source <<-'RUBY'
|
479
479
|
begin
|
480
480
|
begin
|
481
481
|
foo
|
@@ -488,7 +488,7 @@ describe Unparser do
|
|
488
488
|
end
|
489
489
|
RUBY
|
490
490
|
|
491
|
-
assert_source <<-RUBY
|
491
|
+
assert_source <<-'RUBY'
|
492
492
|
begin
|
493
493
|
foo
|
494
494
|
bar
|
@@ -498,7 +498,7 @@ describe Unparser do
|
|
498
498
|
end
|
499
499
|
RUBY
|
500
500
|
|
501
|
-
assert_source <<-RUBY
|
501
|
+
assert_source <<-'RUBY'
|
502
502
|
begin
|
503
503
|
foo
|
504
504
|
rescue Exception
|
@@ -506,7 +506,7 @@ describe Unparser do
|
|
506
506
|
end
|
507
507
|
RUBY
|
508
508
|
|
509
|
-
assert_source <<-RUBY
|
509
|
+
assert_source <<-'RUBY'
|
510
510
|
begin
|
511
511
|
foo
|
512
512
|
rescue => bar
|
@@ -514,7 +514,7 @@ describe Unparser do
|
|
514
514
|
end
|
515
515
|
RUBY
|
516
516
|
|
517
|
-
assert_source <<-RUBY
|
517
|
+
assert_source <<-'RUBY'
|
518
518
|
begin
|
519
519
|
foo
|
520
520
|
rescue Exception, Other => bar
|
@@ -522,20 +522,20 @@ describe Unparser do
|
|
522
522
|
end
|
523
523
|
RUBY
|
524
524
|
|
525
|
-
assert_source <<-RUBY
|
525
|
+
assert_source <<-'RUBY'
|
526
526
|
begin
|
527
527
|
rescue Exception => e
|
528
528
|
end
|
529
529
|
RUBY
|
530
530
|
|
531
|
-
assert_source <<-RUBY
|
531
|
+
assert_source <<-'RUBY'
|
532
532
|
begin
|
533
533
|
rescue
|
534
534
|
ensure
|
535
535
|
end
|
536
536
|
RUBY
|
537
537
|
|
538
|
-
assert_source <<-RUBY
|
538
|
+
assert_source <<-'RUBY'
|
539
539
|
begin
|
540
540
|
foo
|
541
541
|
rescue Exception => bar
|
@@ -543,7 +543,7 @@ describe Unparser do
|
|
543
543
|
end
|
544
544
|
RUBY
|
545
545
|
|
546
|
-
assert_source <<-RUBY
|
546
|
+
assert_source <<-'RUBY'
|
547
547
|
begin
|
548
548
|
bar
|
549
549
|
rescue SomeError, *bar
|
@@ -551,7 +551,7 @@ describe Unparser do
|
|
551
551
|
end
|
552
552
|
RUBY
|
553
553
|
|
554
|
-
assert_source <<-RUBY
|
554
|
+
assert_source <<-'RUBY'
|
555
555
|
begin
|
556
556
|
bar
|
557
557
|
rescue SomeError, *bar => exception
|
@@ -559,7 +559,7 @@ describe Unparser do
|
|
559
559
|
end
|
560
560
|
RUBY
|
561
561
|
|
562
|
-
assert_source <<-RUBY
|
562
|
+
assert_source <<-'RUBY'
|
563
563
|
begin
|
564
564
|
bar
|
565
565
|
rescue *bar
|
@@ -567,14 +567,14 @@ describe Unparser do
|
|
567
567
|
end
|
568
568
|
RUBY
|
569
569
|
|
570
|
-
assert_source <<-RUBY
|
570
|
+
assert_source <<-'RUBY'
|
571
571
|
begin
|
572
572
|
bar
|
573
573
|
rescue LoadError
|
574
574
|
end
|
575
575
|
RUBY
|
576
576
|
|
577
|
-
assert_source <<-RUBY
|
577
|
+
assert_source <<-'RUBY'
|
578
578
|
begin
|
579
579
|
bar
|
580
580
|
rescue
|
@@ -583,7 +583,7 @@ describe Unparser do
|
|
583
583
|
end
|
584
584
|
RUBY
|
585
585
|
|
586
|
-
assert_source <<-RUBY
|
586
|
+
assert_source <<-'RUBY'
|
587
587
|
begin
|
588
588
|
bar
|
589
589
|
rescue *bar => exception
|
@@ -595,7 +595,7 @@ describe Unparser do
|
|
595
595
|
context 'super' do
|
596
596
|
assert_source 'super'
|
597
597
|
|
598
|
-
assert_source <<-RUBY
|
598
|
+
assert_source <<-'RUBY'
|
599
599
|
super do
|
600
600
|
foo
|
601
601
|
end
|
@@ -603,7 +603,7 @@ describe Unparser do
|
|
603
603
|
|
604
604
|
assert_source 'super()'
|
605
605
|
|
606
|
-
assert_source <<-RUBY
|
606
|
+
assert_source <<-'RUBY'
|
607
607
|
super() do
|
608
608
|
foo
|
609
609
|
end
|
@@ -611,7 +611,7 @@ describe Unparser do
|
|
611
611
|
|
612
612
|
assert_source 'super(a)'
|
613
613
|
|
614
|
-
assert_source <<-RUBY
|
614
|
+
assert_source <<-'RUBY'
|
615
615
|
super(a) do
|
616
616
|
foo
|
617
617
|
end
|
@@ -619,7 +619,7 @@ describe Unparser do
|
|
619
619
|
|
620
620
|
assert_source 'super(a, b)'
|
621
621
|
|
622
|
-
assert_source <<-RUBY
|
622
|
+
assert_source <<-'RUBY'
|
623
623
|
super(a, b) do
|
624
624
|
foo
|
625
625
|
end
|
@@ -634,7 +634,7 @@ describe Unparser do
|
|
634
634
|
end
|
635
635
|
|
636
636
|
context 'BEGIN' do
|
637
|
-
assert_source <<-RUBY
|
637
|
+
assert_source <<-'RUBY'
|
638
638
|
BEGIN {
|
639
639
|
foo
|
640
640
|
}
|
@@ -642,7 +642,7 @@ describe Unparser do
|
|
642
642
|
end
|
643
643
|
|
644
644
|
context 'END' do
|
645
|
-
assert_source <<-RUBY
|
645
|
+
assert_source <<-'RUBY'
|
646
646
|
END {
|
647
647
|
foo
|
648
648
|
}
|
@@ -650,11 +650,11 @@ describe Unparser do
|
|
650
650
|
end
|
651
651
|
|
652
652
|
context 'alias' do
|
653
|
-
assert_source <<-RUBY
|
653
|
+
assert_source <<-'RUBY'
|
654
654
|
alias $foo $bar
|
655
655
|
RUBY
|
656
656
|
|
657
|
-
assert_source <<-RUBY
|
657
|
+
assert_source <<-'RUBY'
|
658
658
|
alias :foo :bar
|
659
659
|
RUBY
|
660
660
|
end
|
@@ -674,19 +674,19 @@ describe Unparser do
|
|
674
674
|
end
|
675
675
|
|
676
676
|
context 'if statement' do
|
677
|
-
assert_source <<-RUBY
|
677
|
+
assert_source <<-'RUBY'
|
678
678
|
if /foo/
|
679
679
|
bar
|
680
680
|
end
|
681
681
|
RUBY
|
682
682
|
|
683
|
-
assert_source <<-RUBY
|
683
|
+
assert_source <<-'RUBY'
|
684
684
|
if 3
|
685
685
|
9
|
686
686
|
end
|
687
687
|
RUBY
|
688
688
|
|
689
|
-
assert_source <<-RUBY
|
689
|
+
assert_source <<-'RUBY'
|
690
690
|
if 4
|
691
691
|
5
|
692
692
|
else
|
@@ -694,19 +694,19 @@ describe Unparser do
|
|
694
694
|
end
|
695
695
|
RUBY
|
696
696
|
|
697
|
-
assert_source <<-RUBY
|
697
|
+
assert_source <<-'RUBY'
|
698
698
|
unless 3
|
699
699
|
nil
|
700
700
|
end
|
701
701
|
RUBY
|
702
702
|
|
703
|
-
assert_source <<-RUBY
|
703
|
+
assert_source <<-'RUBY'
|
704
704
|
unless 3
|
705
705
|
9
|
706
706
|
end
|
707
707
|
RUBY
|
708
708
|
|
709
|
-
assert_source <<-RUBY
|
709
|
+
assert_source <<-'RUBY'
|
710
710
|
if foo
|
711
711
|
end
|
712
712
|
RUBY
|
@@ -715,18 +715,18 @@ describe Unparser do
|
|
715
715
|
context 'def' do
|
716
716
|
context 'on instance' do
|
717
717
|
|
718
|
-
assert_source <<-RUBY
|
718
|
+
assert_source <<-'RUBY'
|
719
719
|
def foo
|
720
720
|
end
|
721
721
|
RUBY
|
722
722
|
|
723
|
-
assert_source <<-RUBY
|
723
|
+
assert_source <<-'RUBY'
|
724
724
|
def foo
|
725
725
|
bar
|
726
726
|
end
|
727
727
|
RUBY
|
728
728
|
|
729
|
-
assert_source <<-RUBY
|
729
|
+
assert_source <<-'RUBY'
|
730
730
|
def foo
|
731
731
|
bar
|
732
732
|
ensure
|
@@ -734,7 +734,7 @@ describe Unparser do
|
|
734
734
|
end
|
735
735
|
RUBY
|
736
736
|
|
737
|
-
assert_source <<-RUBY
|
737
|
+
assert_source <<-'RUBY'
|
738
738
|
def foo
|
739
739
|
bar
|
740
740
|
rescue
|
@@ -742,95 +742,95 @@ describe Unparser do
|
|
742
742
|
end
|
743
743
|
RUBY
|
744
744
|
|
745
|
-
assert_source <<-RUBY
|
745
|
+
assert_source <<-'RUBY'
|
746
746
|
def foo(bar)
|
747
747
|
bar
|
748
748
|
end
|
749
749
|
RUBY
|
750
750
|
|
751
|
-
assert_source <<-RUBY
|
751
|
+
assert_source <<-'RUBY'
|
752
752
|
def foo(bar, baz)
|
753
753
|
bar
|
754
754
|
end
|
755
755
|
RUBY
|
756
756
|
|
757
|
-
assert_source <<-RUBY
|
757
|
+
assert_source <<-'RUBY'
|
758
758
|
def foo(bar = true)
|
759
759
|
bar
|
760
760
|
end
|
761
761
|
RUBY
|
762
762
|
|
763
|
-
assert_source <<-RUBY
|
763
|
+
assert_source <<-'RUBY'
|
764
764
|
def foo(bar, baz = true)
|
765
765
|
bar
|
766
766
|
end
|
767
767
|
RUBY
|
768
768
|
|
769
|
-
assert_source <<-RUBY, %w(1.9 2.0)
|
769
|
+
assert_source <<-'RUBY', %w(1.9 2.0)
|
770
770
|
def foo(bar, baz = true, foo)
|
771
771
|
bar
|
772
772
|
end
|
773
773
|
RUBY
|
774
774
|
|
775
|
-
assert_source <<-RUBY, %w(2.1)
|
775
|
+
assert_source <<-'RUBY', %w(2.1)
|
776
776
|
def foo(bar: 1)
|
777
777
|
end
|
778
778
|
RUBY
|
779
779
|
|
780
|
-
assert_source <<-RUBY, %w(2.0)
|
780
|
+
assert_source <<-'RUBY', %w(2.0)
|
781
781
|
def foo(**bar)
|
782
782
|
end
|
783
783
|
RUBY
|
784
784
|
|
785
|
-
assert_source <<-RUBY
|
785
|
+
assert_source <<-'RUBY'
|
786
786
|
def foo(*)
|
787
787
|
bar
|
788
788
|
end
|
789
789
|
RUBY
|
790
790
|
|
791
|
-
assert_source <<-RUBY
|
791
|
+
assert_source <<-'RUBY'
|
792
792
|
def foo(*bar)
|
793
793
|
bar
|
794
794
|
end
|
795
795
|
RUBY
|
796
796
|
|
797
|
-
assert_source <<-RUBY
|
797
|
+
assert_source <<-'RUBY'
|
798
798
|
def foo(bar, *baz)
|
799
799
|
bar
|
800
800
|
end
|
801
801
|
RUBY
|
802
802
|
|
803
|
-
assert_source <<-RUBY
|
803
|
+
assert_source <<-'RUBY'
|
804
804
|
def foo(baz = true, *bor)
|
805
805
|
bar
|
806
806
|
end
|
807
807
|
RUBY
|
808
808
|
|
809
|
-
assert_source <<-RUBY
|
809
|
+
assert_source <<-'RUBY'
|
810
810
|
def foo(baz = true, *bor, &block)
|
811
811
|
bar
|
812
812
|
end
|
813
813
|
RUBY
|
814
814
|
|
815
|
-
assert_source <<-RUBY
|
815
|
+
assert_source <<-'RUBY'
|
816
816
|
def foo(bar, baz = true, *bor)
|
817
817
|
bar
|
818
818
|
end
|
819
819
|
RUBY
|
820
820
|
|
821
|
-
assert_source <<-RUBY
|
821
|
+
assert_source <<-'RUBY'
|
822
822
|
def foo(&block)
|
823
823
|
bar
|
824
824
|
end
|
825
825
|
RUBY
|
826
826
|
|
827
|
-
assert_source <<-RUBY
|
827
|
+
assert_source <<-'RUBY'
|
828
828
|
def foo(bar, &block)
|
829
829
|
bar
|
830
830
|
end
|
831
831
|
RUBY
|
832
832
|
|
833
|
-
assert_source <<-RUBY
|
833
|
+
assert_source <<-'RUBY'
|
834
834
|
def foo
|
835
835
|
bar
|
836
836
|
baz
|
@@ -839,26 +839,25 @@ describe Unparser do
|
|
839
839
|
end
|
840
840
|
|
841
841
|
context 'on singleton' do
|
842
|
-
assert_source <<-RUBY
|
842
|
+
assert_source <<-'RUBY'
|
843
843
|
def self.foo
|
844
844
|
end
|
845
845
|
RUBY
|
846
846
|
|
847
|
-
|
848
|
-
assert_source <<-RUBY
|
847
|
+
assert_source <<-'RUBY'
|
849
848
|
def self.foo
|
850
849
|
bar
|
851
850
|
end
|
852
851
|
RUBY
|
853
852
|
|
854
|
-
assert_source <<-RUBY
|
853
|
+
assert_source <<-'RUBY'
|
855
854
|
def self.foo
|
856
855
|
bar
|
857
856
|
baz
|
858
857
|
end
|
859
858
|
RUBY
|
860
859
|
|
861
|
-
assert_source <<-RUBY
|
860
|
+
assert_source <<-'RUBY'
|
862
861
|
def Foo.bar
|
863
862
|
bar
|
864
863
|
end
|
@@ -867,43 +866,43 @@ describe Unparser do
|
|
867
866
|
end
|
868
867
|
|
869
868
|
context 'class' do
|
870
|
-
assert_source <<-RUBY
|
869
|
+
assert_source <<-'RUBY'
|
871
870
|
class TestClass
|
872
871
|
end # TestClass
|
873
872
|
RUBY
|
874
873
|
|
875
|
-
assert_source <<-RUBY
|
874
|
+
assert_source <<-'RUBY'
|
876
875
|
class << some_object
|
877
876
|
end
|
878
877
|
RUBY
|
879
878
|
|
880
|
-
assert_source <<-RUBY
|
879
|
+
assert_source <<-'RUBY'
|
881
880
|
class << some_object
|
882
881
|
the_body
|
883
882
|
end
|
884
883
|
RUBY
|
885
884
|
|
886
|
-
assert_source <<-RUBY
|
885
|
+
assert_source <<-'RUBY'
|
887
886
|
class SomeNameSpace::TestClass
|
888
887
|
end # SomeNameSpace::TestClass
|
889
888
|
RUBY
|
890
889
|
|
891
|
-
assert_source <<-RUBY
|
890
|
+
assert_source <<-'RUBY'
|
892
891
|
class Some::Name::Space::TestClass
|
893
892
|
end # Some::Name::Space::TestClass
|
894
893
|
RUBY
|
895
894
|
|
896
|
-
assert_source <<-RUBY
|
895
|
+
assert_source <<-'RUBY'
|
897
896
|
class TestClass < Object
|
898
897
|
end # TestClass
|
899
898
|
RUBY
|
900
899
|
|
901
|
-
assert_source <<-RUBY
|
900
|
+
assert_source <<-'RUBY'
|
902
901
|
class TestClass < SomeNameSpace::Object
|
903
902
|
end # TestClass
|
904
903
|
RUBY
|
905
904
|
|
906
|
-
assert_source <<-RUBY
|
905
|
+
assert_source <<-'RUBY'
|
907
906
|
class TestClass
|
908
907
|
def foo
|
909
908
|
:bar
|
@@ -911,7 +910,7 @@ describe Unparser do
|
|
911
910
|
end # TestClass
|
912
911
|
RUBY
|
913
912
|
|
914
|
-
assert_source <<-RUBY
|
913
|
+
assert_source <<-'RUBY'
|
915
914
|
class ::TestClass
|
916
915
|
end # ::TestClass
|
917
916
|
RUBY
|
@@ -919,22 +918,22 @@ describe Unparser do
|
|
919
918
|
|
920
919
|
context 'module' do
|
921
920
|
|
922
|
-
assert_source <<-RUBY
|
921
|
+
assert_source <<-'RUBY'
|
923
922
|
module TestModule
|
924
923
|
end # TestModule
|
925
924
|
RUBY
|
926
925
|
|
927
|
-
assert_source <<-RUBY
|
926
|
+
assert_source <<-'RUBY'
|
928
927
|
module SomeNameSpace::TestModule
|
929
928
|
end # SomeNameSpace::TestModule
|
930
929
|
RUBY
|
931
930
|
|
932
|
-
assert_source <<-RUBY
|
931
|
+
assert_source <<-'RUBY'
|
933
932
|
module Some::Name::Space::TestModule
|
934
933
|
end # Some::Name::Space::TestModule
|
935
934
|
RUBY
|
936
935
|
|
937
|
-
assert_source <<-RUBY
|
936
|
+
assert_source <<-'RUBY'
|
938
937
|
module TestModule
|
939
938
|
def foo
|
940
939
|
:bar
|
@@ -964,23 +963,23 @@ describe Unparser do
|
|
964
963
|
end
|
965
964
|
|
966
965
|
context 'defined?' do
|
967
|
-
assert_source <<-RUBY
|
966
|
+
assert_source <<-'RUBY'
|
968
967
|
defined?(@foo)
|
969
968
|
RUBY
|
970
969
|
|
971
|
-
assert_source <<-RUBY
|
970
|
+
assert_source <<-'RUBY'
|
972
971
|
defined?(Foo)
|
973
972
|
RUBY
|
974
973
|
end
|
975
974
|
end
|
976
975
|
|
977
976
|
context 'lambda' do
|
978
|
-
assert_source <<-RUBY
|
977
|
+
assert_source <<-'RUBY'
|
979
978
|
lambda do
|
980
979
|
end
|
981
980
|
RUBY
|
982
981
|
|
983
|
-
assert_source <<-RUBY
|
982
|
+
assert_source <<-'RUBY'
|
984
983
|
lambda do |a, b|
|
985
984
|
a
|
986
985
|
end
|
@@ -988,11 +987,11 @@ describe Unparser do
|
|
988
987
|
end
|
989
988
|
|
990
989
|
context 'match operators' do
|
991
|
-
assert_source <<-RUBY
|
990
|
+
assert_source <<-'RUBY'
|
992
991
|
/bar/ =~ foo
|
993
992
|
RUBY
|
994
993
|
|
995
|
-
assert_source <<-RUBY
|
994
|
+
assert_source <<-'RUBY'
|
996
995
|
foo =~ /bar/
|
997
996
|
RUBY
|
998
997
|
end
|
@@ -1023,7 +1022,7 @@ describe Unparser do
|
|
1023
1022
|
assert_source 'a || (b || c)'
|
1024
1023
|
end
|
1025
1024
|
|
1026
|
-
{ :
|
1025
|
+
{ or: :'||', and: :'&&' }.each do |word, symbol|
|
1027
1026
|
assert_generates "a #{word} break foo", "a #{symbol} (break(foo))"
|
1028
1027
|
assert_generates "a #{word} next foo", "a #{symbol} (next(foo))"
|
1029
1028
|
end
|
@@ -1045,7 +1044,7 @@ describe Unparser do
|
|
1045
1044
|
|
1046
1045
|
context 'flip flops' do
|
1047
1046
|
context 'inclusive' do
|
1048
|
-
assert_source <<-RUBY
|
1047
|
+
assert_source <<-'RUBY'
|
1049
1048
|
if (i == 4)..(i == 4)
|
1050
1049
|
foo
|
1051
1050
|
end
|
@@ -1053,7 +1052,7 @@ describe Unparser do
|
|
1053
1052
|
end
|
1054
1053
|
|
1055
1054
|
context 'exclusive' do
|
1056
|
-
assert_source <<-RUBY
|
1055
|
+
assert_source <<-'RUBY'
|
1057
1056
|
if (i == 4)...(i == 4)
|
1058
1057
|
foo
|
1059
1058
|
end
|
@@ -1062,7 +1061,7 @@ describe Unparser do
|
|
1062
1061
|
end
|
1063
1062
|
|
1064
1063
|
context 'case statement' do
|
1065
|
-
assert_source <<-RUBY
|
1064
|
+
assert_source <<-'RUBY'
|
1066
1065
|
case
|
1067
1066
|
when bar
|
1068
1067
|
baz
|
@@ -1071,7 +1070,7 @@ describe Unparser do
|
|
1071
1070
|
end
|
1072
1071
|
RUBY
|
1073
1072
|
|
1074
|
-
assert_source <<-RUBY
|
1073
|
+
assert_source <<-'RUBY'
|
1075
1074
|
case foo
|
1076
1075
|
when bar
|
1077
1076
|
when baz
|
@@ -1079,8 +1078,7 @@ describe Unparser do
|
|
1079
1078
|
end
|
1080
1079
|
RUBY
|
1081
1080
|
|
1082
|
-
|
1083
|
-
assert_source <<-RUBY
|
1081
|
+
assert_source <<-'RUBY'
|
1084
1082
|
case foo
|
1085
1083
|
when bar
|
1086
1084
|
baz
|
@@ -1089,21 +1087,21 @@ describe Unparser do
|
|
1089
1087
|
end
|
1090
1088
|
RUBY
|
1091
1089
|
|
1092
|
-
assert_source <<-RUBY
|
1090
|
+
assert_source <<-'RUBY'
|
1093
1091
|
case foo
|
1094
1092
|
when bar, baz
|
1095
1093
|
:other
|
1096
1094
|
end
|
1097
1095
|
RUBY
|
1098
1096
|
|
1099
|
-
assert_source <<-RUBY
|
1097
|
+
assert_source <<-'RUBY'
|
1100
1098
|
case foo
|
1101
1099
|
when *bar
|
1102
1100
|
:value
|
1103
1101
|
end
|
1104
1102
|
RUBY
|
1105
1103
|
|
1106
|
-
assert_source <<-RUBY
|
1104
|
+
assert_source <<-'RUBY'
|
1107
1105
|
case foo
|
1108
1106
|
when bar
|
1109
1107
|
baz
|
@@ -1114,19 +1112,19 @@ describe Unparser do
|
|
1114
1112
|
end
|
1115
1113
|
|
1116
1114
|
context 'for' do
|
1117
|
-
assert_source <<-RUBY
|
1115
|
+
assert_source <<-'RUBY'
|
1118
1116
|
for a in bar do
|
1119
1117
|
baz
|
1120
1118
|
end
|
1121
1119
|
RUBY
|
1122
1120
|
|
1123
|
-
assert_source <<-RUBY
|
1121
|
+
assert_source <<-'RUBY'
|
1124
1122
|
for a, *b in bar do
|
1125
1123
|
baz
|
1126
1124
|
end
|
1127
1125
|
RUBY
|
1128
1126
|
|
1129
|
-
assert_source <<-RUBY
|
1127
|
+
assert_source <<-'RUBY'
|
1130
1128
|
for a, b in bar do
|
1131
1129
|
baz
|
1132
1130
|
end
|
@@ -1143,7 +1141,7 @@ describe Unparser do
|
|
1143
1141
|
end
|
1144
1142
|
|
1145
1143
|
context 'loop' do
|
1146
|
-
assert_source <<-RUBY
|
1144
|
+
assert_source <<-'RUBY'
|
1147
1145
|
loop do
|
1148
1146
|
foo
|
1149
1147
|
end
|
@@ -1151,20 +1149,20 @@ describe Unparser do
|
|
1151
1149
|
end
|
1152
1150
|
|
1153
1151
|
context 'post conditions' do
|
1154
|
-
assert_source <<-RUBY
|
1152
|
+
assert_source <<-'RUBY'
|
1155
1153
|
begin
|
1156
1154
|
foo
|
1157
1155
|
end while baz
|
1158
1156
|
RUBY
|
1159
1157
|
|
1160
|
-
assert_source <<-RUBY
|
1158
|
+
assert_source <<-'RUBY'
|
1161
1159
|
begin
|
1162
1160
|
foo
|
1163
1161
|
bar
|
1164
1162
|
end until baz
|
1165
1163
|
RUBY
|
1166
1164
|
|
1167
|
-
assert_source <<-RUBY
|
1165
|
+
assert_source <<-'RUBY'
|
1168
1166
|
begin
|
1169
1167
|
foo
|
1170
1168
|
bar
|
@@ -1173,12 +1171,12 @@ describe Unparser do
|
|
1173
1171
|
end
|
1174
1172
|
|
1175
1173
|
context 'while' do
|
1176
|
-
assert_source <<-RUBY
|
1174
|
+
assert_source <<-'RUBY'
|
1177
1175
|
while false
|
1178
1176
|
end
|
1179
1177
|
RUBY
|
1180
1178
|
|
1181
|
-
assert_source <<-RUBY
|
1179
|
+
assert_source <<-'RUBY'
|
1182
1180
|
while false
|
1183
1181
|
3
|
1184
1182
|
end
|
@@ -1186,12 +1184,12 @@ describe Unparser do
|
|
1186
1184
|
end
|
1187
1185
|
|
1188
1186
|
context 'until' do
|
1189
|
-
assert_source <<-RUBY
|
1187
|
+
assert_source <<-'RUBY'
|
1190
1188
|
until false
|
1191
1189
|
end
|
1192
1190
|
RUBY
|
1193
1191
|
|
1194
|
-
assert_source <<-RUBY
|
1192
|
+
assert_source <<-'RUBY'
|
1195
1193
|
until false
|
1196
1194
|
3
|
1197
1195
|
end
|
@@ -1199,16 +1197,16 @@ describe Unparser do
|
|
1199
1197
|
end
|
1200
1198
|
|
1201
1199
|
context 'comments' do
|
1202
|
-
assert_source <<-RUBY
|
1200
|
+
assert_source <<-'RUBY'
|
1203
1201
|
# comment before
|
1204
1202
|
a_line_of_code
|
1205
1203
|
RUBY
|
1206
1204
|
|
1207
|
-
assert_source <<-RUBY
|
1205
|
+
assert_source <<-'RUBY'
|
1208
1206
|
a_line_of_code # comment after
|
1209
1207
|
RUBY
|
1210
1208
|
|
1211
|
-
assert_source <<-RUBY
|
1209
|
+
assert_source <<-'RUBY'
|
1212
1210
|
nested do # first
|
1213
1211
|
# second
|
1214
1212
|
something # comment
|
@@ -1217,13 +1215,13 @@ describe Unparser do
|
|
1217
1215
|
# last
|
1218
1216
|
RUBY
|
1219
1217
|
|
1220
|
-
assert_source <<-RUBY
|
1218
|
+
assert_source <<-'RUBY'
|
1221
1219
|
def noop
|
1222
1220
|
# do nothing
|
1223
1221
|
end
|
1224
1222
|
RUBY
|
1225
1223
|
|
1226
|
-
assert_source <<-RUBY
|
1224
|
+
assert_source <<-'RUBY'
|
1227
1225
|
=begin
|
1228
1226
|
block comment
|
1229
1227
|
=end
|
@@ -1238,20 +1236,22 @@ describe Unparser do
|
|
1238
1236
|
end
|
1239
1237
|
RUBY
|
1240
1238
|
|
1241
|
-
assert_generates(<<-RUBY, <<-RUBY)
|
1239
|
+
assert_generates(<<-'RUBY', <<-'RUBY')
|
1242
1240
|
1 + # first
|
1243
1241
|
2 # second
|
1244
1242
|
RUBY
|
1245
1243
|
1 + 2 # first # second
|
1246
1244
|
RUBY
|
1247
|
-
|
1245
|
+
|
1246
|
+
assert_generates(<<-'RUBY', <<-'RUBY')
|
1248
1247
|
1 +
|
1249
1248
|
# first
|
1250
1249
|
2 # second
|
1251
1250
|
RUBY
|
1252
1251
|
1 + 2 # first # second
|
1253
1252
|
RUBY
|
1254
|
-
|
1253
|
+
|
1254
|
+
assert_generates(<<-'RUBY', <<-'RUBY')
|
1255
1255
|
1 +
|
1256
1256
|
=begin
|
1257
1257
|
block comment
|
@@ -1263,6 +1263,7 @@ describe Unparser do
|
|
1263
1263
|
block comment
|
1264
1264
|
=end
|
1265
1265
|
RUBY
|
1266
|
+
|
1266
1267
|
end
|
1267
1268
|
end
|
1268
1269
|
end
|