test/test_ruby2ruby.rb in ruby2ruby-2.4.2 vs test/test_ruby2ruby.rb in ruby2ruby-2.4.3
- old
+ new
@@ -1,25 +1,25 @@
#!/usr/local/bin/ruby -w
$TESTING = true
-$: << 'lib'
+$: << "lib"
-require 'minitest/autorun'
-require 'ruby2ruby'
-require 'pt_testcase'
-require 'fileutils'
-require 'tmpdir'
-require 'ruby_parser' if ENV["CHECK_SEXPS"]
+require "minitest/autorun"
+require "ruby2ruby"
+require "pt_testcase"
+require "fileutils"
+require "tmpdir"
+require "ruby_parser" if ENV["CHECK_SEXPS"]
class R2RTestCase < ParseTreeTestCase
def self.previous key
"ParseTree"
end
- def self.generate_test klass, node, data, input_name, output_name
- output_name = data.has_key?('Ruby2Ruby') ? 'Ruby2Ruby' : 'Ruby'
+ def self.generate_test klass, node, data, input_name, _output_name
+ output_name = data.key?("Ruby2Ruby") ? "Ruby2Ruby" : "Ruby"
klass.class_eval <<-EOM
def test_#{node}
pt = #{data[input_name].inspect}
rb = #{data[output_name].inspect}
@@ -168,11 +168,11 @@
def assert_r2r exp, sexp
assert_equal exp, Ruby2Ruby.new.process(sexp)
end
- def assert_rt src, exp=src.dup
+ def assert_rt src, exp = src.dup
assert_equal exp, Ruby2Ruby.new.process(RubyParser.new.parse(src))
end
def test_bug_033
# gentle reminder to keep some sanity
@@ -295,11 +295,11 @@
end
def test_attr_writer_same
do_not_check_sexp!
- inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same , s(:lvar, :o)))
+ inn = s(:defn, :same=, s(:args, :o), s(:iasgn, :@same, s(:lvar, :o)))
out = "attr_writer :same"
assert_parse inn, out
end
def test_dregx_slash
@@ -441,10 +441,21 @@
out = "def blah\n a = 1\nrescue\n return \"a\"\nend"
assert_parse inn, out
end
+ def test_shadow_block_args
+ inn = s(:iter,
+ s(:call, nil, :a),
+ s(:args,
+ s(:shadow, :b),
+ s(:shadow, :c)))
+ out = 'a { |; b, c| }'
+
+ assert_parse inn, out
+ end
+
def test_masgn_block_arg
inn = s(:iter,
s(:call,
s(:nil),
:x),
@@ -456,10 +467,46 @@
out = 'nil.x { |(a, b)| "#{a}=#{b}" }'
assert_parse inn, out
end
+ def test_single_nested_masgn_block_arg
+ inn = s(:iter,
+ s(:call, nil, :a),
+ s(:args,
+ s(:masgn,
+ s(:masgn,
+ s(:masgn, :b)))))
+ out = "a { |(((b)))| }"
+
+ assert_parse inn, out
+ end
+
+ def test_multiple_nested_masgn_block_arg
+ inn = s(:iter,
+ s(:call, nil, :a),
+ s(:args, :b,
+ s(:masgn,
+ s(:masgn, :c, :d),
+ :e,
+ s(:masgn, :f, :g))))
+ out = "a { |b, ((c, d), e, (f, g))| }"
+
+ assert_parse inn, out
+ end
+
+ def test_multiple_nested_masgn_array
+ inn = s(:masgn,
+ s(:array,
+ s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b))),
+ s(:lasgn, :c)),
+ s(:to_ary, s(:call, nil, :fn)))
+ out = "(a, b), c = fn"
+
+ assert_parse inn, out
+ end
+
def test_masgn_wtf
inn = s(:block,
s(:masgn,
s(:array, s(:lasgn, :k), s(:lasgn, :v)),
s(:splat,
@@ -514,11 +561,11 @@
s(:call, nil, :x),
:y),
:z,
s(:lit, 1))
- out ="x&.y&.z(1)"
+ out = "x&.y&.z(1)"
assert_parse inn, out
end
def test_safe_call_binary
inn = s(:safe_call,
@@ -815,14 +862,14 @@
# t old 0 1
# e
# s
# t new 2 3
-tr2r = File.read(__FILE__).split(/\n/)[start+1..__LINE__-2].join("\n")
+tr2r = File.read(__FILE__).split(/\n/)[start + 1..__LINE__ - 2].join("\n")
ir2r = File.read("lib/ruby2ruby.rb")
-require 'ruby_parser'
+require "ruby_parser"
def silent_eval ruby
old, $-w = $-w, nil
eval ruby
$-w = old
@@ -835,12 +882,12 @@
silent_eval new_src
new_src
end
unless ENV["SIMPLE"] then
- ____ = morph_and_eval tr2r, /TestRuby2Ruby/, 'TestRuby2Ruby2', Ruby2Ruby
- ruby = morph_and_eval ir2r, /Ruby2Ruby/, 'Ruby2Ruby2', Ruby2Ruby
- ____ = morph_and_eval ruby, /Ruby2Ruby2/, 'Ruby2Ruby3', Ruby2Ruby2
+ ____ = morph_and_eval tr2r, /TestRuby2Ruby/, "TestRuby2Ruby2", Ruby2Ruby
+ ruby = morph_and_eval ir2r, /Ruby2Ruby/, "Ruby2Ruby2", Ruby2Ruby
+ ____ = morph_and_eval ruby, /Ruby2Ruby2/, "Ruby2Ruby3", Ruby2Ruby2
class TestRuby2Ruby1 < TestRuby2Ruby
def setup
super
@processor = Ruby2Ruby2.new