test/pt_testcase.rb in ParseTree-3.0.3 vs test/pt_testcase.rb in ParseTree-3.0.4

- old
+ new

@@ -1,8 +1,8 @@ $TESTING = true -require 'test/unit/testcase' +require 'minitest/unit' require 'sexp_processor' # for deep_clone # key: # wwtt = what were they thinking? @@ -30,16 +30,11 @@ define_method :dmethod_added, instance_method(:a_method) if RUBY_VERSION < "1.9" end -class ParseTreeTestCase < Test::Unit::TestCase - unless defined? Mini then - undef_method :default_test rescue nil - alias :refute_nil :assert_not_nil - end - +class ParseTreeTestCase < MiniTest::Unit::TestCase attr_accessor :processor # to be defined by subclass def setup super @processor = nil @@ -368,12 +363,11 @@ s(:back_ref, :"'"), s(:back_ref, :+))) add_tests("begin", "Ruby" => "begin\n (1 + 1)\nend", - "RawParseTree" => [:begin, - [:call, [:lit, 1], :+, [:array, [:lit, 1]]]], + "RawParseTree" => [:call, [:lit, 1], :+, [:array, [:lit, 1]]], "ParseTree" => s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1))), "Ruby2Ruby" => "(1 + 1)") add_tests("begin_def", @@ -383,47 +377,43 @@ s(:scope, s(:block, s(:nil)))), "Ruby2Ruby" => "def m\n # do nothing\nend") add_tests("begin_rescue_ensure", "Ruby" => "begin\n a\nrescue\n # do nothing\nensure\n # do nothing\nend", - "RawParseTree" => [:begin, - [:ensure, - [:rescue, - [:vcall, :a], - [:resbody, nil]], - [:nil]]], + "RawParseTree" => [:ensure, + [:rescue, + [:vcall, :a], + [:resbody, nil]], + [:nil]], "ParseTree" => s(:ensure, s(:rescue, s(:call, nil, :a, s(:arglist)), s(:resbody, s(:array), nil)), s(:nil))) add_tests("begin_rescue_ensure_all_empty", "Ruby" => "begin\n # do nothing\nrescue\n # do nothing\nensure\n # do nothing\nend", - "RawParseTree" => [:begin, - [:ensure, - [:rescue, - [:resbody, nil]], - [:nil]]], + "RawParseTree" => [:ensure, + [:rescue, + [:resbody, nil]], + [:nil]], "ParseTree" => s(:ensure, s(:rescue, s(:resbody, s(:array), nil)), s(:nil))) add_tests("begin_rescue_twice", "Ruby" => "begin\n a\nrescue => mes\n # do nothing\nend\nbegin\n b\nrescue => mes\n # do nothing\nend\n", "RawParseTree" => [:block, - [:begin, - [:rescue, - [:vcall, :a], - [:resbody, nil, - [:lasgn, :mes, [:gvar, :$!]]]]], - [:begin, - [:rescue, - [:vcall, :b], - [:resbody, nil, - [:lasgn, :mes, [:gvar, :$!]]]]]], + [:rescue, + [:vcall, :a], + [:resbody, nil, + [:lasgn, :mes, [:gvar, :$!]]]], + [:rescue, + [:vcall, :b], + [:resbody, nil, + [:lasgn, :mes, [:gvar, :$!]]]]], "ParseTree" => s(:block, s(:rescue, s(:call, nil, :a, s(:arglist)), s(:resbody, s(:array, s(:lasgn, :mes, s(:gvar, :$!))), @@ -439,15 +429,14 @@ "RawParseTree" => [:block, [:rescue, # no begin [:vcall, :a], [:resbody, nil, [:lasgn, :mes, [:gvar, :$!]]]], - [:begin, - [:rescue, - [:vcall, :b], - [:resbody, nil, - [:lasgn, :mes, [:gvar, :$!]]]]]]) + [:rescue, + [:vcall, :b], + [:resbody, nil, + [:lasgn, :mes, [:gvar, :$!]]]]]) copy_test_case "begin_rescue_twice", "Ruby" copy_test_case "begin_rescue_twice", "ParseTree" add_tests("block_attrasgn", @@ -663,14 +652,13 @@ "Ruby" => "def f\n begin\n b\n rescue\n c\n end\n\n d\nend", "RawParseTree" => [:defn, :f, [:scope, [:block, [:args], - [:begin, - [:rescue, - [:vcall, :b], - [:resbody, nil, [:vcall, :c]]]], + [:rescue, + [:vcall, :b], + [:resbody, nil, [:vcall, :c]]], [:vcall, :d]]]], "ParseTree" => s(:defn, :f, s(:args), s(:scope, s(:block, @@ -701,13 +689,12 @@ "RawParseTree" => [:defn, :f, [:scope, [:block, [:args], [:vcall, :a], - [:begin, - [:rescue, [:vcall, :b], - [:resbody, nil, [:vcall, :c]]]]]]], + [:rescue, [:vcall, :b], + [:resbody, nil, [:vcall, :c]]]]]], "ParseTree" => s(:defn, :f, s(:args), s(:scope, s(:block, s(:call, nil, :a, s(:arglist)), @@ -728,16 +715,15 @@ "RawParseTree" => [:defn, :f, [:scope, [:block, [:args], [:vcall, :a], - [:begin, - [:rescue, - [:vcall, :b], - [:resbody, - nil, - [:vcall, :c]]]], + [:rescue, + [:vcall, :b], + [:resbody, + nil, + [:vcall, :c]]], [:vcall, :d]]]], "ParseTree" => s(:defn, :f, s(:args), s(:scope, s(:block, s(:call, nil, :a, s(:arglist)), @@ -1420,18 +1406,17 @@ [:dasgn_curr, :v, [:nil]], [:iter, [:fcall, :assert_block, [:array, [:vcall, :full_message]]], nil, - [:begin, - [:rescue, - [:yield], - [:resbody, - [:array, [:const, :Exception]], - [:block, - [:dasgn, :v, - [:gvar, :$!]], [:break]]]]]]]], + [:rescue, + [:yield], + [:resbody, + [:array, [:const, :Exception]], + [:block, + [:dasgn, :v, + [:gvar, :$!]], [:break]]]]]]], "ParseTree" => s(:iter, s(:call, nil, :a, s(:arglist)), nil, s(:block, s(:lasgn, :v, s(:nil)), @@ -2168,24 +2153,23 @@ s(:lasgn, :t, s(:lit, 5)), s(:dxstr, 'touch ', s(:evstr, s(:lvar, :t))))) add_tests("ensure", "Ruby" => "begin\n (1 + 1)\nrescue SyntaxError => e1\n 2\nrescue Exception => e2\n 3\nelse\n 4\nensure\n 5\nend", - "RawParseTree" => [:begin, - [:ensure, - [:rescue, - [:call, [:lit, 1], :+, [:array, [:lit, 1]]], + "RawParseTree" => [:ensure, + [:rescue, + [:call, [:lit, 1], :+, [:array, [:lit, 1]]], + [:resbody, + [:array, [:const, :SyntaxError]], + [:block, + [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]], [:resbody, - [:array, [:const, :SyntaxError]], + [:array, [:const, :Exception]], [:block, - [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]], - [:resbody, - [:array, [:const, :Exception]], - [:block, - [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]], - [:lit, 4]], - [:lit, 5]]], + [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]], + [:lit, 4]], + [:lit, 5]], "ParseTree" => s(:ensure, s(:rescue, s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1))), s(:resbody, @@ -2337,11 +2321,12 @@ add_tests("flip2_method", "Ruby" => "if 1..2.a?(b) then\n nil\nend", "RawParseTree" => [:if, [:flip2, - [:lit, 1], + [:call, [:lit, 1], :==, + [:array, [:gvar, :$.]]], [:call, [:lit, 2], :a?, [:array, [:vcall, :b]]]], [:nil], nil], "ParseTree" => s(:if, @@ -2908,19 +2893,18 @@ [:block, [:args], [:iter, [:fcall, :c], nil, - [:begin, - [:rescue, - [:vcall, :do_stuff], - [:resbody, - [:array, [:const, :RuntimeError]], - [:block, - [:dasgn_curr, :b, [:gvar, :$!]], - [:fcall, :puts, - [:array, [:dvar, :b]]]]]]]]]]]], + [:rescue, + [:vcall, :do_stuff], + [:resbody, + [:array, [:const, :RuntimeError]], + [:block, + [:dasgn_curr, :b, [:gvar, :$!]], + [:fcall, :puts, + [:array, [:dvar, :b]]]]]]]]]]], "ParseTree" => s(:block, s(:lasgn, :b, s(:lit, 42)), s(:defn, :a, s(:args), s(:scope, @@ -3588,37 +3572,35 @@ s(:call, nil, :blah, s(:arglist)), s(:resbody, s(:array), s(:nil)))) add_tests("rescue_block_body", "Ruby" => "begin\n a\nrescue => e\n c\n d\nend", - "RawParseTree" => [:begin, - [:rescue, - [:vcall, :a], - [:resbody, nil, - [:block, - [:lasgn, :e, [:gvar, :$!]], - [:vcall, :c], - [:vcall, :d]]]]], + "RawParseTree" => [:rescue, + [:vcall, :a], + [:resbody, nil, + [:block, + [:lasgn, :e, [:gvar, :$!]], + [:vcall, :c], + [:vcall, :d]]]], "ParseTree" => s(:rescue, s(:call, nil, :a, s(:arglist)), s(:resbody, s(:array, s(:lasgn, :e, s(:gvar, :$!))), s(:block, s(:call, nil, :c, s(:arglist)), s(:call, nil, :d, s(:arglist)))))) add_tests("rescue_block_body_3", "Ruby" => "begin\n a\nrescue A\n b\nrescue B\n c\nrescue C\n d\nend", - "RawParseTree" => [:begin, - [:rescue, - [:vcall, :a], - [:resbody, [:array, [:const, :A]], - [:vcall, :b], - [:resbody, [:array, [:const, :B]], - [:vcall, :c], - [:resbody, [:array, [:const, :C]], - [:vcall, :d]]]]]], + "RawParseTree" => [:rescue, + [:vcall, :a], + [:resbody, [:array, [:const, :A]], + [:vcall, :b], + [:resbody, [:array, [:const, :B]], + [:vcall, :c], + [:resbody, [:array, [:const, :C]], + [:vcall, :d]]]]], "ParseTree" => s(:rescue, s(:call, nil, :a, s(:arglist)), s(:resbody, s(:array, s(:const, :A)), s(:call, nil, :b, s(:arglist))), s(:resbody, s(:array, s(:const, :B)), @@ -3626,42 +3608,39 @@ s(:resbody, s(:array, s(:const, :C)), s(:call, nil, :d, s(:arglist))))) add_tests("rescue_block_body_ivar", "Ruby" => "begin\n a\nrescue => @e\n c\n d\nend", - "RawParseTree" => [:begin, - [:rescue, - [:vcall, :a], - [:resbody, nil, - [:block, - [:iasgn, :@e, [:gvar, :$!]], - [:vcall, :c], - [:vcall, :d]]]]], + "RawParseTree" => [:rescue, + [:vcall, :a], + [:resbody, nil, + [:block, + [:iasgn, :@e, [:gvar, :$!]], + [:vcall, :c], + [:vcall, :d]]]], "ParseTree" => s(:rescue, s(:call, nil, :a, s(:arglist)), s(:resbody, s(:array, s(:iasgn, :@e, s(:gvar, :$!))), s(:block, s(:call, nil, :c, s(:arglist)), s(:call, nil, :d, s(:arglist)))))) add_tests("rescue_block_nada", "Ruby" => "begin\n blah\nrescue\n # do nothing\nend", - "RawParseTree" => [:begin, - [:rescue, [:vcall, :blah], [:resbody, nil]]], + "RawParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil]], "ParseTree" => s(:rescue, s(:call, nil, :blah, s(:arglist)), s(:resbody, s(:array), nil))) add_tests("rescue_exceptions", "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend", - "RawParseTree" => [:begin, - [:rescue, - [:vcall, :blah], - [:resbody, - [:array, [:const, :RuntimeError]], - [:lasgn, :r, [:gvar, :$!]]]]], + "RawParseTree" => [:rescue, + [:vcall, :blah], + [:resbody, + [:array, [:const, :RuntimeError]], + [:lasgn, :r, [:gvar, :$!]]]], "ParseTree" => s(:rescue, s(:call, nil, :blah, s(:arglist)), s(:resbody, s(:array, s(:const, :RuntimeError), @@ -3669,53 +3648,49 @@ nil))) add_tests("rescue_iasgn_var_empty", "Ruby" => "begin\n 1\nrescue => @e\n # do nothing\nend", - "RawParseTree" => [:begin, - [:rescue, - [:lit, 1], - [:resbody, nil, [:iasgn, :@e, [:gvar, :$!]]]]], + "RawParseTree" => [:rescue, + [:lit, 1], + [:resbody, nil, [:iasgn, :@e, [:gvar, :$!]]]], "ParseTree" => s(:rescue, s(:lit, 1), s(:resbody, s(:array, s(:iasgn, :@e, s(:gvar, :$!))), nil))) add_tests("rescue_lasgn", "Ruby" => "begin\n 1\nrescue\n var = 2\nend", - "RawParseTree" => [:begin, - [:rescue, - [:lit, 1], - [:resbody, nil, [:lasgn, :var, [:lit, 2]]]]], + "RawParseTree" => [:rescue, + [:lit, 1], + [:resbody, nil, [:lasgn, :var, [:lit, 2]]]], "ParseTree" => s(:rescue, s(:lit, 1), s(:resbody, s(:array), s(:lasgn, :var, s(:lit, 2)))), "Ruby2Ruby" => "1 rescue var = 2") add_tests("rescue_lasgn_var", "Ruby" => "begin\n 1\nrescue => e\n var = 2\nend", - "RawParseTree" => [:begin, - [:rescue, - [:lit, 1], - [:resbody, nil, - [:block, - [:lasgn, :e, [:gvar, :$!]], - [:lasgn, :var, [:lit, 2]]]]]], + "RawParseTree" => [:rescue, + [:lit, 1], + [:resbody, nil, + [:block, + [:lasgn, :e, [:gvar, :$!]], + [:lasgn, :var, [:lit, 2]]]]], "ParseTree" => s(:rescue, s(:lit, 1), s(:resbody, s(:array, s(:lasgn, :e, s(:gvar, :$!))), s(:lasgn, :var, s(:lit, 2))))) add_tests("rescue_lasgn_var_empty", "Ruby" => "begin\n 1\nrescue => e\n # do nothing\nend", - "RawParseTree" => [:begin, - [:rescue, - [:lit, 1], - [:resbody, nil, [:lasgn, :e, [:gvar, :$!]]]]], + "RawParseTree" => [:rescue, + [:lit, 1], + [:resbody, nil, [:lasgn, :e, [:gvar, :$!]]]], "ParseTree" => s(:rescue, s(:lit, 1), s(:resbody, s(:array, s(:lasgn, :e, s(:gvar, :$!))), nil)))