test/pt_testcase.rb in ParseTree-1.6.4 vs test/pt_testcase.rb in ParseTree-1.7.0

- old
+ new

@@ -127,17 +127,40 @@ "block_pass" => { "Ruby" => "a(&b)", "ParseTree" => [:block_pass, [:vcall, :b], [:fcall, :a]], }, + "block_pass_omgwtf" => { + "Ruby" => "define_attr_method(:x, :sequence_name, &Proc.new { |*args| nil })", + "ParseTree" => [:block_pass, + [:iter, + [:call, [:const, :Proc], :new], + [:masgn, [:dasgn_curr, :args]], + [:nil]], + [:fcall, :define_attr_method, + [:array, [:lit, :x], [:lit, :sequence_name]]]], + }, + + "block_pass_splat" => { + "Ruby" => "def blah(*args, &block)\n other(*args, &block)\nend", + "ParseTree" => [:defn, :blah, + [:scope, + [:block, + [:args, "*args".intern], + [:block_arg, :block], + [:block_pass, + [:lvar, :block], + [:fcall, :other, [:splat, [:lvar, :args]]]]]]], + }, + "bmethod" => { "Ruby" => [Examples, :unsplatted], "ParseTree" => [:defn, :unsplatted, [:bmethod, [:dasgn_curr, :x], - [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]], + [:call, [:dvar, :x], "+".intern, [:array, [:lit, 1]]]]], "Ruby2Ruby" => "def unsplatted(x)\n (x + 1)\nend" }, "bmethod_splat" => { "Ruby" => [Examples, :splatted], @@ -150,17 +173,17 @@ [:call, [:dvar, :y], :+, [:array, [:lit, 42]]]]]], "Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend", }, "break" => { - "Ruby" => "loop do\n break if true\nend", + "Ruby" => "loop { break if true }", "ParseTree" => [:iter, [:fcall, :loop], nil, [:if, [:true], [:break], nil]], }, "break_arg" => { - "Ruby" => "loop do\n break 42 if true\nend", + "Ruby" => "loop { break 42 if true }", "ParseTree" => [:iter, [:fcall, :loop], nil, [:if, [:true], [:break, [:lit, 42]], nil]], }, @@ -362,11 +385,11 @@ "ParseTree" => [:class, :X, nil, [:scope, [:cvdecl, :@@blah, [:lit, 1]]]], }, "dasgn" => { - "Ruby" => "a.each do |x|\n b.each do |y|\n x = (x + 1)\n end\nend", + "Ruby" => "a.each { |x| b.each { |y| x = (x + 1) } }", "ParseTree" => [:iter, [:call, [:vcall, :a], :each], [:dasgn_curr, :x], [:iter, [:call, [:vcall, :b], :each], @@ -624,35 +647,35 @@ "Ruby" => "@a = 4", "ParseTree" => [:iasgn, :@a, [:lit, 4]], }, "iteration1" => { - "Ruby" => "loop do end", + "Ruby" => "loop { }", "ParseTree" => [:iter, [:fcall, :loop], nil], }, "iteration2" => { - "Ruby" => "array = [1, 2, 3]\narray.each do |x|\n puts(x.to_s)\nend\n", + "Ruby" => "array = [1, 2, 3]\narray.each { |x| puts(x.to_s) }\n", "ParseTree" => [:block, [:lasgn, :array, [:array, [:lit, 1], [:lit, 2], [:lit, 3]]], [:iter, [:call, [:lvar, :array], :each], [:dasgn_curr, :x], [:fcall, :puts, [:array, [:call, [:dvar, :x], :to_s]]]]], }, "iteration3" => { - "Ruby" => "1.upto(3) do |n|\n puts(n.to_s)\nend", + "Ruby" => "1.upto(3) { |n| puts(n.to_s) }", "ParseTree" => [:iter, [:call, [:lit, 1], :upto, [:array, [:lit, 3]]], [:dasgn_curr, :n], [:fcall, :puts, [:array, [:call, [:dvar, :n], :to_s]]]], }, "iteration4" => { - "Ruby" => "3.downto(1) do |n|\n puts(n.to_s)\nend", + "Ruby" => "3.downto(1) { |n| puts(n.to_s) }", "ParseTree" => [:iter, [:call, [:lit, 3], :downto, [:array, [:lit, 1]]], [:dasgn_curr, :n], [:fcall, :puts, [:array, [:call, [:dvar, :n], :to_s]]]], }, @@ -660,17 +683,17 @@ "iteration5" => { "Ruby" => "argl = 10\nwhile (argl >= 1) do\n puts(\"hello\")\n argl = (argl - 1)\nend\n", "ParseTree" => [:block, [:lasgn, :argl, [:lit, 10]], [:while, - [:call, [:lvar, :argl], :>=, [:array, [:lit, 1]]], + [:call, [:lvar, :argl], ">=".intern, [:array, [:lit, 1]]], [:block, [:fcall, :puts, [:array, [:str, "hello"]]], [:lasgn, :argl, [:call, [:lvar, :argl], - :-, [:array, [:lit, 1]]]]], true]], + "-".intern, [:array, [:lit, 1]]]]], true]], }, "iteration6" => { "Ruby" => "array1 = [1, 2, 3]\narray2 = [4, 5, 6, 7]\narray1.each do |x|\n array2.each do |y|\n puts(x.to_s)\n puts(y.to_s)\n end\nend\n", "ParseTree" => [:block, @@ -764,13 +787,32 @@ }, "masgn_iasgn" => { "Ruby" => "a, @b = c, d", "ParseTree" => [:masgn, - [:array, [:lasgn, :a], [:iasgn, :@b]], + [:array, [:lasgn, :a], [:iasgn, "@b".intern]], [:array, [:vcall, :c], [:vcall, :d]]], }, + + "masgn_attrasgn" => { + "Ruby" => "a, b.c = d, e", + "ParseTree" => [:masgn, + [:array, [:lasgn, :a], [:attrasgn, [:vcall, :b], :c=]], + [:array, [:vcall, :d], [:vcall, :e]]], + }, + + "masgn_splat" => { + "Ruby" => "a, b, *c = d, e, f, g", + "ParseTree" => [:masgn, + [:array, [:lasgn, :a], [:lasgn, :b]], + [:lasgn, :c], + [:array, + [:vcall, :d], [:vcall, :e], + [:vcall, :f], [:vcall, :g]]] + }, + + "match" => { "Ruby" => "1 if /x/", "ParseTree" => [:if, [:match, [:lit, /x/]], [:lit, 1], nil], }, @@ -790,11 +832,11 @@ [:scope, [:defn, :y, [:scope, [:block, [:args], [:nil]]]]]], }, "next" => { - "Ruby" => "loop do\n next if false\nend", + "Ruby" => "loop { next if false }", "ParseTree" => [:iter, [:fcall, :loop], nil, [:if, [:false], [:next], nil]], }, @@ -860,51 +902,51 @@ "Ruby" => "(a or b)", "ParseTree" => [:or, [:vcall, :a], [:vcall, :b]], }, "postexe" => { - "Ruby" => "END {\n 1\n}", + "Ruby" => "END { 1 }", "ParseTree" => [:iter, [:postexe], nil, [:lit, 1]], }, - "proc_no_args" => { - "Ruby" => "proc do\n (x + 1)\nend", + "proc_args" => { + "Ruby" => "proc { |x| (x + 1) }", "ParseTree" => [:iter, [:fcall, :proc], - nil, - [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]], + [:dasgn_curr, :x], + [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]], }, - "proc_args" => { - "Ruby" => "proc do |x|\n (x + 1)\nend", + "proc_no_args" => { + "Ruby" => "proc { (x + 1) }", "ParseTree" => [:iter, [:fcall, :proc], - [:dasgn_curr, :x], - [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]], + nil, + [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]], }, "redo" => { - "Ruby" => "loop do\n redo if false\nend", + "Ruby" => "loop { redo if false }", "ParseTree" => [:iter, [:fcall, :loop], nil, [:if, [:false], [:redo], nil]], }, "rescue" => { "Ruby" => "blah rescue nil", "ParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]], }, - "rescue_block_nada" => { - "Ruby" => "begin\n blah\nrescue\n # do nothing\nend\n", - "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil]]] - }, - "rescue_block_body" => { "Ruby" => "begin\n blah\nrescue\n nil\nend\n", "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]]], }, + "rescue_block_nada" => { + "Ruby" => "begin\n blah\nrescue\n # do nothing\nend\n", + "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil]]] + }, + "rescue_exceptions" => { "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend\n", "ParseTree" => [:begin, [:rescue, [:vcall, :blah], @@ -976,22 +1018,22 @@ [:undef, [:lit, :y]], [:undef, [:lit, :z]]], "Ruby2Ruby" => "undef :x\nundef :y\nundef :z\n", }, - "until_pre" => { - "Ruby" => "until false do\n (1 + 1)\nend", - "ParseTree" => [:until, [:false], - [:call, [:lit, 1], :+, [:array, [:lit, 1]]], true], - }, - "until_post" => { "Ruby" => "begin\n (1 + 1)\nend until false", "ParseTree" => [:until, [:false], [:call, [:lit, 1], :+, [:array, [:lit, 1]]], false], }, + "until_pre" => { + "Ruby" => "until false do\n (1 + 1)\nend", + "ParseTree" => [:until, [:false], + [:call, [:lit, 1], :+, [:array, [:lit, 1]]], true], + }, + "valias" => { "Ruby" => "alias $y $x", "ParseTree" => [:valias, :$y, :$x], }, @@ -1112,10 +1154,10 @@ flunk "Processor is nil" if processor.nil? assert data.has_key?(input_name), "Unknown input data" unless data.has_key?(output_name) then $stderr.puts "add_test(#{node.inspect}, :same)" end - assert data.has_key?(output_name), "Unknown expected data" + assert data.has_key?(output_name), "Missing test data: #{self.class} #{node}" input = data[input_name].deep_clone expected = if data[output_name] == :same then input else