ruby2ruby 2.4.2 → 2.4.3
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +13 -5
- data/lib/ruby2ruby.rb +120 -110
- data/test/test_ruby2ruby.rb +64 -17
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f72338e1430e938dcc3c0934ecef41cd7a1a589d8c67cde7419f05b9eb8b247
|
4
|
+
data.tar.gz: 2be6fc2a82fe2ca73fe59d9025ba6c3734d7571dcc867f2e3da800537cf71758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9fe4523da05005533346ba4ba1806e3f1ba22c7d36faff48623d7827b108d4dc195ae77bf3124369fed874b28229cefcbfcc00d9c2596b7a638b2931d8f5c9
|
7
|
+
data.tar.gz: 314e0287a424263e3f05e013d06bde2e8f9c9b9dd3b69ce1d9c9358c820f23571c5a66cdd621200ff0315c25082886ef124f870f9fb9d38d403d607b2b77d747
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
-
=== 4.
|
1
|
+
=== 2.4.3 / 2019-06-03
|
2
2
|
|
3
|
-
*
|
3
|
+
* 4 bug fixes:
|
4
|
+
|
5
|
+
* Added shadow block args. (jaynetics)
|
6
|
+
* Fixed generation for block args w/ trailing commas.
|
7
|
+
* Fixed nested masgn block args and arrays. (jaynetics)
|
8
|
+
* Fixes for stabby proc / lambda changes.
|
9
|
+
|
10
|
+
=== 2.4.2 / 2019-03-12
|
11
|
+
|
12
|
+
* 2 bug fixes:
|
4
13
|
|
5
|
-
*
|
6
|
-
*
|
7
|
-
* Use concat internally instead of splat. Some people have 20000 node sexps! (presidentbeef)
|
14
|
+
* Rewrote process_masgn to fix problems with nesting masgn in block args.
|
15
|
+
* Use RubyParser directly instead of versioned parsers.
|
8
16
|
|
9
17
|
=== 2.4.1 / 2018-02-15
|
10
18
|
|
data/lib/ruby2ruby.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rubygems"
|
4
|
+
require "sexp_processor"
|
5
5
|
|
6
6
|
# :stopdoc:
|
7
7
|
# REFACTOR: stolen from ruby_parser
|
@@ -15,13 +15,13 @@ class Regexp
|
|
15
15
|
|
16
16
|
unless defined? CODES then
|
17
17
|
CODES = {
|
18
|
-
EXTENDED =>
|
19
|
-
IGNORECASE =>
|
20
|
-
MULTILINE =>
|
21
|
-
ENC_NONE =>
|
22
|
-
ENC_EUC =>
|
23
|
-
ENC_SJIS =>
|
24
|
-
ENC_UTF8 =>
|
18
|
+
EXTENDED => "x",
|
19
|
+
IGNORECASE => "i",
|
20
|
+
MULTILINE => "m",
|
21
|
+
ENC_NONE => "n",
|
22
|
+
ENC_EUC => "e",
|
23
|
+
ENC_SJIS => "s",
|
24
|
+
ENC_UTF8 => "u",
|
25
25
|
}
|
26
26
|
end
|
27
27
|
end
|
@@ -31,13 +31,13 @@ end
|
|
31
31
|
# Generate ruby code from a sexp.
|
32
32
|
|
33
33
|
class Ruby2Ruby < SexpProcessor
|
34
|
-
VERSION = "2.4.
|
34
|
+
VERSION = "2.4.3" # :nodoc:
|
35
35
|
|
36
36
|
# cutoff for one-liners
|
37
37
|
LINE_LENGTH = 78
|
38
38
|
|
39
39
|
# binary operation messages
|
40
|
-
BINARY = [:<=>, :==, :<, :>, :<=, :>=, :-, :+, :*, :/, :%, :<<, :>>, :**, :
|
40
|
+
BINARY = [:<=>, :==, :<, :>, :<=, :>=, :-, :+, :*, :/, :%, :<<, :>>, :**, :"!=", :^, :|, :&]
|
41
41
|
|
42
42
|
##
|
43
43
|
# Nodes that represent assignment and probably need () around them.
|
@@ -76,7 +76,7 @@ class Ruby2Ruby < SexpProcessor
|
|
76
76
|
:lvar,
|
77
77
|
:nil,
|
78
78
|
:str,
|
79
|
-
:true
|
79
|
+
:true,
|
80
80
|
]
|
81
81
|
|
82
82
|
def initialize # :nodoc:
|
@@ -118,6 +118,8 @@ class Ruby2Ruby < SexpProcessor
|
|
118
118
|
def process_args exp # :nodoc:
|
119
119
|
_, *args = exp
|
120
120
|
|
121
|
+
shadow = []
|
122
|
+
|
121
123
|
args = args.map { |arg|
|
122
124
|
case arg
|
123
125
|
when Symbol then
|
@@ -131,15 +133,24 @@ class Ruby2Ruby < SexpProcessor
|
|
131
133
|
when :kwarg then
|
132
134
|
_, k, v = arg
|
133
135
|
"#{k}: #{process v}"
|
136
|
+
when :shadow then
|
137
|
+
shadow << arg[1]
|
138
|
+
next
|
134
139
|
else
|
135
140
|
raise "unknown arg type #{arg.first.inspect}"
|
136
141
|
end
|
142
|
+
when nil then
|
143
|
+
""
|
137
144
|
else
|
138
145
|
raise "unknown arg type #{arg.inspect}"
|
139
146
|
end
|
140
|
-
}
|
147
|
+
}.compact
|
148
|
+
|
149
|
+
args = args.join(", ").strip
|
150
|
+
shadow = shadow.join(", ").strip
|
151
|
+
shadow = "; #{shadow}" unless shadow.empty?
|
141
152
|
|
142
|
-
"(
|
153
|
+
"(%s%s)" % [args, shadow]
|
143
154
|
end
|
144
155
|
|
145
156
|
def process_array exp # :nodoc:
|
@@ -180,7 +191,7 @@ class Ruby2Ruby < SexpProcessor
|
|
180
191
|
|
181
192
|
code = rest.map { |sexp|
|
182
193
|
src = process sexp
|
183
|
-
src = indent src unless src =~
|
194
|
+
src = indent src unless src =~ /(^|\n)(rescue|ensure)/ # ensure no level 0 rescues
|
184
195
|
src
|
185
196
|
}
|
186
197
|
code.unshift "begin"
|
@@ -238,7 +249,7 @@ class Ruby2Ruby < SexpProcessor
|
|
238
249
|
@calls.push name
|
239
250
|
|
240
251
|
in_context :arglist do
|
241
|
-
max = args.size-1
|
252
|
+
max = args.size - 1
|
242
253
|
args = args.map.with_index { |arg, i|
|
243
254
|
arg_type = arg.sexp_type
|
244
255
|
is_empty_hash = arg == s(:hash)
|
@@ -249,7 +260,7 @@ class Ruby2Ruby < SexpProcessor
|
|
249
260
|
strip_hash = (arg_type == :hash and
|
250
261
|
not BINARY.include? name and
|
251
262
|
not is_empty_hash and
|
252
|
-
(i == max or args[i+1].sexp_type == :splat))
|
263
|
+
(i == max or args[i + 1].sexp_type == :splat))
|
253
264
|
wrap_arg = Ruby2Ruby::ASSIGN_NODES.include? arg_type
|
254
265
|
|
255
266
|
arg = arg[2..-3] if strip_hash
|
@@ -262,19 +273,19 @@ class Ruby2Ruby < SexpProcessor
|
|
262
273
|
case name
|
263
274
|
when *BINARY then
|
264
275
|
if safe_call
|
265
|
-
"#{receiver}&.#{name}(#{args.join(
|
276
|
+
"#{receiver}&.#{name}(#{args.join(", ")})"
|
266
277
|
elsif args.length > 1
|
267
|
-
"#{receiver}.#{name}(#{args.join(
|
278
|
+
"#{receiver}.#{name}(#{args.join(", ")})"
|
268
279
|
else
|
269
|
-
"(#{receiver} #{name} #{args.join(
|
280
|
+
"(#{receiver} #{name} #{args.join(", ")})"
|
270
281
|
end
|
271
282
|
when :[] then
|
272
283
|
receiver ||= "self"
|
273
|
-
"#{receiver}[#{args.join(
|
284
|
+
"#{receiver}[#{args.join(", ")}]"
|
274
285
|
when :[]= then
|
275
286
|
receiver ||= "self"
|
276
287
|
rhs = args.pop
|
277
|
-
"#{receiver}[#{args.join(
|
288
|
+
"#{receiver}[#{args.join(", ")}] = #{rhs}"
|
278
289
|
when :"!" then
|
279
290
|
"(not #{receiver})"
|
280
291
|
when :"-@" then
|
@@ -283,7 +294,7 @@ class Ruby2Ruby < SexpProcessor
|
|
283
294
|
"+#{receiver}"
|
284
295
|
else
|
285
296
|
args = nil if args.empty?
|
286
|
-
args = "(#{args.join(
|
297
|
+
args = "(#{args.join(", ")})" if args
|
287
298
|
receiver = "#{receiver}." if receiver and not safe_call
|
288
299
|
receiver = "#{receiver}&." if receiver and safe_call
|
289
300
|
|
@@ -304,11 +315,11 @@ class Ruby2Ruby < SexpProcessor
|
|
304
315
|
|
305
316
|
expr = process expr
|
306
317
|
|
307
|
-
if expr then
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
318
|
+
result << if expr then
|
319
|
+
"case #{expr}"
|
320
|
+
else
|
321
|
+
"case"
|
322
|
+
end
|
312
323
|
|
313
324
|
result.concat rest.map { |pt|
|
314
325
|
if pt and pt.sexp_type == :when
|
@@ -416,7 +427,7 @@ class Ruby2Ruby < SexpProcessor
|
|
416
427
|
simple && body =~ /^\Abegin/ && body =~ /^end\z/
|
417
428
|
body = indent(body) unless simple && body =~ /(^|\n)rescue/
|
418
429
|
|
419
|
-
|
430
|
+
"#{comm}def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
|
420
431
|
end
|
421
432
|
|
422
433
|
def process_defs exp # :nodoc:
|
@@ -475,10 +486,10 @@ class Ruby2Ruby < SexpProcessor
|
|
475
486
|
ens = process(ens) || "# do nothing"
|
476
487
|
ens = "begin\n#{ens}\nend\n" if ens =~ /(^|\n)rescue/
|
477
488
|
|
478
|
-
body.sub!(/\n\s*end\z/,
|
489
|
+
body.sub!(/\n\s*end\z/, "")
|
479
490
|
body = indent(body) unless body =~ /(^|\n)rescue/
|
480
491
|
|
481
|
-
|
492
|
+
"#{body}\nensure\n#{indent ens}"
|
482
493
|
end
|
483
494
|
|
484
495
|
def process_evstr exp # :nodoc:
|
@@ -530,8 +541,6 @@ class Ruby2Ruby < SexpProcessor
|
|
530
541
|
def process_hash(exp) # :nodoc:
|
531
542
|
_, *pairs = exp
|
532
543
|
|
533
|
-
result = []
|
534
|
-
|
535
544
|
result = pairs.each_slice(2).map { |k, v|
|
536
545
|
if k.sexp_type == :kwsplat then
|
537
546
|
"%s" % process(k)
|
@@ -546,7 +555,7 @@ class Ruby2Ruby < SexpProcessor
|
|
546
555
|
end
|
547
556
|
}
|
548
557
|
|
549
|
-
|
558
|
+
result.empty? ? "{}" : "{ #{result.join(", ")} }"
|
550
559
|
end
|
551
560
|
|
552
561
|
def process_iasgn(exp) # :nodoc:
|
@@ -577,7 +586,7 @@ class Ruby2Ruby < SexpProcessor
|
|
577
586
|
else
|
578
587
|
r = "#{t} if #{c}"
|
579
588
|
end
|
580
|
-
return r if r and (@indent+r).size < LINE_LENGTH and r !~ /\n/
|
589
|
+
return r if r and (@indent + r).size < LINE_LENGTH and r !~ /\n/
|
581
590
|
end
|
582
591
|
|
583
592
|
r = "if #{c} then\n#{indent(t)}\n"
|
@@ -588,52 +597,74 @@ class Ruby2Ruby < SexpProcessor
|
|
588
597
|
elsif f
|
589
598
|
unless expand then
|
590
599
|
r = "#{f} unless #{c}"
|
591
|
-
return r if (@indent+r).size < LINE_LENGTH and r !~ /\n/
|
600
|
+
return r if (@indent + r).size < LINE_LENGTH and r !~ /\n/
|
592
601
|
end
|
593
602
|
"unless #{c} then\n#{indent(f)}\nend"
|
594
603
|
else
|
595
604
|
# empty if statement, just do it in case of side effects from condition
|
596
|
-
"if #{c} then\n#{indent
|
605
|
+
"if #{c} then\n#{indent "# do nothing"}\nend"
|
597
606
|
end
|
598
607
|
end
|
599
608
|
|
609
|
+
def process_lambda exp # :nodoc:
|
610
|
+
"->"
|
611
|
+
end
|
612
|
+
|
600
613
|
def process_iter(exp) # :nodoc:
|
601
614
|
_, iter, args, body = exp
|
602
615
|
|
616
|
+
is_lambda = iter.sexp_type == :lambda
|
617
|
+
|
603
618
|
iter = process iter
|
604
619
|
body = process body if body
|
605
620
|
|
606
|
-
args = case
|
607
|
-
when 0 then
|
621
|
+
args = case
|
622
|
+
when args == 0 then
|
608
623
|
""
|
624
|
+
when is_lambda then
|
625
|
+
" (#{process(args)[1..-2]})"
|
609
626
|
else
|
610
627
|
" |#{process(args)[1..-2]}|"
|
611
628
|
end
|
612
629
|
|
613
630
|
b, e = if iter == "END" then
|
614
|
-
[
|
631
|
+
%w[ { } ]
|
615
632
|
else
|
616
|
-
[
|
633
|
+
%w[ do end ]
|
617
634
|
end
|
618
635
|
|
619
|
-
iter.sub!(/\(\)$/,
|
636
|
+
iter.sub!(/\(\)$/, "")
|
620
637
|
|
621
638
|
# REFACTOR: ugh
|
622
639
|
result = []
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
result << "
|
640
|
+
if is_lambda then
|
641
|
+
result << iter
|
642
|
+
result << args
|
643
|
+
result << " {"
|
627
644
|
else
|
628
|
-
result <<
|
645
|
+
result << "#{iter} {"
|
646
|
+
result << args
|
629
647
|
end
|
648
|
+
result << if body then
|
649
|
+
" #{body.strip} "
|
650
|
+
else
|
651
|
+
" "
|
652
|
+
end
|
630
653
|
result << "}"
|
631
654
|
result = result.join
|
632
655
|
return result if result !~ /\n/ and result.size < LINE_LENGTH
|
633
656
|
|
634
657
|
result = []
|
635
|
-
|
636
|
-
|
658
|
+
|
659
|
+
if is_lambda then
|
660
|
+
result << iter
|
661
|
+
result << args
|
662
|
+
result << " #{b}"
|
663
|
+
else
|
664
|
+
result << "#{iter} #{b}"
|
665
|
+
result << args
|
666
|
+
end
|
667
|
+
|
637
668
|
result << "\n"
|
638
669
|
if body then
|
639
670
|
result << indent(body.strip)
|
@@ -677,43 +708,28 @@ class Ruby2Ruby < SexpProcessor
|
|
677
708
|
end
|
678
709
|
|
679
710
|
def process_masgn(exp) # :nodoc:
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
case
|
686
|
-
when
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
when :array then # a, b = [c, d]
|
693
|
-
process(rhs)[1..-2]
|
694
|
-
else # a, b = c
|
695
|
-
process rhs
|
696
|
-
end
|
697
|
-
"%s = %s" % [lhs.join(", "), rhs]
|
698
|
-
when 2 then # a, (b, c) = ...
|
699
|
-
"(%s)" % [process(lhs)[1..-2]]
|
700
|
-
else
|
701
|
-
raise "unknown masgn length: %p" % [exp]
|
702
|
-
end
|
703
|
-
else # a { |(b, c)| ... }
|
704
|
-
lhs = exp.sexp_body.map { |e|
|
705
|
-
case e
|
706
|
-
when Symbol then
|
707
|
-
e
|
708
|
-
when Sexp then
|
709
|
-
process e
|
711
|
+
# s(:masgn, s(:array, s(:lasgn, :var), ...), s(:to_ary, <val>, ...))
|
712
|
+
# s(:iter, <call>, s(:args, s(:masgn, :a, :b)), <body>)
|
713
|
+
parenthesize = true
|
714
|
+
|
715
|
+
result = exp.sexp_body.map { |sexp|
|
716
|
+
case sexp
|
717
|
+
when Sexp then
|
718
|
+
if sexp.sexp_type == :array then
|
719
|
+
parenthesize = context.grep(:masgn).size > 1
|
720
|
+
res = process sexp
|
721
|
+
|
722
|
+
res[1..-2]
|
710
723
|
else
|
711
|
-
|
724
|
+
process sexp
|
712
725
|
end
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
726
|
+
when Symbol then
|
727
|
+
sexp
|
728
|
+
else
|
729
|
+
raise "unknown masgn: #{sexp.inspect}"
|
730
|
+
end
|
731
|
+
}
|
732
|
+
parenthesize ? "(#{result.join ", "})" : result.join(" = ")
|
717
733
|
end
|
718
734
|
|
719
735
|
def process_match exp # :nodoc:
|
@@ -811,14 +827,14 @@ class Ruby2Ruby < SexpProcessor
|
|
811
827
|
# a &&= 1
|
812
828
|
# [[:lvar, :a], [:lasgn, :a, [:lit, 1]]]
|
813
829
|
_, _lhs, rhs = exp
|
814
|
-
process(rhs).sub(/\=/,
|
830
|
+
process(rhs).sub(/\=/, "&&=")
|
815
831
|
end
|
816
832
|
|
817
833
|
def process_op_asgn_or(exp) # :nodoc:
|
818
834
|
# a ||= 1
|
819
835
|
# [[:lvar, :a], [:lasgn, :a, [:lit, 1]]]
|
820
836
|
_, _lhs, rhs = exp
|
821
|
-
process(rhs).sub(/\=/,
|
837
|
+
process(rhs).sub(/\=/, "||=")
|
822
838
|
end
|
823
839
|
|
824
840
|
def process_or(exp) # :nodoc:
|
@@ -856,10 +872,9 @@ class Ruby2Ruby < SexpProcessor
|
|
856
872
|
|
857
873
|
def process_rescue exp # :nodoc:
|
858
874
|
_, *rest = exp
|
859
|
-
exp = nil
|
860
875
|
|
861
876
|
body = process rest.shift unless rest.first.sexp_type == :resbody
|
862
|
-
els = process rest.pop unless rest.last && rest.last.sexp_type
|
877
|
+
els = process rest.pop unless rest.last && rest.last.sexp_type == :resbody
|
863
878
|
|
864
879
|
body ||= "# do nothing"
|
865
880
|
|
@@ -878,7 +893,7 @@ class Ruby2Ruby < SexpProcessor
|
|
878
893
|
if els then
|
879
894
|
"#{indent body}\n#{resbodies.join("\n")}\nelse\n#{indent els}"
|
880
895
|
elsif simple then
|
881
|
-
resbody = resbodies.first.sub(/\n\s*/,
|
896
|
+
resbody = resbodies.first.sub(/\n\s*/, " ")
|
882
897
|
"#{body} #{resbody}"
|
883
898
|
else
|
884
899
|
"#{indent body}\n#{resbodies.join("\n")}"
|
@@ -911,7 +926,7 @@ class Ruby2Ruby < SexpProcessor
|
|
911
926
|
|
912
927
|
raise "dunno what to do: #{args.inspect}" if args
|
913
928
|
|
914
|
-
name = name.to_s.sub(/=$/,
|
929
|
+
name = name.to_s.sub(/=$/, "")
|
915
930
|
|
916
931
|
if rhs && rhs != s(:arglist) then
|
917
932
|
"#{receiver}&.#{name} = #{process rhs}"
|
@@ -1004,7 +1019,7 @@ class Ruby2Ruby < SexpProcessor
|
|
1004
1019
|
end
|
1005
1020
|
|
1006
1021
|
def process_until(exp) # :nodoc:
|
1007
|
-
cond_loop(exp,
|
1022
|
+
cond_loop(exp, "until")
|
1008
1023
|
end
|
1009
1024
|
|
1010
1025
|
def process_valias exp # :nodoc:
|
@@ -1048,7 +1063,7 @@ class Ruby2Ruby < SexpProcessor
|
|
1048
1063
|
}
|
1049
1064
|
|
1050
1065
|
unless args.empty? then
|
1051
|
-
"yield(#{args.join(
|
1066
|
+
"yield(#{args.join(", ")})"
|
1052
1067
|
else
|
1053
1068
|
"yield"
|
1054
1069
|
end
|
@@ -1209,7 +1224,7 @@ class Ruby2Ruby < SexpProcessor
|
|
1209
1224
|
# Wrap appropriate expressions in matching parens.
|
1210
1225
|
|
1211
1226
|
def parenthesize exp
|
1212
|
-
case
|
1227
|
+
case context[1]
|
1213
1228
|
when nil, :defn, :defs, :class, :sclass, :if, :iter, :resbody, :when, :while then
|
1214
1229
|
exp
|
1215
1230
|
else
|
@@ -1243,18 +1258,13 @@ class Ruby2Ruby < SexpProcessor
|
|
1243
1258
|
str = dthing_escape(type, str)
|
1244
1259
|
|
1245
1260
|
rest = rest.map { |pt|
|
1246
|
-
case pt
|
1247
|
-
when
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
when :evstr then
|
1252
|
-
'#{%s}' % [process(pt)]
|
1253
|
-
else
|
1254
|
-
raise "unknown type: #{pt.inspect}"
|
1255
|
-
end
|
1261
|
+
case pt.sexp_type
|
1262
|
+
when :str then
|
1263
|
+
dthing_escape(type, pt.last)
|
1264
|
+
when :evstr then
|
1265
|
+
'#{%s}' % [process(pt)]
|
1256
1266
|
else
|
1257
|
-
raise "
|
1267
|
+
raise "unknown type: #{pt.inspect}"
|
1258
1268
|
end
|
1259
1269
|
}
|
1260
1270
|
|
@@ -1264,7 +1274,7 @@ class Ruby2Ruby < SexpProcessor
|
|
1264
1274
|
##
|
1265
1275
|
# Utility method to generate ether a module or class.
|
1266
1276
|
|
1267
|
-
def util_module_or_class
|
1277
|
+
def util_module_or_class exp, is_class = false
|
1268
1278
|
result = []
|
1269
1279
|
|
1270
1280
|
_, name, *body = exp
|
@@ -1285,11 +1295,11 @@ class Ruby2Ruby < SexpProcessor
|
|
1285
1295
|
process(sexp).chomp
|
1286
1296
|
}
|
1287
1297
|
|
1288
|
-
unless body.empty? then
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1298
|
+
body = unless body.empty? then
|
1299
|
+
indent(body.join("\n\n")) + "\n"
|
1300
|
+
else
|
1301
|
+
""
|
1302
|
+
end
|
1293
1303
|
|
1294
1304
|
result << body
|
1295
1305
|
result << "end"
|
data/test/test_ruby2ruby.rb
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
|
-
$: <<
|
5
|
+
$: << "lib"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "ruby2ruby"
|
9
|
+
require "pt_testcase"
|
10
|
+
require "fileutils"
|
11
|
+
require "tmpdir"
|
12
|
+
require "ruby_parser" if ENV["CHECK_SEXPS"]
|
13
13
|
|
14
14
|
class R2RTestCase < ParseTreeTestCase
|
15
15
|
def self.previous key
|
16
16
|
"ParseTree"
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.generate_test klass, node, data, input_name,
|
20
|
-
output_name = data.
|
19
|
+
def self.generate_test klass, node, data, input_name, _output_name
|
20
|
+
output_name = data.key?("Ruby2Ruby") ? "Ruby2Ruby" : "Ruby"
|
21
21
|
|
22
22
|
klass.class_eval <<-EOM
|
23
23
|
def test_#{node}
|
@@ -170,7 +170,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
170
170
|
assert_equal exp, Ruby2Ruby.new.process(sexp)
|
171
171
|
end
|
172
172
|
|
173
|
-
def assert_rt src, exp=src.dup
|
173
|
+
def assert_rt src, exp = src.dup
|
174
174
|
assert_equal exp, Ruby2Ruby.new.process(RubyParser.new.parse(src))
|
175
175
|
end
|
176
176
|
|
@@ -297,7 +297,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
297
297
|
def test_attr_writer_same
|
298
298
|
do_not_check_sexp!
|
299
299
|
|
300
|
-
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same
|
300
|
+
inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same, s(:lvar, :o)))
|
301
301
|
out = "attr_writer :same"
|
302
302
|
assert_parse inn, out
|
303
303
|
end
|
@@ -443,6 +443,17 @@ class TestRuby2Ruby < R2RTestCase
|
|
443
443
|
assert_parse inn, out
|
444
444
|
end
|
445
445
|
|
446
|
+
def test_shadow_block_args
|
447
|
+
inn = s(:iter,
|
448
|
+
s(:call, nil, :a),
|
449
|
+
s(:args,
|
450
|
+
s(:shadow, :b),
|
451
|
+
s(:shadow, :c)))
|
452
|
+
out = 'a { |; b, c| }'
|
453
|
+
|
454
|
+
assert_parse inn, out
|
455
|
+
end
|
456
|
+
|
446
457
|
def test_masgn_block_arg
|
447
458
|
inn = s(:iter,
|
448
459
|
s(:call,
|
@@ -458,6 +469,42 @@ class TestRuby2Ruby < R2RTestCase
|
|
458
469
|
assert_parse inn, out
|
459
470
|
end
|
460
471
|
|
472
|
+
def test_single_nested_masgn_block_arg
|
473
|
+
inn = s(:iter,
|
474
|
+
s(:call, nil, :a),
|
475
|
+
s(:args,
|
476
|
+
s(:masgn,
|
477
|
+
s(:masgn,
|
478
|
+
s(:masgn, :b)))))
|
479
|
+
out = "a { |(((b)))| }"
|
480
|
+
|
481
|
+
assert_parse inn, out
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_multiple_nested_masgn_block_arg
|
485
|
+
inn = s(:iter,
|
486
|
+
s(:call, nil, :a),
|
487
|
+
s(:args, :b,
|
488
|
+
s(:masgn,
|
489
|
+
s(:masgn, :c, :d),
|
490
|
+
:e,
|
491
|
+
s(:masgn, :f, :g))))
|
492
|
+
out = "a { |b, ((c, d), e, (f, g))| }"
|
493
|
+
|
494
|
+
assert_parse inn, out
|
495
|
+
end
|
496
|
+
|
497
|
+
def test_multiple_nested_masgn_array
|
498
|
+
inn = s(:masgn,
|
499
|
+
s(:array,
|
500
|
+
s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b))),
|
501
|
+
s(:lasgn, :c)),
|
502
|
+
s(:to_ary, s(:call, nil, :fn)))
|
503
|
+
out = "(a, b), c = fn"
|
504
|
+
|
505
|
+
assert_parse inn, out
|
506
|
+
end
|
507
|
+
|
461
508
|
def test_masgn_wtf
|
462
509
|
inn = s(:block,
|
463
510
|
s(:masgn,
|
@@ -516,7 +563,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
516
563
|
:z,
|
517
564
|
s(:lit, 1))
|
518
565
|
|
519
|
-
out ="x&.y&.z(1)"
|
566
|
+
out = "x&.y&.z(1)"
|
520
567
|
assert_parse inn, out
|
521
568
|
end
|
522
569
|
|
@@ -817,10 +864,10 @@ end
|
|
817
864
|
# s
|
818
865
|
# t new 2 3
|
819
866
|
|
820
|
-
tr2r = File.read(__FILE__).split(/\n/)[start+1..__LINE__-2].join("\n")
|
867
|
+
tr2r = File.read(__FILE__).split(/\n/)[start + 1..__LINE__ - 2].join("\n")
|
821
868
|
ir2r = File.read("lib/ruby2ruby.rb")
|
822
869
|
|
823
|
-
require
|
870
|
+
require "ruby_parser"
|
824
871
|
|
825
872
|
def silent_eval ruby
|
826
873
|
old, $-w = $-w, nil
|
@@ -837,9 +884,9 @@ def morph_and_eval src, from, to, processor
|
|
837
884
|
end
|
838
885
|
|
839
886
|
unless ENV["SIMPLE"] then
|
840
|
-
____ = morph_and_eval tr2r, /TestRuby2Ruby/,
|
841
|
-
ruby = morph_and_eval ir2r, /Ruby2Ruby/,
|
842
|
-
____ = morph_and_eval ruby, /Ruby2Ruby2/,
|
887
|
+
____ = morph_and_eval tr2r, /TestRuby2Ruby/, "TestRuby2Ruby2", Ruby2Ruby
|
888
|
+
ruby = morph_and_eval ir2r, /Ruby2Ruby/, "Ruby2Ruby2", Ruby2Ruby
|
889
|
+
____ = morph_and_eval ruby, /Ruby2Ruby2/, "Ruby2Ruby3", Ruby2Ruby2
|
843
890
|
|
844
891
|
class TestRuby2Ruby1 < TestRuby2Ruby
|
845
892
|
def setup
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
Em82dBUFsipwMLCYj39kcyHWAxyl6Ae1Cn9r/ItVBCxoeFdrHjfavnrIEoXUt4bU
|
30
30
|
UfBugfLD19bu3nvL+zTAGx/U
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2019-
|
32
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: sexp_processor
|
metadata.gz.sig
CHANGED
Binary file
|