[rubygem-ruby2ruby/f21] Update to 2.1.1, latest pt_testcase, fix rawhide build
Vít Ondruch
vondruch at fedoraproject.org
Fri Aug 1 08:36:04 UTC 2014
commit 01c97854dd1f975a1840fb60a7f95cff6ded62e2
Author: Mo Morsi <mmorsi at redhat.com>
Date: Thu Jul 31 15:17:40 2014 -0400
Update to 2.1.1, latest pt_testcase, fix rawhide build
pt_testcase.rb | 3532 +++++++++++++++---------------------------------
rubygem-ruby2ruby.spec | 28 +-
2 files changed, 1129 insertions(+), 2431 deletions(-)
---
diff --git a/pt_testcase.rb b/pt_testcase.rb
index 97cb77f..35ff2c0 100644
--- a/pt_testcase.rb
+++ b/pt_testcase.rb
@@ -1,3 +1,5 @@
+# encoding: US-ASCII
+
$TESTING = true
require 'minitest/unit'
@@ -6,8 +8,6 @@ require 'sexp_processor' # for deep_clone
# key:
# wwtt = what were they thinking?
-# TODO: <ko1_> 1.8.7 support {|&b|} syntax
-
class Examples
attr_reader :reader
attr_writer :writer
@@ -32,7 +32,7 @@ class Examples
RUBY_VERSION < "1.9"
end
-class ParseTreeTestCase < MiniTest::Unit::TestCase
+class ParseTreeTestCase < Minitest::Test
attr_accessor :processor # to be defined by subclass
def setup
@@ -71,6 +71,20 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
end
end
+ def self.add_18tests name, hash
+ add_tests "#{name}__18", hash
+ end
+
+ def self.add_19tests name, hash
+ add_tests "#{name}__19", hash
+ end
+
+ def self.add_19edgecases ruby, sexp, cases
+ cases.each do |name, code|
+ add_19tests name, "Ruby" => code, "ParseTree" => sexp, "Ruby2Ruby" => ruby
+ end
+ end
+
def self.clone_same
@@testcases.each do |node, data|
data.each do |key, val|
@@ -88,9 +102,16 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
end
def self.generate_test klass, node, data, input_name, output_name
- klass.send(:define_method, "test_#{node}".to_sym) do
+ klass.send :define_method, "test_#{node}" do
flunk "Processor is nil" if processor.nil?
+ if node =~ /(1[89]|2[01])$/ then
+ version = $1
+ # can't push this up because it may be generating into an
+ # abstract test class and the actual subclass is versioned.
+ return "version specific test" unless self.class.name =~ /#{version}/
+ end
+
assert data.has_key?(input_name), "Unknown input data"
assert data.has_key?(output_name), "Missing test data"
@@ -118,7 +139,7 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
# body into an assertion. It'll allow subclasses to hook in
# and add behavior before or after the processor does it's
# thing. If you go the body refactor route, some of the
- # RawParseTree test casese fail for completely bogus reasons.
+ # RawParseTree test cases fail for completely bogus reasons.
before_process_hook klass, node, data, input_name, output_name
refute_nil data[input_name], "testcase does not exist?"
@@ -199,92 +220,480 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
############################################################
# Shared TestCases:
- @@testcase_order = %w(Ruby RawParseTree ParseTree)
+ @@testcase_order = %w(Ruby ParseTree)
@@testcases = Hash.new { |h,k| h[k] = {} }
+ ###
+ # 1.8 specific tests
+
+ add_18tests("call_arglist_norm_hash_splat",
+ "Ruby" => "o.m(42, :a => 1, :b => 2, *c)",
+ "ParseTree" => s(:call,
+ s(:call, nil, :o), :m,
+ s(:lit, 42),
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2)),
+ s(:splat, s(:call, nil, :c))))
+
+ add_18tests("call_arglist_space",
+ "Ruby" => "a (1,2,3)",
+ "ParseTree" => s(:call, nil, :a,
+ s(:lit, 1), s(:lit, 2), s(:lit, 3)),
+ "Ruby2Ruby" => "a(1, 2, 3)")
+
+ add_18tests("fcall_arglist_norm_hash_splat",
+ "Ruby" => "m(42, :a => 1, :b => 2, *c)",
+ "ParseTree" => s(:call, nil, :m,
+ s(:lit, 42),
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2)),
+ s(:splat, s(:call, nil, :c))))
+
+ add_18tests("if_args_no_space_symbol",
+ "Ruby" => "x if y:z",
+ "ParseTree" => s(:if,
+ s(:call, nil, :y, s(:lit, :z)),
+ s(:call, nil, :x),
+ nil),
+ "Ruby2Ruby" => "x if y(:z)")
+
+ add_18tests("if_post_not",
+ "Ruby" => "a if not b",
+ "ParseTree" => s(:if, s(:call, nil, :b), nil,
+ s(:call, nil, :a)),
+ "Ruby2Ruby" => "a unless b")
+
+ add_18tests("if_pre_not",
+ "Ruby" => "if not b then a end",
+ "ParseTree" => s(:if, s(:call, nil, :b), nil,
+ s(:call, nil, :a)),
+ "Ruby2Ruby" => "a unless b")
+
+ add_18tests("iter_args_ivar",
+ "Ruby" => "a { |@a| 42 }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :a),
+ s(:args, :@a),
+ s(:lit, 42)))
+
+ add_18tests("iter_masgn_args_ivar",
+ "Ruby" => "a { |a, @b| 42 }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :a),
+ s(:args, :a, :@b),
+ s(:lit, 42)))
+
+ add_18tests("not",
+ "Ruby" => "(not true)",
+ "ParseTree" => s(:not, s(:true)))
+
+ add_18tests("str_question_control",
+ "Ruby" => '?\M-\C-a',
+ "ParseTree" => s(:lit, 129),
+ "Ruby2Ruby" => "129")
+
+ add_18tests("str_question_escape",
+ "Ruby" => '?\n',
+ "ParseTree" => s(:lit, 10),
+ "Ruby2Ruby" => "10")
+
+ add_18tests("str_question_literal",
+ "Ruby" => '?a',
+ "ParseTree" => s(:lit, 97),
+ "Ruby2Ruby" => "97")
+
+ add_18tests("unless_post_not",
+ "Ruby" => "a unless not b",
+ "ParseTree" => s(:if, s(:call, nil, :b),
+ s(:call, nil, :a), nil),
+ "Ruby2Ruby" => "a if b")
+
+ add_18tests("unless_pre_not",
+ "Ruby" => "unless not b then a end",
+ "ParseTree" => s(:if, s(:call, nil, :b),
+ s(:call, nil, :a), nil),
+ "Ruby2Ruby" => "a if b")
+
+ add_18tests("until_post_not",
+ "Ruby" => "begin\n (1 + 1)\nend until not true",
+ "ParseTree" => s(:while, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false),
+ "Ruby2Ruby" => "begin\n (1 + 1)\nend while true")
+
+ add_18tests("until_pre_not",
+ "Ruby" => "until not true do\n (1 + 1)\nend",
+ "ParseTree" => s(:while, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
+
+ add_18tests("until_pre_not_mod",
+ "Ruby" => "(1 + 1) until not true",
+ "ParseTree" => s(:while, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
+
+ add_18tests("while_post_not",
+ "Ruby" => "begin\n (1 + 1)\nend while not true",
+ "ParseTree" => s(:until, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false),
+ "Ruby2Ruby" => "begin\n (1 + 1)\nend until true")
+
+ add_18tests("while_pre_not",
+ "Ruby" => "while not true do\n (1 + 1)\nend",
+ "ParseTree" => s(:until, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "until true do\n (1 + 1)\nend")
+
+ add_18tests("while_pre_not_mod",
+ "Ruby" => "(1 + 1) while not true",
+ "ParseTree" => s(:until, s(:true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "until true do\n (1 + 1)\nend") # FIX
+
+ ###
+ # 1.9 specific tests
+
+ add_19edgecases("lambda { || (x + 1) }",
+ s(:iter,
+ s(:call, nil, :lambda),
+ 0,
+ s(:call, s(:call, nil, :x), :+, s(:lit, 1))),
+ "stabby_args_0" => "->() { (x + 1) }",
+ "stabby_args_0_doend" => "->() do (x + 1) end",
+ "stabby_args_0_no_parens" => "-> { (x + 1) }",
+ "stabby_args_0_no_parens_doend" => "-> do (x + 1) end",
+ "stabby_args_0_spacebar_broken" => "->{x+1}") # I hate you
+
+ add_19edgecases("lambda { |x, y| (x + y) }",
+ s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :x, :y),
+ s(:call, s(:lvar, :x), :+, s(:lvar, :y))),
+ "stabby_args_2" => "->(x, y) { (x + y) }",
+ "stabby_args_2_doend" => "->(x, y) do (x + y) end",
+ "stabby_args_2_no_parens" => "-> x, y { (x + y) }",
+ "stabby_args_2_no_parens_doend" => "-> x, y do (x + y) end")
+
+ add_19edgecases("lambda { |x| (x + 1) }",
+ s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :x),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))),
+ "stabby_args_1" => "->(x) { (x + 1) }",
+ "stabby_args_1_doend" => "->(x) do (x + 1) end",
+ "stabby_args_1_no_parens" => "-> x { (x + 1) }",
+ "stabby_args_1_no_parens_doend" => "-> x do (x + 1) end")
+
+ add_19tests("array_bare_hash",
+ "Ruby" => "[:a, :b => :c]",
+ "ParseTree" => s(:array,
+ s(:lit, :a),
+ s(:hash,
+ s(:lit, :b),
+ s(:lit, :c))),
+ "Ruby2Ruby" => "[:a, { :b => :c }]")
+
+ add_19tests("array_bare_hash_labels",
+ "Ruby" => "[:a, b: :c]",
+ "ParseTree" => s(:array,
+ s(:lit, :a),
+ s(:hash,
+ s(:lit, :b),
+ s(:lit, :c))),
+ "Ruby2Ruby" => "[:a, { :b => :c }]")
+
+ add_19tests("call_arglist_norm_hash_colons",
+ "Ruby" => "o.m(42, a: 1, b: 2)",
+ "ParseTree" => s(:call,
+ s(:call, nil, :o),
+ :m,
+ s(:lit, 42),
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))),
+ "Ruby2Ruby" => "o.m(42, :a => 1, :b => 2)")
+
+ add_19tests("call_arglist_trailing_comma",
+ "Ruby" => "a(1,2,3,)",
+ "ParseTree" => s(:call,
+ nil,
+ :a,
+ s(:lit, 1), s(:lit, 2), s(:lit, 3)),
+ "Ruby2Ruby" => "a(1, 2, 3)")
+
+ add_19tests("call_bang",
+ "Ruby" => "!a",
+ "ParseTree" => s(:call,
+ s(:call, nil, :a),
+ :"!"))
+
+ add_19tests("call_bang_empty",
+ "Ruby" => "! ()",
+ "ParseTree" => s(:call, s(:nil), :"!"))
+
+ add_19tests("call_fonz",
+ "Ruby" => "a.()",
+ "ParseTree" => s(:call, s(:call, nil, :a), :call),
+ "Ruby2Ruby" => "a.call")
+
+ add_19tests("call_fonz_cm",
+ "Ruby" => "a::()",
+ "ParseTree" => s(:call, s(:call, nil, :a), :call),
+ "Ruby2Ruby" => "a.call")
+
+ add_19tests("call_not",
+ "Ruby" => "not (42)",
+ "ParseTree" => s(:call, s(:lit, 42), :"!"))
+
+ # add_19tests("call_not_empty",
+ # "Ruby" => "not ()",
+ # "ParseTree" => s(:call, s(:lit, 42), :"!"))
+
+ add_19tests("call_not_equal",
+ "Ruby" => "a != b",
+ "ParseTree" => s(:call,
+ s(:call, nil, :a),
+ :"!=",
+ s(:call, nil, :b)))
+
+ add_19tests("call_splat_mid",
+ "Ruby" => "def f(a = nil, *b, c)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, s(:lasgn, :a, s(:nil)), :"*b", :c),
+ s(:nil)))
+
+ add_19tests("defn_args_mand_opt_mand",
+ "Ruby" => "def f(mand1, opt = 42, mand2)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, :mand1, s(:lasgn, :opt, s(:lit, 42)), :mand2),
+ s(:nil)))
+
+ add_19tests("defn_args_mand_opt_splat_mand",
+ "Ruby" => "def f(mand1, opt = 42, *rest, mand2)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, :mand1, s(:lasgn, :opt, s(:lit, 42)), :"*rest", :mand2),
+ s(:nil)))
+
+ add_19tests("defn_args_opt_mand",
+ "Ruby" => "def f(opt = 42, mand)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, s(:lasgn, :opt, s(:lit, 42)), :mand),
+ s(:nil)))
+
+ add_19tests("defn_args_opt_splat_mand",
+ "Ruby" => "def f(opt = 42, *rest, mand)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, s(:lasgn, :opt, s(:lit, 42)), :"*rest", :mand),
+ s(:nil)))
+
+ add_19tests("defn_args_splat_mand",
+ "Ruby" => "def f(*rest, mand)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, :"*rest", :mand),
+ s(:nil)))
+
+ add_19tests("defn_args_splat_middle",
+ "Ruby" => "def f(first, *middle, last)\n # do nothing\nend",
+ "ParseTree" => s(:defn, :f,
+ s(:args, :first, :"*middle", :last),
+ s(:nil)))
+
+ add_19tests("fcall_arglist_hash_colons",
+ "Ruby" => "m(a: 1, b: 2)",
+ "ParseTree" => s(:call, nil, :m,
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))),
+ "Ruby2Ruby" => "m(:a => 1, :b => 2)")
+
+ add_19tests("hash_new",
+ "Ruby" => "{ a: 1, b: 2 }",
+ "ParseTree" => s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2)),
+ "Ruby2Ruby" => "{ :a => 1, :b => 2 }")
+
+ add_19tests("hash_new_no_space",
+ "Ruby" => "{a:1,b:2}",
+ "ParseTree" => s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2)),
+ "Ruby2Ruby" => "{ :a => 1, :b => 2 }")
+
+ add_19tests("hash_new_with_keyword",
+ "Ruby" => "{ true: 1, b: 2 }",
+ "ParseTree" => s(:hash,
+ s(:lit, :true), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2)),
+ "Ruby2Ruby" => "{ :true => 1, :b => 2 }")
+
+ add_19tests("if_post_not",
+ "Ruby" => "a if not b",
+ "ParseTree" => s(:if, s(:call, s(:call, nil, :b), :"!"),
+ s(:call, nil, :a),
+ nil),
+ "Ruby2Ruby" => "a unless b")
+
+ add_19tests("if_pre_not",
+ "Ruby" => "if not b then a end",
+ "ParseTree" => s(:if, s(:call, s(:call, nil, :b), :"!"),
+ s(:call, nil, :a),
+ nil),
+ "Ruby2Ruby" => "a unless b")
+
+ add_19tests("label_in_bare_hash_in_array_in_ternary",
+ "Ruby" => "1 ? [:a, b: 2] : 1",
+ "ParseTree" => s(:if, s(:lit, 1),
+ s(:array,
+ s(:lit, :a),
+ s(:hash, s(:lit, :b), s(:lit, 2))),
+ s(:lit, 1)),
+ "Ruby2Ruby" => "1 ? ([:a, { :b => 2 }]) : (1)")
+
+ add_19tests("label_in_callargs_in_ternary",
+ "Ruby" => "1 ? m(a: 2) : 1",
+ "ParseTree" => s(:if, s(:lit, 1),
+ s(:call, nil, :m,
+ s(:hash, s(:lit, :a), s(:lit, 2))),
+ s(:lit, 1)),
+ "Ruby2Ruby" => "1 ? (m(:a => 2)) : (1)")
+
+ add_19tests("not",
+ "Ruby" => "(not true)",
+ "ParseTree" => s(:call, s(:true), :"!"))
+
+ add_19tests("splat_fcall_middle",
+ "Ruby" => "meth(1, *[2], 3)",
+ "ParseTree" => s(:call,
+ nil,
+ :meth,
+ s(:lit, 1),
+ s(:splat, s(:array, s(:lit, 2))),
+ s(:lit, 3)))
+
+ add_19tests("str_question_control",
+ "Ruby" => '?\M-\C-a',
+ "ParseTree" => s(:str, "\x81"))
+
+ add_19tests("str_question_escape",
+ "Ruby" => '?\n',
+ "ParseTree" => s(:str, "\n"))
+
+ add_19tests("str_question_literal",
+ "Ruby" => '?a',
+ "ParseTree" => s(:str, "a"))
+
+ add_19tests("unless_post_not",
+ "Ruby" => "a unless not b",
+ "ParseTree" => s(:if, s(:call, s(:call, nil, :b), :"!"),
+ nil,
+ s(:call, nil, :a)),
+ "Ruby2Ruby" => "a if b")
+
+ add_19tests("unless_pre_not",
+ "Ruby" => "unless not b then a end",
+ "ParseTree" => s(:if, s(:call, s(:call, nil, :b), :"!"),
+ nil,
+ s(:call, nil, :a)),
+ "Ruby2Ruby" => "a if b")
+
+ add_19tests("until_post_not",
+ "Ruby" => "begin\n (1 + 1)\nend until not true",
+ "ParseTree" => s(:until, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false),
+ "Ruby2Ruby" => "begin\n (1 + 1)\nend while true")
+
+ add_19tests("until_pre_not",
+ "Ruby" => "until not true do\n (1 + 1)\nend",
+ "ParseTree" => s(:until, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
+
+ add_19tests("until_pre_not_mod",
+ "Ruby" => "(1 + 1) until not true",
+ "ParseTree" => s(:until, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
+
+ add_19tests("while_post_not",
+ "Ruby" => "begin\n (1 + 1)\nend while not true",
+ "ParseTree" => s(:while, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false),
+ "Ruby2Ruby" => "begin\n (1 + 1)\nend until true")
+
+ add_19tests("while_pre_not",
+ "Ruby" => "while not true do\n (1 + 1)\nend",
+ "ParseTree" => s(:while, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "until true do\n (1 + 1)\nend")
+
+ add_19tests("while_pre_not_mod",
+ "Ruby" => "(1 + 1) while not true",
+ "ParseTree" => s(:while, s(:call, s(:true), :"!"),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
+ "Ruby2Ruby" => "until true do\n (1 + 1)\nend") # FIX
+
+ ###
+ # Shared tests:
+
add_tests("alias",
"Ruby" => "class X\n alias :y :x\nend",
- "RawParseTree" => [:class, :X, nil,
- [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
"ParseTree" => s(:class, :X, nil,
- s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))))
+ s(:alias, s(:lit, :y), s(:lit, :x))))
add_tests("alias_ugh",
"Ruby" => "class X\n alias y x\nend",
- "RawParseTree" => [:class, :X, nil,
- [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
"ParseTree" => s(:class, :X, nil,
- s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))),
+ s(:alias, s(:lit, :y), s(:lit, :x))),
"Ruby2Ruby" => "class X\n alias :y :x\nend")
add_tests("and",
- "Ruby" => "(a and b)",
- "RawParseTree" => [:and, [:vcall, :a], [:vcall, :b]],
+ "Ruby" => "a and b",
"ParseTree" => s(:and,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))))
+ s(:call, nil, :a),
+ s(:call, nil, :b)))
add_tests("argscat_inside",
"Ruby" => "a = [b, *c]",
- "RawParseTree" => [:lasgn, :a,
- [:argscat,
- [:array, [:vcall, :b]], [:vcall, :c]]],
"ParseTree" => s(:lasgn, :a,
s(:array,
- s(:call, nil, :b, s(:arglist)),
- s(:splat, s(:call, nil, :c, s(:arglist))))))
+ s(:call, nil, :b),
+ s(:splat, s(:call, nil, :c)))))
add_tests("argscat_svalue",
"Ruby" => "a = b, c, *d",
- "RawParseTree" => [:lasgn, :a,
- [:svalue,
- [:argscat,
- [:array, [:vcall, :b], [:vcall, :c]],
- [:vcall, :d]]]],
"ParseTree" => s(:lasgn, :a,
s(:svalue,
s(:array,
- s(:call, nil, :b, s(:arglist)),
- s(:call, nil, :c, s(:arglist)),
+ s(:call, nil, :b),
+ s(:call, nil, :c),
s(:splat,
- s(:call, nil, :d, s(:arglist)))))))
+ s(:call, nil, :d))))))
add_tests("argspush",
"Ruby" => "a[*b] = c",
- "RawParseTree" => [:attrasgn,
- [:vcall, :a],
- :[]=,
- [:argspush,
- [:splat,
- [:vcall, :b]],
- [:vcall, :c]]],
"ParseTree" => s(:attrasgn,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:[]=,
- s(:arglist,
- s(:splat,
- s(:call, nil, :b, s(:arglist))),
- s(:call, nil, :c, s(:arglist)))))
+ s(:splat,
+ s(:call, nil, :b)),
+ s(:call, nil, :c)))
add_tests("array",
"Ruby" => "[1, :b, \"c\"]",
- "RawParseTree" => [:array, [:lit, 1], [:lit, :b], [:str, "c"]],
"ParseTree" => s(:array, s(:lit, 1), s(:lit, :b), s(:str, "c")))
add_tests("array_pct_W",
"Ruby" => "%W[a b c]",
- "RawParseTree" => [:array, [:str, "a"], [:str, "b"], [:str, "c"]],
"ParseTree" => s(:array,
s(:str, "a"), s(:str, "b"), s(:str, "c")),
"Ruby2Ruby" => "[\"a\", \"b\", \"c\"]")
add_tests("array_pct_W_dstr",
"Ruby" => "%W[a #\{@b} c]",
- "RawParseTree" => [:array,
- [:str, "a"],
- [:dstr, "", [:evstr, [:ivar, :@b]]],
- [:str, "c"]],
"ParseTree" => s(:array,
s(:str, "a"),
s(:dstr, "", s(:evstr, s(:ivar, :@b))),
@@ -293,17 +702,12 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("array_pct_w",
"Ruby" => "%w[a b c]",
- "RawParseTree" => [:array, [:str, "a"], [:str, "b"], [:str, "c"]],
"ParseTree" => s(:array,
s(:str, "a"), s(:str, "b"), s(:str, "c")),
"Ruby2Ruby" => "[\"a\", \"b\", \"c\"]")
add_tests("array_pct_w_dstr",
"Ruby" => "%w[a #\{@b} c]",
- "RawParseTree" => [:array,
- [:str, "a"],
- [:str, "#\{@b}"],
- [:str, "c"]],
"ParseTree" => s(:array,
s(:str, "a"),
s(:str, "#\{@b}"),
@@ -312,39 +716,28 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("attrasgn",
"Ruby" => "y = 0\n42.method = y\n",
- "RawParseTree" => [:block,
- [:lasgn, :y, [:lit, 0]],
- [:attrasgn, [:lit, 42], :method=,
- [:array, [:lvar, :y]]]],
"ParseTree" => s(:block,
s(:lasgn, :y, s(:lit, 0)),
- s(:attrasgn, s(:lit, 42), :method=,
- s(:arglist, s(:lvar, :y)))))
+ s(:attrasgn,
+ s(:lit, 42), :method=, s(:lvar, :y))))
add_tests("attrasgn_index_equals",
"Ruby" => "a[42] = 24",
- "RawParseTree" => [:attrasgn, [:vcall, :a], :[]=,
- [:array, [:lit, 42], [:lit, 24]]],
"ParseTree" => s(:attrasgn,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:[]=,
- s(:arglist, s(:lit, 42), s(:lit, 24))))
+ s(:lit, 42), s(:lit, 24)))
add_tests("attrasgn_index_equals_space",
"Ruby" => "a = []; a [42] = 24",
- "RawParseTree" => [:block,
- [:lasgn, :a, [:zarray]],
- [:attrasgn, [:lvar, :a], :[]=,
- [:array, [:lit, 42], [:lit, 24]]]],
"ParseTree" => s(:block,
s(:lasgn, :a, s(:array)),
s(:attrasgn, s(:lvar, :a), :[]=,
- s(:arglist, s(:lit, 42), s(:lit, 24)))),
+ s(:lit, 42), s(:lit, 24))),
"Ruby2Ruby" => "a = []\na[42] = 24\n")
add_tests("attrset",
"Ruby" => [Examples, :writer=],
- "RawParseTree" => [:defn, :writer=, [:attrset, :@writer]],
"ParseTree" => s(:defn, :writer=,
s(:args, :arg),
s(:attrset, :@writer)),
@@ -352,11 +745,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("back_ref",
"Ruby" => "[$&, $`, $', $+]",
- "RawParseTree" => [:array,
- [:back_ref, :&],
- [:back_ref, :"`"],
- [:back_ref, :"'"],
- [:back_ref, :+]],
"ParseTree" => s(:array,
s(:back_ref, :&),
s(:back_ref, :"`"),
@@ -365,37 +753,24 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("begin",
"Ruby" => "begin\n (1 + 1)\nend",
- "RawParseTree" => [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
- "ParseTree" => s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))),
+ "ParseTree" => s(:call, s(:lit, 1), :+, s(:lit, 1)),
"Ruby2Ruby" => "(1 + 1)")
add_tests("begin_def",
"Ruby" => "def m\n begin\n\n end\nend",
- "RawParseTree" => [:defn, :m, [:scope, [:block, [:args], [:nil]]]],
- "ParseTree" => s(:defn, :m, s(:args),
- s(:scope, s(:block, s(:nil)))),
+ "ParseTree" => s(:defn, :m, s(:args), 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" => [:ensure,
- [:rescue,
- [:vcall, :a],
- [:resbody, nil]],
- [:nil]],
"ParseTree" => s(:ensure,
s(:rescue,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
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" => [:ensure,
- [:rescue,
- [:resbody, nil]],
- [:nil]],
"ParseTree" => s(:ensure,
s(:rescue,
s(:resbody, s(:array), nil)),
@@ -403,587 +778,279 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
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,
- [: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(:call, nil, :a),
s(:resbody,
s(:array, s(:lasgn, :mes, s(:gvar, :$!))),
nil)),
s(:rescue,
- s(:call, nil, :b, s(:arglist)),
+ s(:call, nil, :b),
s(:resbody,
s(:array,
s(:lasgn, :mes, s(:gvar, :$!))),
nil))))
-
- add_tests("begin_rescue_twice_mri_verbose_flag",
- "RawParseTree" => [:block,
- [:rescue, # no begin
- [:vcall, :a],
- [: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",
"Ruby" => "def self.setup(ctx)\n bind = allocate\n bind.context = ctx\n return bind\nend",
- "RawParseTree" => [:defs, [:self], :setup,
- [:scope,
- [:block,
- [:args, :ctx],
- [:lasgn, :bind, [:vcall, :allocate]],
- [:attrasgn, [:lvar, :bind], :context=,
- [:array, [:lvar, :ctx]]],
- [:return, [:lvar, :bind]]]]],
"ParseTree" => s(:defs, s(:self), :setup,
s(:args, :ctx),
- s(:scope,
- s(:block,
- s(:lasgn, :bind,
- s(:call, nil, :allocate, s(:arglist))),
- s(:attrasgn, s(:lvar, :bind), :context=,
- s(:arglist, s(:lvar, :ctx))),
- s(:return, s(:lvar, :bind))))))
-
+ s(:lasgn, :bind, s(:call, nil, :allocate)),
+ s(:attrasgn,
+ s(:lvar, :bind), :context=, s(:lvar, :ctx)),
+ s(:return, s(:lvar, :bind))))
add_tests("block_lasgn",
"Ruby" => "x = (y = 1\n(y + 2))",
- "RawParseTree" => [:lasgn, :x,
- [:block,
- [:lasgn, :y, [:lit, 1]],
- [:call, [:lvar, :y], :+, [:array, [:lit, 2]]]]],
"ParseTree" => s(:lasgn, :x,
s(:block,
s(:lasgn, :y, s(:lit, 1)),
- s(:call, s(:lvar, :y), :+,
- s(:arglist, s(:lit, 2))))))
+ s(:call, s(:lvar, :y), :+, s(:lit, 2)))))
add_tests("block_mystery_block",
"Ruby" => "a(b) do\n if b then\n true\n else\n c = false\n d { |x| c = true }\n c\n end\nend",
- "RawParseTree" => [:iter,
- [:fcall, :a, [:array, [:vcall, :b]]],
- nil,
- [:if,
- [:vcall, :b],
- [:true],
- [:block,
- [:dasgn_curr, :c, [:false]],
- [:iter,
- [:fcall, :d],
- [:dasgn_curr, :x],
- [:dasgn, :c, [:true]]],
- [:dvar, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a,
- s(:arglist, s(:call, nil, :b, s(:arglist)))),
- nil,
+ s(:call, nil, :a, s(:call, nil, :b)),
+ s(:args),
s(:if,
- s(:call, nil, :b, s(:arglist)),
+ s(:call, nil, :b),
s(:true),
s(:block,
s(:lasgn, :c, s(:false)),
s(:iter,
- s(:call, nil, :d, s(:arglist)),
- s(:lasgn, :x),
+ s(:call, nil, :d),
+ s(:args, :x),
s(:lasgn, :c, s(:true))),
s(:lvar, :c)))))
add_tests("block_pass_args_and_splat",
"Ruby" => "def blah(*args, &block)\n other(42, *args, &block)\nend",
- "RawParseTree" => [:defn, :blah,
- [:scope,
- [:block,
- [:args, :"*args"],
- [:block_arg, :block],
- [:block_pass,
- [:lvar, :block],
- [:fcall, :other,
- [:argscat,
- [:array, [:lit, 42]], [:lvar, :args]]]]]]],
- "ParseTree" => s(:defn, :blah,
- s(:args, :"*args", :"&block"),
- s(:scope,
- s(:block,
- s(:call, nil, :other,
- s(:arglist,
- s(:lit, 42),
- s(:splat, s(:lvar, :args)),
- s(:block_pass, s(:lvar, :block))))))))
+ "ParseTree" => s(:defn, :blah, s(:args, :"*args", :"&block"),
+ s(:call, nil, :other,
+ s(:lit, 42),
+ s(:splat, s(:lvar, :args)),
+ s(:block_pass, s(:lvar, :block)))))
add_tests("block_pass_call_0",
"Ruby" => "a.b(&c)",
- "RawParseTree" => [:block_pass,
- [:vcall, :c], [:call, [:vcall, :a], :b]],
"ParseTree" => s(:call,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:b,
- s(:arglist,
- s(:block_pass,
- s(:call, nil, :c, s(:arglist))))))
+ s(:block_pass, s(:call, nil, :c))))
add_tests("block_pass_call_1",
"Ruby" => "a.b(4, &c)",
- "RawParseTree" => [:block_pass,
- [:vcall, :c],
- [:call, [:vcall, :a], :b, [:array, [:lit, 4]]]],
"ParseTree" => s(:call,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:b,
- s(:arglist,
- s(:lit, 4),
- s(:block_pass,
- s(:call, nil, :c, s(:arglist))))))
+ s(:lit, 4),
+ s(:block_pass, s(:call, nil, :c))))
add_tests("block_pass_call_n",
"Ruby" => "a.b(1, 2, 3, &c)",
- "RawParseTree" => [:block_pass,
- [:vcall, :c],
- [:call, [:vcall, :a], :b,
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]]],
"ParseTree" => s(:call,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:b,
- s(:arglist,
- s(:lit, 1), s(:lit, 2), s(:lit, 3),
- s(:block_pass,
- s(:call, nil, :c, s(:arglist))))))
+ s(:lit, 1), s(:lit, 2), s(:lit, 3),
+ s(:block_pass, s(:call, nil, :c))))
add_tests("block_pass_fcall_0",
"Ruby" => "a(&b)",
- "RawParseTree" => [:block_pass, [:vcall, :b], [:fcall, :a]],
"ParseTree" => s(:call, nil, :a,
- s(:arglist,
- s(:block_pass,
- s(:call, nil, :b, s(:arglist))))))
+ s(:block_pass, s(:call, nil, :b))))
add_tests("block_pass_fcall_1",
"Ruby" => "a(4, &b)",
- "RawParseTree" => [:block_pass,
- [:vcall, :b],
- [:fcall, :a, [:array, [:lit, 4]]]],
"ParseTree" => s(:call, nil, :a,
- s(:arglist,
- s(:lit, 4),
- s(:block_pass,
- s(:call, nil, :b, s(:arglist))))))
+ s(:lit, 4),
+ s(:block_pass, s(:call, nil, :b))))
add_tests("block_pass_fcall_n",
"Ruby" => "a(1, 2, 3, &b)",
- "RawParseTree" => [:block_pass,
- [:vcall, :b],
- [:fcall, :a,
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]]],
"ParseTree" => s(:call, nil, :a,
- s(:arglist,
- s(:lit, 1), s(:lit, 2), s(:lit, 3),
- s(:block_pass,
- s(:call, nil, :b, s(:arglist))))))
+ s(:lit, 1), s(:lit, 2), s(:lit, 3),
+ s(:block_pass, s(:call, nil, :b))))
add_tests("block_pass_omgwtf",
"Ruby" => "define_attr_method(:x, :sequence_name, &Proc.new { |*args| nil })",
- "RawParseTree" => [:block_pass,
- [:iter,
- [:call, [:const, :Proc], :new],
- [:masgn, nil, [:dasgn_curr, :args], nil],
- [:nil]],
- [:fcall, :define_attr_method,
- [:array, [:lit, :x], [:lit, :sequence_name]]]],
"ParseTree" => s(:call, nil, :define_attr_method,
- s(:arglist,
- s(:lit, :x),
- s(:lit, :sequence_name),
- s(:block_pass,
- s(:iter,
- s(:call, s(:const, :Proc), :new,
- s(:arglist)),
- s(:masgn,
- s(:array, s(:splat, s(:lasgn, :args)))),
- s(:nil))))))
+ s(:lit, :x),
+ s(:lit, :sequence_name),
+ s(:block_pass,
+ s(:iter,
+ s(:call, s(:const, :Proc), :new),
+ s(:args, :"*args"),
+ s(:nil)))))
add_tests("block_pass_splat",
"Ruby" => "def blah(*args, &block)\n other(*args, &block)\nend",
- "RawParseTree" => [:defn, :blah,
- [:scope,
- [:block,
- [:args, :"*args"],
- [:block_arg, :block],
- [:block_pass,
- [:lvar, :block],
- [:fcall, :other,
- [:splat, [:lvar, :args]]]]]]],
"ParseTree" => s(:defn, :blah,
s(:args, :"*args", :"&block"),
- s(:scope,
- s(:block,
- s(:call, nil, :other,
- s(:arglist,
- s(:splat, s(:lvar, :args)),
- s(:block_pass, s(:lvar, :block))))))))
+ s(:call, nil, :other,
+ s(:splat, s(:lvar, :args)),
+ s(:block_pass, s(:lvar, :block)))))
add_tests("block_pass_thingy",
"Ruby" => "r.read_body(dest, &block)",
- "RawParseTree" => [:block_pass,
- [:vcall, :block],
- [:call, [:vcall, :r], :read_body,
- [:array, [:vcall, :dest]]]],
"ParseTree" => s(:call,
- s(:call, nil, :r, s(:arglist)),
+ s(:call, nil, :r),
:read_body,
- s(:arglist,
- s(:call, nil, :dest, s(:arglist)),
- s(:block_pass,
- s(:call, nil, :block, s(:arglist))))))
+ s(:call, nil, :dest),
+ s(:block_pass, s(:call, nil, :block))))
add_tests("block_stmt_after",
"Ruby" => "def f\n begin\n b\n rescue\n c\n end\n\n d\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:rescue,
- [:vcall, :b],
- [:resbody, nil, [:vcall, :c]]],
- [:vcall, :d]]]],
- "ParseTree" => s(:defn, :f,
- s(:args),
- s(:scope,
- s(:block,
- s(:rescue,
- s(:call, nil, :b, s(:arglist)),
- s(:resbody,
- s(:array),
- s(:call, nil, :c, s(:arglist)))),
- s(:call, nil, :d, s(:arglist))))),
+ "ParseTree" => s(:defn, :f, s(:args),
+ s(:rescue,
+ s(:call, nil, :b),
+ s(:resbody,
+ s(:array),
+ s(:call, nil, :c))),
+ s(:call, nil, :d)),
"Ruby2Ruby" => "def f\n b rescue c\n d\nend")
-
- add_tests("block_stmt_after_mri_verbose_flag",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:rescue, # no begin
- [:vcall, :b],
- [:resbody, nil, [:vcall, :c]]],
- [:vcall, :d]]]])
-
copy_test_case "block_stmt_after", "Ruby"
copy_test_case "block_stmt_after", "ParseTree"
copy_test_case "block_stmt_after", "Ruby2Ruby"
add_tests("block_stmt_before",
"Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:vcall, :a],
- [:rescue, [:vcall, :b],
- [:resbody, nil, [:vcall, :c]]]]]],
- "ParseTree" => s(:defn, :f,
- s(:args),
- s(:scope,
- s(:block,
- s(:call, nil, :a, s(:arglist)),
- s(:rescue, s(:call, nil, :b, s(:arglist)),
- s(:resbody,
- s(:array),
- s(:call, nil, :c, s(:arglist))))))),
+ "ParseTree" => s(:defn, :f, s(:args),
+ s(:call, nil, :a),
+ s(:rescue, s(:call, nil, :b),
+ s(:resbody,
+ s(:array),
+ s(:call, nil, :c)))),
"Ruby2Ruby" => "def f\n a\n b rescue c\nend")
-
# oddly... this one doesn't HAVE any differences when verbose... new?
copy_test_case "block_stmt_before", "Ruby"
copy_test_case "block_stmt_before", "ParseTree"
- copy_test_case "block_stmt_before", "RawParseTree"
copy_test_case "block_stmt_before", "Ruby2Ruby"
add_tests("block_stmt_both",
"Ruby" => "def f\n a\n begin\n b\n rescue\n c\n end\n d\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:vcall, :a],
- [: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)),
- s(:rescue,
- s(:call, nil, :b, s(:arglist)),
- s(:resbody,
- s(:array),
- s(:call, nil, :c, s(:arglist)))),
- s(:call, nil, :d, s(:arglist))))),
+ s(:call, nil, :a),
+ s(:rescue,
+ s(:call, nil, :b),
+ s(:resbody,
+ s(:array),
+ s(:call, nil, :c))),
+ s(:call, nil, :d)),
"Ruby2Ruby" => "def f\n a\n b rescue c\n d\nend")
-
- add_tests("block_stmt_both_mri_verbose_flag",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:vcall, :a],
- [:rescue, # no begin
- [:vcall, :b],
- [:resbody,
- nil,
- [:vcall, :c]]],
- [:vcall, :d]]]])
-
copy_test_case "block_stmt_both", "Ruby"
copy_test_case "block_stmt_both", "ParseTree"
copy_test_case "block_stmt_both", "Ruby2Ruby"
add_tests("bmethod",
"Ruby" => [Examples, :unsplatted],
- "RawParseTree" => [:defn, :unsplatted,
- [:bmethod,
- [:dasgn_curr, :x],
- [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]],
- "ParseTree" => s(:defn, :unsplatted,
- s(:args, :x),
- s(:scope,
- s(:block,
- s(:call,
- s(:lvar, :x),
- :+,
- s(:arglist, s(:lit, 1)))))),
+ "ParseTree" => s(:defn, :unsplatted, s(:args, :x),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))),
"Ruby2Ruby" => "def unsplatted(x)\n (x + 1)\nend")
add_tests("bmethod_noargs",
"Ruby" => [Examples, :bmethod_noargs],
- "RawParseTree" => [:defn, :bmethod_noargs,
- [:bmethod,
- nil,
- [:call,
- [:vcall, :x], :"+", [:array, [:lit, 1]]]]],
- "ParseTree" => s(:defn, :bmethod_noargs,
- s(:args),
- s(:scope,
- s(:block,
- s(:call,
- s(:call, nil, :x, s(:arglist)),
- :"+",
- s(:arglist, s(:lit, 1)))))),
+ "ParseTree" => s(:defn, :bmethod_noargs, s(:args),
+ s(:call,
+ s(:call, nil, :x),
+ :"+",
+ s(:lit, 1))),
"Ruby2Ruby" => "def bmethod_noargs\n (x + 1)\nend")
add_tests("bmethod_splat",
"Ruby" => [Examples, :splatted],
- "RawParseTree" => [:defn, :splatted,
- [:bmethod,
- [:masgn, nil, [:dasgn_curr, :args], nil],
- [:block,
- [:dasgn_curr, :y,
- [:call, [:dvar, :args], :first]],
- [:call, [:dvar, :y], :+,
- [:array, [:lit, 42]]]]]],
- "ParseTree" => s(:defn, :splatted,
- s(:args, :"*args"),
- s(:scope,
- s(:block,
- s(:lasgn, :y,
- s(:call, s(:lvar, :args), :first,
- s(:arglist))),
- s(:call, s(:lvar, :y), :+,
- s(:arglist, s(:lit, 42)))))),
+ "ParseTree" => s(:defn, :splatted, s(:args, :"*args"),
+ s(:lasgn, :y,
+ s(:call, s(:lvar, :args), :first)),
+ s(:call, s(:lvar, :y), :+, s(:lit, 42))),
"Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend")
add_tests("break",
"Ruby" => "loop { break if true }",
- "RawParseTree" => [:iter,
- [:fcall, :loop], nil,
- [:if, [:true], [:break], nil]],
"ParseTree" => s(:iter,
- s(:call, nil, :loop, s(:arglist)), nil,
+ s(:call, nil, :loop),
+ s(:args),
s(:if, s(:true), s(:break), nil)))
add_tests("break_arg",
"Ruby" => "loop { break 42 if true }",
- "RawParseTree" => [:iter,
- [:fcall, :loop], nil,
- [:if, [:true], [:break, [:lit, 42]], nil]],
"ParseTree" => s(:iter,
- s(:call, nil, :loop, s(:arglist)), nil,
+ s(:call, nil, :loop),
+ s(:args),
s(:if, s(:true), s(:break, s(:lit, 42)), nil)))
add_tests("call",
"Ruby" => "self.method",
- "RawParseTree" => [:call, [:self], :method],
- "ParseTree" => s(:call, s(:self), :method, s(:arglist)))
+ "ParseTree" => s(:call, s(:self), :method))
add_tests("call_arglist",
"Ruby" => "o.puts(42)",
- "RawParseTree" => [:call, [:vcall, :o], :puts,
- [:array, [:lit, 42]]],
- "ParseTree" => s(:call, s(:call, nil, :o, s(:arglist)), :puts,
- s(:arglist, s(:lit, 42))))
+ "ParseTree" => s(:call, s(:call, nil, :o), :puts, s(:lit, 42)))
add_tests("call_arglist_hash",
"Ruby" => "o.m(:a => 1, :b => 2)",
- "RawParseTree" => [:call,
- [:vcall, :o], :m,
- [:array,
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]]],
"ParseTree" => s(:call,
- s(:call, nil, :o, s(:arglist)), :m,
- s(:arglist,
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)))))
+ s(:call, nil, :o), :m,
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))))
add_tests("call_arglist_norm_hash",
"Ruby" => "o.m(42, :a => 1, :b => 2)",
- "RawParseTree" => [:call,
- [:vcall, :o], :m,
- [:array,
- [:lit, 42],
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]]],
"ParseTree" => s(:call,
- s(:call, nil, :o, s(:arglist)), :m,
- s(:arglist,
- s(:lit, 42),
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)))))
-
- add_tests("call_arglist_norm_hash_splat",
- "Ruby" => "o.m(42, :a => 1, :b => 2, *c)",
- "RawParseTree" => [:call,
- [:vcall, :o], :m,
- [:argscat,
- [:array,
- [:lit, 42],
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]],
- [:vcall, :c]]],
- "ParseTree" => s(:call,
- s(:call, nil, :o, s(:arglist)), :m,
- s(:arglist,
- s(:lit, 42),
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)),
- s(:splat, s(:call, nil, :c, s(:arglist))))))
-
- add_tests("call_arglist_space",
- "Ruby" => "a (1,2,3)",
- "RawParseTree" => [:fcall, :a,
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
- "ParseTree" => s(:call, nil, :a,
- s(:arglist,
- s(:lit, 1), s(:lit, 2), s(:lit, 3))),
- "Ruby2Ruby" => "a(1, 2, 3)")
+ s(:call, nil, :o), :m,
+ s(:lit, 42),
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))))
add_tests("call_command",
"Ruby" => "1.b(c)",
- "RawParseTree" => [:call, [:lit, 1], :b, [:array, [:vcall, :c]]],
"ParseTree" => s(:call,
s(:lit, 1),
:b,
- s(:arglist, s(:call, nil, :c, s(:arglist)))))
+ s(:call, nil, :c)))
add_tests("call_expr",
"Ruby" => "(v = (1 + 1)).zero?",
- "RawParseTree" => [:call,
- [:lasgn, :v,
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
- :zero?],
"ParseTree" => s(:call,
s(:lasgn, :v,
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1)))),
- :zero?, s(:arglist)))
+ s(:call, s(:lit, 1), :+, s(:lit, 1))),
+ :zero?))
add_tests("call_index",
"Ruby" => "a = []\na[42]\n",
- "RawParseTree" => [:block,
- [:lasgn, :a, [:zarray]],
- [:call, [:lvar, :a], :[], [:array, [:lit, 42]]]],
"ParseTree" => s(:block,
s(:lasgn, :a, s(:array)),
- s(:call, s(:lvar, :a), :[],
- s(:arglist, s(:lit, 42)))))
+ s(:call, s(:lvar, :a), :[], s(:lit, 42))))
add_tests("call_index_no_args",
"Ruby" => "a[]",
- "RawParseTree" => [:call, [:vcall, :a], :[]],
- "ParseTree" => s(:call, s(:call, nil, :a, s(:arglist)),
- :[], s(:arglist)))
+ "ParseTree" => s(:call, s(:call, nil, :a),
+ :[]))
add_tests("call_index_space",
"Ruby" => "a = []\na [42]\n",
- "RawParseTree" => [:block,
- [:lasgn, :a, [:zarray]],
- [:call, [:lvar, :a], :[], [:array, [:lit, 42]]]],
"ParseTree" => s(:block,
s(:lasgn, :a, s(:array)),
- s(:call, s(:lvar, :a), :[],
- s(:arglist, s(:lit, 42)))),
+ s(:call, s(:lvar, :a), :[], s(:lit, 42))),
"Ruby2Ruby" => "a = []\na[42]\n")
+ add_tests("call_no_space_symbol",
+ "Ruby" => "foo:bar",
+ "ParseTree" => s(:call, nil, :foo, s(:lit, :bar)),
+ "Ruby2Ruby" => "foo(:bar)")
+
add_tests("call_unary_neg",
"Ruby" => "-2**31",
- "RawParseTree" => [:call,
- [:call, [:lit, 2], :**, [:array, [:lit, 31]]],
- :-@],
"ParseTree" => s(:call,
- s(:call,
- s(:lit, 2),
- :**,
- s(:arglist, s(:lit, 31))),
- :-@, s(:arglist)),
+ s(:call, s(:lit, 2), :**, s(:lit, 31)),
+ :-@),
"Ruby2Ruby" => "-(2 ** 31)")
add_tests("case",
"Ruby" => "var = 2\nresult = \"\"\ncase var\nwhen 1 then\n puts(\"something\")\n result = \"red\"\nwhen 2, 3 then\n result = \"yellow\"\nwhen 4 then\n # do nothing\nelse\n result = \"green\"\nend\ncase result\nwhen \"red\" then\n var = 1\nwhen \"yellow\" then\n var = 2\nwhen \"green\" then\n var = 3\nelse\n # do nothing\nend\n",
- "RawParseTree" => [:block,
- [:lasgn, :var, [:lit, 2]],
- [:lasgn, :result, [:str, ""]],
- [:case,
- [:lvar, :var],
- [:when,
- [:array, [:lit, 1]],
- [:block,
- [:fcall, :puts,
- [:array, [:str, "something"]]],
- [:lasgn, :result, [:str, "red"]]]],
- [:when,
- [:array, [:lit, 2], [:lit, 3]],
- [:lasgn, :result, [:str, "yellow"]]],
- [:when, [:array, [:lit, 4]], nil],
- [:lasgn, :result, [:str, "green"]]],
- [:case,
- [:lvar, :result],
- [:when, [:array, [:str, "red"]],
- [:lasgn, :var, [:lit, 1]]],
- [:when, [:array, [:str, "yellow"]],
- [:lasgn, :var, [:lit, 2]]],
- [:when, [:array, [:str, "green"]],
- [:lasgn, :var, [:lit, 3]]],
- nil]],
"ParseTree" => s(:block,
s(:lasgn, :var, s(:lit, 2)),
s(:lasgn, :result, s(:str, "")),
@@ -991,10 +1058,8 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
s(:lvar, :var),
s(:when,
s(:array, s(:lit, 1)),
- s(:block,
- s(:call, nil, :puts,
- s(:arglist, s(:str, "something"))),
- s(:lasgn, :result, s(:str, "red")))),
+ s(:call, nil, :puts, s(:str, "something")),
+ s(:lasgn, :result, s(:str, "red"))),
s(:when,
s(:array, s(:lit, 2), s(:lit, 3)),
s(:lasgn, :result, s(:str, "yellow"))),
@@ -1012,29 +1077,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("case_nested",
"Ruby" => "var1 = 1\nvar2 = 2\nresult = nil\ncase var1\nwhen 1 then\n case var2\n when 1 then\n result = 1\n when 2 then\n result = 2\n else\n result = 3\n end\nwhen 2 then\n case var2\n when 1 then\n result = 4\n when 2 then\n result = 5\n else\n result = 6\n end\nelse\n result = 7\nend\n",
- "RawParseTree" => [:block,
- [:lasgn, :var1, [:lit, 1]],
- [:lasgn, :var2, [:lit, 2]],
- [:lasgn, :result, [:nil]],
- [:case,
- [:lvar, :var1],
- [:when, [:array, [:lit, 1]],
- [:case,
- [:lvar, :var2],
- [:when, [:array, [:lit, 1]],
- [:lasgn, :result, [:lit, 1]]],
- [:when, [:array, [:lit, 2]],
- [:lasgn, :result, [:lit, 2]]],
- [:lasgn, :result, [:lit, 3]]]],
- [:when, [:array, [:lit, 2]],
- [:case,
- [:lvar, :var2],
- [:when, [:array, [:lit, 1]],
- [:lasgn, :result, [:lit, 4]]],
- [:when, [:array, [:lit, 2]],
- [:lasgn, :result, [:lit, 5]]],
- [:lasgn, :result, [:lit, 6]]]],
- [:lasgn, :result, [:lit, 7]]]],
"ParseTree" => s(:block,
s(:lasgn, :var1, s(:lit, 1)),
s(:lasgn, :var2, s(:lit, 2)),
@@ -1061,337 +1103,176 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("case_nested_inner_no_expr",
"Ruby" => "case a\nwhen b then\n case\n when (d and e) then\n f\n else\n # do nothing\n end\nelse\n # do nothing\nend",
- "RawParseTree" => [:case, [:vcall, :a],
- [:when, [:array, [:vcall, :b]],
- [:case, nil,
- [:when,
- [:array, [:and, [:vcall, :d], [:vcall, :e]]],
- [:vcall, :f]],
- nil]],
- nil],
- "ParseTree" => s(:case, s(:call, nil, :a, s(:arglist)),
+ "ParseTree" => s(:case, s(:call, nil, :a),
s(:when,
- s(:array, s(:call, nil, :b, s(:arglist))),
+ s(:array, s(:call, nil, :b)),
s(:case, nil,
s(:when,
s(:array,
s(:and,
- s(:call, nil, :d, s(:arglist)),
- s(:call, nil, :e, s(:arglist)))),
- s(:call, nil, :f, s(:arglist))),
+ s(:call, nil, :d),
+ s(:call, nil, :e))),
+ s(:call, nil, :f)),
nil)),
nil))
add_tests("case_no_expr",
"Ruby" => "case\nwhen (a == 1) then\n :a\nwhen (a == 2) then\n :b\nelse\n :c\nend",
- "RawParseTree" => [:case, nil,
- [:when,
- [:array,
- [:call, [:vcall, :a], :==,
- [:array, [:lit, 1]]]],
- [:lit, :a]],
- [:when,
- [:array,
- [:call, [:vcall, :a], :==,
- [:array, [:lit, 2]]]],
- [:lit, :b]],
- [:lit, :c]],
"ParseTree" => s(:case, nil,
s(:when,
s(:array,
s(:call,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:==,
- s(:arglist, s(:lit, 1)))),
+ s(:lit, 1))),
s(:lit, :a)),
s(:when,
s(:array,
s(:call,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
:==,
- s(:arglist, s(:lit, 2)))),
+ s(:lit, 2))),
s(:lit, :b)),
s(:lit, :c)))
add_tests("case_splat",
"Ruby" => "case a\nwhen :b, *c then\n d\nelse\n e\nend",
- "RawParseTree" => [:case, [:vcall, :a],
- [:when,
- [:array,
- [:lit, :b], [:when, [:vcall, :c], nil]], # wtf?
- [:vcall, :d]],
- [:vcall, :e]],
- "ParseTree" => s(:case, s(:call, nil, :a, s(:arglist)),
+ "ParseTree" => s(:case, s(:call, nil, :a),
s(:when,
s(:array,
s(:lit, :b),
- s(:when,
- s(:call, nil, :c, s(:arglist)),
- nil)), # wtf?
- s(:call, nil, :d, s(:arglist))),
- s(:call, nil, :e, s(:arglist))))
+ s(:splat, s(:call, nil, :c))),
+ s(:call, nil, :d)),
+ s(:call, nil, :e)))
add_tests("cdecl",
"Ruby" => "X = 42",
- "RawParseTree" => [:cdecl, :X, [:lit, 42]],
"ParseTree" => s(:cdecl, :X, s(:lit, 42)))
add_tests("class_plain",
- "Ruby" => "class X\n puts((1 + 1))\n def blah\n puts(\"hello\")\n end\nend",
- "RawParseTree" => [:class,
- :X,
- nil,
- [:scope,
- [:block,
- [:fcall, :puts,
- [:array,
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]]]],
- [:defn, :blah,
- [:scope,
- [:block,
- [:args],
- [:fcall, :puts,
- [:array, [:str, "hello"]]]]]]]]],
- "ParseTree" => s(:class,
- :X,
- nil,
- s(:scope,
- s(:block,
- s(:call, nil, :puts,
- s(:arglist,
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))))),
- s(:defn, :blah,
- s(:args),
- s(:scope,
- s(:block,
- s(:call, nil, :puts,
- s(:arglist,
- s(:str, "hello"))))))))))
+ "Ruby" => "class X\n puts((1 + 1))\n \n def blah\n puts(\"hello\")\n end\nend",
+ "ParseTree" => s(:class, :X, nil,
+ s(:call, nil, :puts,
+ s(:call, s(:lit, 1), :+, s(:lit, 1))),
+ s(:defn, :blah, s(:args),
+ s(:call, nil, :puts, s(:str, "hello")))))
add_tests("class_scoped",
"Ruby" => "class X::Y\n c\nend",
- "RawParseTree" => [:class, [:colon2, [:const, :X], :Y], nil,
- [:scope, [:vcall, :c]]],
"ParseTree" => s(:class, s(:colon2, s(:const, :X), :Y), nil,
- s(:scope, s(:call, nil, :c, s(:arglist)))))
+ s(:call, nil, :c)))
add_tests("class_scoped3",
"Ruby" => "class ::Y\n c\nend",
- "RawParseTree" => [:class, [:colon3, :Y], nil,
- [:scope, [:vcall, :c]]],
"ParseTree" => s(:class, s(:colon3, :Y), nil,
- s(:scope, s(:call, nil, :c, s(:arglist)))))
+ s(:call, nil, :c)))
add_tests("class_super_array",
"Ruby" => "class X < Array\nend",
- "RawParseTree" => [:class,
- :X,
- [:const, :Array],
- [:scope]],
- "ParseTree" => s(:class,
- :X,
- s(:const, :Array),
- s(:scope)))
+ "ParseTree" => s(:class, :X, s(:const, :Array)))
add_tests("class_super_expr",
"Ruby" => "class X < expr\nend",
- "RawParseTree" => [:class,
- :X,
- [:vcall, :expr],
- [:scope]],
- "ParseTree" => s(:class,
- :X,
- s(:call, nil, :expr, s(:arglist)),
- s(:scope)))
+ "ParseTree" => s(:class, :X, s(:call, nil, :expr)))
add_tests("class_super_object",
"Ruby" => "class X < Object\nend",
- "RawParseTree" => [:class,
- :X,
- [:const, :Object],
- [:scope]],
- "ParseTree" => s(:class,
- :X,
- s(:const, :Object),
- s(:scope)))
+ "ParseTree" => s(:class, :X, s(:const, :Object)))
add_tests("colon2",
"Ruby" => "X::Y",
- "RawParseTree" => [:colon2, [:const, :X], :Y],
"ParseTree" => s(:colon2, s(:const, :X), :Y))
add_tests("colon3",
"Ruby" => "::X",
- "RawParseTree" => [:colon3, :X],
"ParseTree" => s(:colon3, :X))
add_tests("const",
"Ruby" => "X",
- "RawParseTree" => [:const, :X],
"ParseTree" => s(:const, :X))
add_tests("constX",
"Ruby" => "X = 1",
- "RawParseTree" => [:cdecl, :X, [:lit, 1]],
"ParseTree" => s(:cdecl, :X, s(:lit, 1)))
add_tests("constY",
"Ruby" => "::X = 1",
- "RawParseTree" => [:cdecl, [:colon3, :X], [:lit, 1]],
"ParseTree" => s(:cdecl, s(:colon3, :X), s(:lit, 1)))
add_tests("constZ",
"Ruby" => "X::Y = 1",
- "RawParseTree" => [:cdecl, [:colon2, [:const, :X], :Y], [:lit, 1]],
"ParseTree" => s(:cdecl,
s(:colon2, s(:const, :X), :Y),
s(:lit, 1)))
add_tests("cvar",
"Ruby" => "@@x",
- "RawParseTree" => [:cvar, :@@x],
"ParseTree" => s(:cvar, :@@x))
add_tests("cvasgn",
"Ruby" => "def x\n @@blah = 1\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block, [:args],
- [:cvasgn, :@@blah, [:lit, 1]]]]],
- "ParseTree" => s(:defn, :x,
- s(:args),
- s(:scope,
- s(:block,
- s(:cvasgn, :@@blah, s(:lit, 1))))))
+ "ParseTree" => s(:defn, :x, s(:args),
+ s(:cvasgn, :@@blah, s(:lit, 1))))
add_tests("cvasgn_cls_method",
"Ruby" => "def self.quiet_mode=(boolean)\n @@quiet_mode = boolean\nend",
- "RawParseTree" => [:defs, [:self], :quiet_mode=,
- [:scope,
- [:block,
- [:args, :boolean],
- [:cvasgn, :@@quiet_mode, [:lvar, :boolean]]]]],
"ParseTree" => s(:defs, s(:self), :quiet_mode=,
s(:args, :boolean),
- s(:scope,
- s(:block,
- s(:cvasgn, :@@quiet_mode,
- s(:lvar, :boolean))))))
+ s(:cvasgn, :@@quiet_mode,
+ s(:lvar, :boolean))))
add_tests("cvdecl",
"Ruby" => "class X\n @@blah = 1\nend",
- "RawParseTree" => [:class, :X, nil,
- [:scope, [:cvdecl, :@@blah, [:lit, 1]]]],
"ParseTree" => s(:class, :X, nil,
- s(:scope, s(:cvdecl, :@@blah, s(:lit, 1)))))
+ s(:cvdecl, :@@blah, s(:lit, 1))))
add_tests("dasgn_0",
"Ruby" => "a.each { |x| b.each { |y| x = (x + 1) } if true }",
- "RawParseTree" => [:iter,
- [:call, [:vcall, :a], :each],
- [:dasgn_curr, :x],
- [:if, [:true],
- [:iter,
- [:call, [:vcall, :b], :each],
- [:dasgn_curr, :y],
- [:dasgn, :x,
- [:call, [:dvar, :x], :+,
- [:array, [:lit, 1]]]]],
- nil]],
"ParseTree" => s(:iter,
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
- s(:arglist)),
- s(:lasgn, :x),
+ s(:call, s(:call, nil, :a), :each),
+ s(:args, :x),
s(:if, s(:true),
s(:iter,
- s(:call, s(:call, nil, :b, s(:arglist)),
- :each,
- s(:arglist)),
- s(:lasgn, :y),
+ s(:call, s(:call, nil, :b), :each),
+ s(:args, :y),
s(:lasgn, :x,
- s(:call, s(:lvar, :x), :+,
- s(:arglist, s(:lit, 1))))),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1)))),
nil)))
add_tests("dasgn_1",
"Ruby" => "a.each { |x| b.each { |y| c = (c + 1) } if true }",
- "RawParseTree" => [:iter,
- [:call, [:vcall, :a], :each],
- [:dasgn_curr, :x],
- [:if, [:true],
- [:iter,
- [:call, [:vcall, :b], :each],
- [:dasgn_curr, :y],
- [:dasgn_curr, :c,
- [:call, [:dvar, :c], :+,
- [:array, [:lit, 1]]]]],
- nil]],
"ParseTree" => s(:iter,
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
- s(:arglist)),
- s(:lasgn, :x),
+ s(:call, s(:call, nil, :a), :each),
+ s(:args, :x),
s(:if, s(:true),
s(:iter,
- s(:call, s(:call, nil, :b, s(:arglist)),
- :each,
- s(:arglist)),
- s(:lasgn, :y),
+ s(:call, s(:call, nil, :b), :each),
+ s(:args, :y),
s(:lasgn, :c,
- s(:call, s(:lvar, :c), :+,
- s(:arglist, s(:lit, 1))))),
+ s(:call, s(:lvar, :c), :+, s(:lit, 1)))),
nil)))
add_tests("dasgn_2",
- "Ruby" => "a.each do |x|\n if true then\n c = 0\n b.each { |y| c = (c + 1) }\n end\nend", # FIX: hate that extra newline!
- "RawParseTree" => [:iter,
- [:call, [:vcall, :a], :each],
- [:dasgn_curr, :x],
- [:if, [:true],
- [:block,
- [:dasgn_curr, :c, [:lit, 0]],
- [:iter,
- [:call, [:vcall, :b], :each],
- [:dasgn_curr, :y],
- [:dasgn, :c,
- [:call, [:dvar, :c], :+,
- [:array, [:lit, 1]]]]]],
- nil]],
+ "Ruby" => "a.each do |x|\n if true then\n c = 0\n b.each { |y| c = (c + 1) }\n end\nend",
"ParseTree" => s(:iter,
- s(:call, s(:call, nil, :a, s(:arglist)), :each,
- s(:arglist)),
- s(:lasgn, :x),
+ s(:call, s(:call, nil, :a), :each),
+ s(:args, :x),
s(:if, s(:true),
s(:block,
s(:lasgn, :c, s(:lit, 0)),
s(:iter,
- s(:call, s(:call, nil, :b, s(:arglist)),
- :each,
- s(:arglist)),
- s(:lasgn, :y),
+ s(:call, s(:call, nil, :b), :each),
+ s(:args, :y),
s(:lasgn, :c,
s(:call, s(:lvar, :c), :+,
- s(:arglist, s(:lit, 1)))))),
+ s(:lit, 1))))),
nil)))
add_tests("dasgn_curr",
"Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
- "RawParseTree" => [:iter,
- [:call, [:vcall, :data], :each],
- [:masgn,
- [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]],
- nil, nil],
- [:block,
- [:dasgn_curr, :a, [:lit, 1]],
- [:dasgn_curr, :b, [:dvar, :a]],
- [:dasgn_curr, :b,
- [:dasgn_curr, :a, [:dvar, :x]]]]],
"ParseTree" => s(:iter,
- s(:call, s(:call, nil, :data,
- s(:arglist)), :each, s(:arglist)),
- s(:masgn,
- s(:array, s(:lasgn, :x), s(:lasgn, :y))),
+ s(:call, s(:call, nil, :data), :each),
+ s(:args, :x, :y),
s(:block,
s(:lasgn, :a, s(:lit, 1)),
s(:lasgn, :b, s(:lvar, :a)),
@@ -1399,33 +1280,15 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dasgn_icky",
"Ruby" => "a do\n v = nil\n assert_block(full_message) do\n begin\n yield\n rescue Exception => v\n break\n end\n end\nend",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- nil,
- [:block,
- [:dasgn_curr, :v, [:nil]],
- [:iter,
- [:fcall, :assert_block,
- [:array, [:vcall, :full_message]]],
- nil,
- [:rescue,
- [:yield],
- [:resbody,
- [:array, [:const, :Exception]],
- [:block,
- [:dasgn, :v,
- [:gvar, :$!]], [:break]]]]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- nil,
+ s(:call, nil, :a),
+ s(:args),
s(:block,
s(:lasgn, :v, s(:nil)),
s(:iter,
s(:call, nil, :assert_block,
- s(:arglist,
- s(:call, nil, :full_message,
- s(:arglist)))),
- nil,
+ s(:call, nil, :full_message)),
+ s(:args),
s(:rescue,
s(:yield),
s(:resbody,
@@ -1436,523 +1299,253 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dasgn_mixed",
"Ruby" => "t = 0\nns.each { |n| t += n }\n",
- "RawParseTree" => [:block,
- [:lasgn, :t, [:lit, 0]],
- [:iter,
- [:call, [:vcall, :ns], :each],
- [:dasgn_curr, :n],
- [:lasgn, :t,
- [:call, [:lvar, :t], :+,
- [:array, [:dvar, :n]]]]]],
"ParseTree" => s(:block,
s(:lasgn, :t, s(:lit, 0)),
s(:iter,
- s(:call, s(:call, nil, :ns,
- s(:arglist)), :each, s(:arglist)),
- s(:lasgn, :n),
+ s(:call, s(:call, nil, :ns), :each),
+ s(:args, :n),
s(:lasgn, :t,
- s(:call, s(:lvar, :t), :+,
- s(:arglist, s(:lvar, :n)))))),
+ s(:call, s(:lvar, :t), :+, s(:lvar, :n))))),
"Ruby2Ruby" => "t = 0\nns.each { |n| t = (t + n) }\n")
add_tests("defined",
"Ruby" => "defined? $x",
- "RawParseTree" => [:defined, [:gvar, :$x]],
"ParseTree" => s(:defined, s(:gvar, :$x)))
- # TODO: make all the defn_args* p their arglist
- add_tests("defn_args_block",
+ add_tests("defn_args_block", # TODO: make all the defn_args* p their arglist
"Ruby" => "def f(&block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args],
- [:block_arg, :block],
- [:nil]]]],
- "ParseTree" => s(:defn, :f,
- s(:args, :"&block"),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :f, s(:args, :"&block"),
+ s(:nil)))
add_tests("defn_args_mand",
"Ruby" => "def f(mand)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand],
- [:nil]]]],
- "ParseTree" => s(:defn, :f,
- s(:args, :mand),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :f, s(:args, :mand),
+ s(:nil)))
add_tests("defn_args_mand_block",
"Ruby" => "def f(mand, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand],
- [:block_arg, :block],
- [:nil]]]],
- "ParseTree" => s(:defn, :f,
- s(:args, :mand, :"&block"),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :f, s(:args, :mand, :"&block"),
+ s(:nil)))
add_tests("defn_args_mand_opt",
"Ruby" => "def f(mand, opt = 42)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :opt,
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :mand, :opt,
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, :mand, s(:lasgn, :opt, s(:lit, 42))),
+ s(:nil)))
add_tests("defn_args_mand_opt_block",
"Ruby" => "def f(mand, opt = 42, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :opt,
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:block_arg, :block],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :mand, :opt, :"&block",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, :mand, s(:lasgn, :opt, s(:lit, 42)), :"&block"),
+ s(:nil)))
add_tests("defn_args_mand_opt_splat",
"Ruby" => "def f(mand, opt = 42, *rest)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :opt, :"*rest",
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :mand, :opt, :"*rest",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, :mand, s(:lasgn, :opt, s(:lit, 42)), :"*rest"),
+ s(:nil)))
add_tests("defn_args_mand_opt_splat_block",
"Ruby" => "def f(mand, opt = 42, *rest, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :opt, :"*rest",
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:block_arg, :block],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :mand, :opt, :"*rest", :"&block",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, :mand, s(:lasgn, :opt, s(:lit, 42)), :"*rest", :"&block"),
+ s(:nil)))
add_tests("defn_args_mand_opt_splat_no_name",
"Ruby" => "def x(a, b = 42, *)\n # do nothing\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :a, :b, :"*",
- [:block, [:lasgn, :b, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :x,
- s(:args, :a, :b, :"*",
- s(:block, s(:lasgn, :b, s(:lit, 42)))),
- s(:scope,
- s(:block,
- s(:nil)))))
+ s(:args, :a, s(:lasgn, :b, s(:lit, 42)), :"*"),
+ s(:nil)))
add_tests("defn_args_mand_splat",
"Ruby" => "def f(mand, *rest)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :"*rest"],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
s(:args, :mand, :"*rest"),
- s(:scope, s(:block, s(:nil)))))
+ s(:nil)))
add_tests("defn_args_mand_splat_block",
"Ruby" => "def f(mand, *rest, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :mand, :"*rest"],
- [:block_arg, :block],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
s(:args, :mand, :"*rest", :"&block"),
- s(:scope, s(:block, s(:nil)))))
+ s(:nil)))
add_tests("defn_args_mand_splat_no_name",
"Ruby" => "def x(a, *args)\n p(a, args)\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :a, :"*args"],
- [:fcall, :p,
- [:array, [:lvar, :a], [:lvar, :args]]]]]],
- "ParseTree" => s(:defn, :x,
- s(:args, :a, :"*args"),
- s(:scope,
- s(:block,
- s(:call, nil, :p,
- s(:arglist, s(:lvar, :a), s(:lvar, :args)))))))
+ "ParseTree" => s(:defn, :x, s(:args, :a, :"*args"),
+ s(:call, nil, :p,
+ s(:lvar, :a), s(:lvar, :args))))
add_tests("defn_args_none",
"Ruby" => "def empty\n # do nothing\nend",
- "RawParseTree" => [:defn, :empty,
- [:scope, [:block, [:args], [:nil]]]],
- "ParseTree" => s(:defn, :empty,
- s(:args),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :empty, s(:args),
+ s(:nil)))
add_tests("defn_args_opt",
"Ruby" => "def f(opt = 42)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :opt,
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :opt,
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, s(:lasgn, :opt, s(:lit, 42))),
+ s(:nil)))
add_tests("defn_args_opt_block",
"Ruby" => "def f(opt = 42, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :opt,
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:block_arg, :block],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :opt, :"&block",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, s(:lasgn, :opt, s(:lit, 42)), :"&block"),
+ s(:nil)))
add_tests("defn_args_opt_splat",
"Ruby" => "def f(opt = 42, *rest)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :opt, :"*rest",
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :opt, :"*rest",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args, s(:lasgn, :opt, s(:lit, 42)), :"*rest"),
+ s(:nil)))
add_tests("defn_args_opt_splat_block",
"Ruby" => "def f(opt = 42, *rest, &block)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :opt, :"*rest",
- [:block,
- [:lasgn, :opt, [:lit, 42]]]],
- [:block_arg, :block],
- [:nil]]]],
"ParseTree" => s(:defn, :f,
- s(:args, :opt, :"*rest", :"&block",
- s(:block,
- s(:lasgn, :opt, s(:lit, 42)))),
- s(:scope, s(:block, s(:nil)))))
+ s(:args,
+ s(:lasgn, :opt, s(:lit, 42)),
+ :"*rest", :"&block"),
+ s(:nil)))
add_tests("defn_args_opt_splat_no_name",
"Ruby" => "def x(b = 42, *)\n # do nothing\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :b, :"*",
- [:block, [:lasgn, :b, [:lit, 42]]]],
- [:nil]]]],
"ParseTree" => s(:defn, :x,
- s(:args, :b, :"*",
- s(:block, s(:lasgn, :b, s(:lit, 42)))),
- s(:scope,
- s(:block,
- s(:nil)))))
+ s(:args, s(:lasgn, :b, s(:lit, 42)), :"*"),
+ s(:nil)))
add_tests("defn_args_splat",
"Ruby" => "def f(*rest)\n # do nothing\nend",
- "RawParseTree" => [:defn, :f,
- [:scope,
- [:block,
- [:args, :"*rest"],
- [:nil]]]],
- "ParseTree" => s(:defn, :f,
- s(:args, :"*rest"),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :f, s(:args, :"*rest"),
+ s(:nil)))
add_tests("defn_args_splat_no_name",
"Ruby" => "def x(*)\n # do nothing\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :"*"],
- [:nil]]]],
- "ParseTree" => s(:defn, :x,
- s(:args, :"*"),
- s(:scope,
- s(:block,
- s(:nil)))))
+ "ParseTree" => s(:defn, :x, s(:args, :"*"),
+ s(:nil)))
add_tests("defn_or",
"Ruby" => "def |(o)\n # do nothing\nend",
- "RawParseTree" => [:defn, :|,
- [:scope, [:block, [:args, :o], [:nil]]]],
- "ParseTree" => s(:defn, :|,
- s(:args, :o),
- s(:scope, s(:block, s(:nil)))))
+ "ParseTree" => s(:defn, :|, s(:args, :o),
+ s(:nil)))
add_tests("defn_rescue",
"Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid)\nrescue\n false\nend",
- "RawParseTree" => [:defn, :eql?,
- [:scope,
- [:block,
- [:args, :resource],
- [:rescue,
- [:call,
- [:call, [:self], :uuid],
- :==,
- [:array,
- [:call, [:lvar, :resource], :uuid]]],
- [:resbody, nil, [:false]]]]]],
"ParseTree" => s(:defn, :eql?,
s(:args, :resource),
- s(:scope,
- s(:block,
- s(:rescue,
- s(:call,
- s(:call, s(:self), :uuid, s(:arglist)),
- :==,
- s(:arglist,
- s(:call, s(:lvar, :resource),
- :uuid, s(:arglist)))),
- s(:resbody, s(:array), s(:false)))))),
+ s(:rescue,
+ s(:call,
+ s(:call, s(:self), :uuid),
+ :==,
+ s(:call, s(:lvar, :resource), :uuid)),
+ s(:resbody, s(:array), s(:false)))),
"Ruby2Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend")
add_tests("defn_rescue_mri_verbose_flag",
"Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid)\nrescue\n false\nend",
- "RawParseTree" => [:defn, :eql?,
- [:scope,
- [:block,
- [:args, :resource],
- [:rescue,
- [:call,
- [:call, [:self], :uuid],
- :==,
- [:array,
- [:call, [:lvar, :resource], :uuid]]],
- [:resbody, nil, [:false]]]]]],
"ParseTree" => s(:defn, :eql?,
s(:args, :resource),
- s(:scope,
- s(:block,
- s(:rescue,
- s(:call,
- s(:call, s(:self), :uuid, s(:arglist)),
- :==,
- s(:arglist,
- s(:call, s(:lvar, :resource),
- :uuid, s(:arglist)))),
- s(:resbody, s(:array), s(:false)))))),
+ s(:rescue,
+ s(:call,
+ s(:call, s(:self), :uuid),
+ :==,
+ s(:call, s(:lvar, :resource), :uuid)),
+ s(:resbody, s(:array), s(:false)))),
"Ruby2Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend")
add_tests("defn_something_eh",
"Ruby" => "def something?\n # do nothing\nend",
- "RawParseTree" => [:defn, :something?,
- [:scope, [:block, [:args], [:nil]]]],
"ParseTree" => s(:defn, :something?,
s(:args),
- s(:scope, s(:block, s(:nil)))))
+ s(:nil)))
add_tests("defn_splat_no_name",
"Ruby" => "def x(a, *)\n p(a)\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :a, :"*"],
- [:fcall, :p,
- [:array, [:lvar, :a]]]]]],
"ParseTree" => s(:defn, :x,
s(:args, :a, :"*"),
- s(:scope,
- s(:block,
- s(:call, nil, :p,
- s(:arglist, s(:lvar, :a)))))))
+ s(:call, nil, :p, s(:lvar, :a))))
add_tests("defn_zarray",
"Ruby" => "def zarray\n a = []\n return a\nend",
- "RawParseTree" => [:defn, :zarray,
- [:scope,
- [:block, [:args],
- [:lasgn, :a, [:zarray]],
- [:return, [:lvar, :a]]]]],
"ParseTree" => s(:defn, :zarray,
s(:args),
- s(:scope,
- s(:block,
- s(:lasgn, :a, s(:array)),
- s(:return, s(:lvar, :a))))))
+ s(:lasgn, :a, s(:array)),
+ s(:return, s(:lvar, :a))))
add_tests("defs",
"Ruby" => "def self.x(y)\n (y + 1)\nend",
- "RawParseTree" => [:defs, [:self], :x,
- [:scope,
- [:block,
- [:args, :y],
- [:call, [:lvar, :y], :+,
- [:array, [:lit, 1]]]]]],
"ParseTree" => s(:defs, s(:self), :x,
s(:args, :y),
- s(:scope,
- s(:block,
- s(:call, s(:lvar, :y), :+,
- s(:arglist, s(:lit, 1)))))))
+ s(:call, s(:lvar, :y), :+, s(:lit, 1))))
add_tests("defs_empty",
"Ruby" => "def self.empty\n # do nothing\nend",
- "RawParseTree" => [:defs, [:self], :empty,
- [:scope, [:args]]],
- "ParseTree" => s(:defs, s(:self), :empty,
- s(:args),
- s(:scope, s(:block))))
+ "ParseTree" => s(:defs, s(:self), :empty, s(:args)))
add_tests("defs_empty_args",
"Ruby" => "def self.empty(*)\n # do nothing\nend",
- "RawParseTree" => [:defs, [:self], :empty,
- [:scope, [:args, :*]]],
"ParseTree" => s(:defs, s(:self), :empty,
- s(:args, :*),
- s(:scope, s(:block))))
+ s(:args, :*)))
add_tests("defs_expr_wtf",
"Ruby" => "def (a.b).empty(*)\n # do nothing\nend",
- "RawParseTree" => [:defs,
- [:call, [:vcall, :a], :b],
- :empty,
- [:scope, [:args, :*]]],
"ParseTree" => s(:defs,
- s(:call,
- s(:call, nil, :a, s(:arglist)),
- :b, s(:arglist)),
+ s(:call, s(:call, nil, :a), :b),
:empty,
- s(:args, :*),
- s(:scope, s(:block))))
+ s(:args, :*)))
add_tests("dmethod",
"Ruby" => [Examples, :dmethod_added],
- "RawParseTree" => [:defn, :dmethod_added,
- [:dmethod,
- :a_method,
- [:scope,
- [:block,
- [:args, :x],
- [:call, [:lvar, :x], :+,
- [:array, [:lit, 1]]]]]]],
"ParseTree" => s(:defn, :dmethod_added,
s(:args, :x),
- s(:scope,
- s(:block,
- s(:call, s(:lvar, :x), :+,
- s(:arglist, s(:lit, 1)))))),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))),
"Ruby2Ruby" => "def dmethod_added(x)\n (x + 1)\nend")
add_tests("dot2",
"Ruby" => "(a..b)",
- "RawParseTree" => [:dot2, [:vcall, :a], [:vcall, :b]],
"ParseTree" => s(:dot2,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))))
+ s(:call, nil, :a),
+ s(:call, nil, :b)))
add_tests("dot3",
"Ruby" => "(a...b)",
- "RawParseTree" => [:dot3, [:vcall, :a], [:vcall, :b]],
"ParseTree" => s(:dot3,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))))
+ s(:call, nil, :a),
+ s(:call, nil, :b)))
add_tests("dregx",
"Ruby" => "/x#\{(1 + 1)}y/",
- "RawParseTree" => [:dregx, "x",
- [:evstr,
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
- [:str, "y"]],
"ParseTree" => s(:dregx, "x",
s(:evstr,
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1)))),
+ s(:call, s(:lit, 1), :+, s(:lit, 1))),
s(:str, "y")))
add_tests("dregx_interp",
"Ruby" => "/#\{@rakefile}/",
- "RawParseTree" => [:dregx, '', [:evstr, [:ivar, :@rakefile]]],
"ParseTree" => s(:dregx, '', s(:evstr, s(:ivar, :@rakefile))))
add_tests("dregx_interp_empty",
"Ruby" => "/a#\{}b/",
- "RawParseTree" => [:dregx, 'a', [:evstr], [:str, "b"]],
"ParseTree" => s(:dregx, 'a', s(:evstr), s(:str, "b")))
add_tests("dregx_n",
"Ruby" => '/#{1}/n',
- "RawParseTree" => [:dregx, '', [:evstr, [:lit, 1]], /x/n.options],
"ParseTree" => s(:dregx, '',
- s(:evstr, s(:lit, 1)), /x/n.options),
- "Ruby2Ruby" => "/#\{1}/") # HACK - need to support regexp flag
+ s(:evstr, s(:lit, 1)), /x/n.options))
add_tests("dregx_once",
"Ruby" => "/x#\{(1 + 1)}y/o",
- "RawParseTree" => [:dregx_once, "x",
- [:evstr,
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
- [:str, "y"]],
"ParseTree" => s(:dregx_once, "x",
s(:evstr,
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1)))),
+ s(:call, s(:lit, 1), :+, s(:lit, 1))),
s(:str, "y")))
add_tests("dregx_once_n_interp",
"Ruby" => "/#\{IAC}#\{SB}/no",
- "RawParseTree" => [:dregx_once, '',
- [:evstr, [:const, :IAC]],
- [:evstr, [:const, :SB]], /x/n.options],
"ParseTree" => s(:dregx_once, '',
s(:evstr, s(:const, :IAC)),
- s(:evstr, s(:const, :SB)), /x/n.options),
- "Ruby2Ruby" => "/#\{IAC}#\{SB}/o") # HACK
+ s(:evstr, s(:const, :SB)), /x/n.options))
add_tests("dstr",
"Ruby" => "argl = 1\n\"x#\{argl}y\"\n",
- "RawParseTree" => [:block,
- [:lasgn, :argl, [:lit, 1]],
- [:dstr, "x", [:evstr, [:lvar, :argl]],
- [:str, "y"]]],
"ParseTree" => s(:block,
s(:lasgn, :argl, s(:lit, 1)),
s(:dstr, "x", s(:evstr, s(:lvar, :argl)),
@@ -1960,37 +1553,17 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dstr_2",
"Ruby" => "argl = 1\n\"x#\{(\"%.2f\" % 3.14159)}y\"\n",
- "RawParseTree" => [:block,
- [:lasgn, :argl, [:lit, 1]],
- [:dstr,
- "x",
- [:evstr,
- [:call, [:str, "%.2f"], :%,
- [:array, [:lit, 3.14159]]]],
- [:str, "y"]]],
"ParseTree" => s(:block,
s(:lasgn, :argl, s(:lit, 1)),
s(:dstr,
"x",
s(:evstr,
s(:call, s(:str, "%.2f"), :%,
- s(:arglist, s(:lit, 3.14159)))),
+ s(:lit, 3.14159))),
s(:str, "y"))))
add_tests("dstr_3",
"Ruby" => "max = 2\nargl = 1\n\"x#\{(\"%.#\{max}f\" % 3.14159)}y\"\n",
- "RawParseTree" => [:block,
- [:lasgn, :max, [:lit, 2]],
- [:lasgn, :argl, [:lit, 1]],
- [:dstr, "x",
- [:evstr,
- [:call,
- [:dstr, "%.",
- [:evstr, [:lvar, :max]],
- [:str, "f"]],
- :%,
- [:array, [:lit, 3.14159]]]],
- [:str, "y"]]],
"ParseTree" => s(:block,
s(:lasgn, :max, s(:lit, 2)),
s(:lasgn, :argl, s(:lit, 1)),
@@ -2001,19 +1574,11 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
s(:evstr, s(:lvar, :max)),
s(:str, "f")),
:%,
- s(:arglist, s(:lit, 3.14159)))),
+ s(:lit, 3.14159))),
s(:str, "y"))))
add_tests("dstr_concat",
"Ruby" => '"#{22}aa" "cd#{44}" "55" "#{66}"',
- "RawParseTree" => [:dstr,
- "",
- [:evstr, [:lit, 22]],
- [:str, "aa"],
- [:str, "cd"],
- [:evstr, [:lit, 44]],
- [:str, "55"],
- [:evstr, [:lit, 66]]],
"ParseTree" => s(:dstr,
"",
s(:evstr, s(:lit, 22)),
@@ -2026,13 +1591,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dstr_gross",
"Ruby" => '"a #$global b #@ivar c #@@cvar d"',
- "RawParseTree" => [:dstr, "a ",
- [:evstr, [:gvar, :$global]],
- [:str, " b "],
- [:evstr, [:ivar, :@ivar]],
- [:str, " c "],
- [:evstr, [:cvar, :@@cvar]],
- [:str, " d"]],
"ParseTree" => s(:dstr, "a ",
s(:evstr, s(:gvar, :$global)),
s(:str, " b "),
@@ -2044,35 +1602,21 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dstr_heredoc_expand",
"Ruby" => "<<EOM\n blah\n#\{1 + 1}blah\nEOM\n",
- "RawParseTree" => [:dstr, " blah\n",
- [:evstr, [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]]],
- [:str, "blah\n"]],
"ParseTree" => s(:dstr, " blah\n",
- s(:evstr, s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1)))),
+ s(:evstr, s(:call, s(:lit, 1), :+, s(:lit, 1))),
s(:str, "blah\n")),
"Ruby2Ruby" => "\" blah\\n#\{(1 + 1)}blah\\n\"")
add_tests("dstr_heredoc_windoze_sucks",
"Ruby" => "<<-EOF\r\ndef test_#\{action}_valid_feed\r\n EOF\r\n",
- "RawParseTree" => [:dstr,
- 'def test_',
- [:evstr, [:vcall, :action]],
- [:str, "_valid_feed\n"]],
"ParseTree" => s(:dstr,
'def test_',
- s(:evstr, s(:call, nil, :action, s(:arglist))),
+ s(:evstr, s(:call, nil, :action)),
s(:str, "_valid_feed\n")),
"Ruby2Ruby" => "\"def test_#\{action}_valid_feed\\n\"")
add_tests("dstr_heredoc_yet_again",
"Ruby" => "<<-EOF\ns1 '#\{RUBY_PLATFORM}' s2\n#\{__FILE__}\n EOF\n",
- "RawParseTree" => [:dstr, "s1 '",
- [:evstr, [:const, :RUBY_PLATFORM]],
- [:str, "' s2\n"],
- [:str, "(string)"],
- [:str, "\n"]],
"ParseTree" => s(:dstr, "s1 '",
s(:evstr, s(:const, :RUBY_PLATFORM)),
s(:str, "' s2\n"),
@@ -2082,52 +1626,30 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dstr_nest",
"Ruby" => "%Q[before [#\{nest}] after]",
- "RawParseTree" => [:dstr, "before [",
- [:evstr, [:vcall, :nest]], [:str, "] after"]],
"ParseTree" => s(:dstr, "before [",
- s(:evstr, s(:call, nil, :nest, s(:arglist))),
+ s(:evstr, s(:call, nil, :nest)),
s(:str, "] after")),
"Ruby2Ruby" => "\"before [#\{nest}] after\"")
add_tests("dstr_str_lit_start",
"Ruby" => '"#{"blah"}#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})"',
- "RawParseTree" => [:dstr,
- "blah(string):",
- [:evstr, [:lit, 1]],
- [:str, ": warning: "],
- [:evstr, [:call, [:gvar, :$!], :message]],
- [:str, " ("],
- [:evstr, [:call, [:gvar, :$!], :class]],
- [:str, ")"]],
"ParseTree" => s(:dstr,
"blah(string):",
s(:evstr, s(:lit, 1)),
s(:str, ": warning: "),
- s(:evstr, s(:call, s(:gvar, :$!), :message,
- s(:arglist))),
+ s(:evstr, s(:call, s(:gvar, :$!), :message)),
s(:str, " ("),
- s(:evstr, s(:call, s(:gvar, :$!), :class,
- s(:arglist))),
+ s(:evstr, s(:call, s(:gvar, :$!), :class)),
s(:str, ")")),
"Ruby2Ruby" => '"blah(string):#{1}: warning: #{$!.message} (#{$!.class})"')
add_tests("dstr_the_revenge",
"Ruby" => '"before #{from} middle #{to} (#{__FILE__}:#{__LINE__})"',
- "RawParseTree" => [:dstr,
- "before ",
- [:evstr, [:vcall, :from]],
- [:str, " middle "],
- [:evstr, [:vcall, :to]],
- [:str, " ("],
- [:str, "(string)"],
- [:str, ":"],
- [:evstr, [:lit, 1]],
- [:str, ")"]],
"ParseTree" => s(:dstr,
"before ",
- s(:evstr, s(:call, nil, :from, s(:arglist))),
+ s(:evstr, s(:call, nil, :from)),
s(:str, " middle "),
- s(:evstr, s(:call, nil, :to, s(:arglist))),
+ s(:evstr, s(:call, nil, :to)),
s(:str, " ("),
s(:str, "(string)"),
s(:str, ":"),
@@ -2137,41 +1659,21 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("dsym",
"Ruby" => ":\"x#\{(1 + 1)}y\"",
- "RawParseTree" => [:dsym, "x",
- [:evstr, [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]]], [:str, "y"]],
"ParseTree" => s(:dsym, "x",
- s(:evstr, s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1)))), s(:str, "y")))
+ s(:evstr, s(:call, s(:lit, 1), :+, s(:lit, 1))),
+ s(:str, "y")))
add_tests("dxstr",
"Ruby" => "t = 5\n`touch #\{t}`\n",
- "RawParseTree" => [:block,
- [:lasgn, :t, [:lit, 5]],
- [:dxstr, 'touch ', [:evstr, [:lvar, :t]]]],
"ParseTree" => s(:block,
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" => [:ensure,
- [:rescue,
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
- [:resbody,
- [:array, [:const, :SyntaxError]],
- [:block,
- [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]],
- [:resbody,
- [:array, [:const, :Exception]],
- [:block,
- [: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(:call, s(:lit, 1), :+, s(:lit, 1)),
s(:resbody,
s(:array,
s(:const, :SyntaxError),
@@ -2187,258 +1689,151 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("false",
"Ruby" => "false",
- "RawParseTree" => [:false],
"ParseTree" => s(:false))
add_tests("fbody",
"Ruby" => [Examples, :an_alias],
- "RawParseTree" => [:defn, :an_alias,
- [:fbody,
- [:scope,
- [:block,
- [:args, :x],
- [:call, [:lvar, :x], :+,
- [:array, [:lit, 1]]]]]]],
- "ParseTree" => s(:defn, :an_alias,
- s(:args, :x),
- s(:scope,
- s(:block,
- s(:call, s(:lvar, :x), :+,
- s(:arglist, s(:lit, 1)))))),
+ "ParseTree" => s(:defn, :an_alias, s(:args, :x),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))),
"Ruby2Ruby" => "def an_alias(x)\n (x + 1)\nend")
add_tests("fcall_arglist",
"Ruby" => "m(42)",
- "RawParseTree" => [:fcall, :m, [:array, [:lit, 42]]],
- "ParseTree" => s(:call, nil, :m, s(:arglist, s(:lit, 42))))
+ "ParseTree" => s(:call, nil, :m, s(:lit, 42)))
add_tests("fcall_arglist_hash",
"Ruby" => "m(:a => 1, :b => 2)",
- "RawParseTree" => [:fcall, :m,
- [:array,
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]]],
"ParseTree" => s(:call, nil, :m,
- s(:arglist,
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)))))
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))))
add_tests("fcall_arglist_norm_hash",
"Ruby" => "m(42, :a => 1, :b => 2)",
- "RawParseTree" => [:fcall, :m,
- [:array,
- [:lit, 42],
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]]],
"ParseTree" => s(:call, nil, :m,
- s(:arglist,
- s(:lit, 42),
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)))))
-
- add_tests("fcall_arglist_norm_hash_splat",
- "Ruby" => "m(42, :a => 1, :b => 2, *c)",
- "RawParseTree" => [:fcall, :m,
- [:argscat,
- [:array,
- [:lit, 42],
- [:hash,
- [:lit, :a], [:lit, 1],
- [:lit, :b], [:lit, 2]]],
- [:vcall, :c]]],
- "ParseTree" => s(:call, nil, :m,
- s(:arglist,
- s(:lit, 42),
- s(:hash,
- s(:lit, :a), s(:lit, 1),
- s(:lit, :b), s(:lit, 2)),
- s(:splat, s(:call, nil, :c, s(:arglist))))))
+ s(:lit, 42),
+ s(:hash,
+ s(:lit, :a), s(:lit, 1),
+ s(:lit, :b), s(:lit, 2))))
add_tests("fcall_block",
"Ruby" => "a(:b) { :c }",
- "RawParseTree" => [:iter,
- [:fcall, :a, [:array, [:lit, :b]]], nil,
- [:lit, :c]],
"ParseTree" => s(:iter,
- s(:call, nil, :a,
- s(:arglist, s(:lit, :b))), nil,
+ s(:call, nil, :a, s(:lit, :b)),
+ s(:args),
s(:lit, :c)))
add_tests("fcall_index_space",
"Ruby" => "a [42]",
- "RawParseTree" => [:fcall, :a, [:array, [:array, [:lit, 42]]]],
- "ParseTree" => s(:call, nil, :a,
- s(:arglist, s(:array, s(:lit, 42)))),
+ "ParseTree" => s(:call, nil, :a, s(:array, s(:lit, 42))),
"Ruby2Ruby" => "a([42])")
+ add_tests("fcall_inside_parens",
+ "Ruby" => "( a (b), c)",
+ "ParseTree" => s(:call, nil, :a,
+ s(:call, nil, :b), s(:call, nil, :c)),
+ "Ruby2Ruby" => "a(b, c)")
+
add_tests("fcall_keyword",
"Ruby" => "42 if block_given?",
- "RawParseTree" => [:if, [:fcall, :block_given?], [:lit, 42], nil],
"ParseTree" => s(:if,
- s(:call, nil, :block_given?, s(:arglist)),
+ s(:call, nil, :block_given?),
s(:lit, 42), nil))
add_tests("flip2",
"Ruby" => "x = if ((i % 4) == 0)..((i % 3) == 0) then\n i\nelse\n nil\nend",
- "RawParseTree" => [:lasgn,
- :x,
- [:if,
- [:flip2,
- [:call,
- [:call, [:vcall, :i], :%,
- [:array, [:lit, 4]]],
- :==,
- [:array, [:lit, 0]]],
- [:call,
- [:call, [:vcall, :i], :%,
- [:array, [:lit, 3]]],
- :==,
- [:array, [:lit, 0]]]],
- [:vcall, :i],
- [:nil]]],
"ParseTree" => s(:lasgn,
:x,
s(:if,
s(:flip2,
s(:call,
- s(:call, s(:call, nil, :i, s(:arglist)),
+ s(:call, s(:call, nil, :i),
:%,
- s(:arglist, s(:lit, 4))),
+ s(:lit, 4)),
:==,
- s(:arglist, s(:lit, 0))),
+ s(:lit, 0)),
s(:call,
- s(:call, s(:call, nil, :i, s(:arglist)),
+ s(:call, s(:call, nil, :i),
:%,
- s(:arglist, s(:lit, 3))),
+ s(:lit, 3)),
:==,
- s(:arglist, s(:lit, 0)))),
- s(:call, nil, :i, s(:arglist)),
+ s(:lit, 0))),
+ s(:call, nil, :i),
s(:nil))))
add_tests("flip2_method",
"Ruby" => "if 1..2.a?(b) then\n nil\nend",
- "RawParseTree" => [:if,
- [:flip2,
- [:call, [:lit, 1], :==,
- [:array, [:gvar, :$.]]],
- [:call, [:lit, 2], :a?,
- [:array, [:vcall, :b]]]],
- [:nil],
- nil],
"ParseTree" => s(:if,
s(:flip2,
s(:lit, 1),
- s(:call, s(:lit, 2), :a?,
- s(:arglist,
- s(:call, nil, :b, s(:arglist))))),
+ s(:call, s(:lit, 2), :a?, s(:call, nil, :b))),
s(:nil),
nil))
add_tests("flip3",
"Ruby" => "x = if ((i % 4) == 0)...((i % 3) == 0) then\n i\nelse\n nil\nend",
- "RawParseTree" => [:lasgn,
- :x,
- [:if,
- [:flip3,
- [:call,
- [:call, [:vcall, :i], :%,
- [:array, [:lit, 4]]],
- :==,
- [:array, [:lit, 0]]],
- [:call,
- [:call, [:vcall, :i], :%,
- [:array, [:lit, 3]]],
- :==,
- [:array, [:lit, 0]]]],
- [:vcall, :i],
- [:nil]]],
"ParseTree" => s(:lasgn,
:x,
s(:if,
s(:flip3,
s(:call,
- s(:call, s(:call, nil, :i, s(:arglist)),
+ s(:call, s(:call, nil, :i),
:%,
- s(:arglist, s(:lit, 4))),
+ s(:lit, 4)),
:==,
- s(:arglist, s(:lit, 0))),
+ s(:lit, 0)),
s(:call,
- s(:call, s(:call, nil, :i, s(:arglist)),
+ s(:call, s(:call, nil, :i),
:%,
- s(:arglist, s(:lit, 3))),
+ s(:lit, 3)),
:==,
- s(:arglist, s(:lit, 0)))),
- s(:call, nil, :i, s(:arglist)),
+ s(:lit, 0))),
+ s(:call, nil, :i),
s(:nil))))
add_tests("for",
"Ruby" => "for o in ary do\n puts(o)\nend",
- "RawParseTree" => [:for,
- [:vcall, :ary],
- [:lasgn, :o],
- [:fcall, :puts, [:array, [:lvar, :o]]]],
"ParseTree" => s(:for,
- s(:call, nil, :ary, s(:arglist)),
+ s(:call, nil, :ary),
s(:lasgn, :o),
- s(:call, nil, :puts,
- s(:arglist, s(:lvar, :o)))))
+ s(:call, nil, :puts, s(:lvar, :o))))
add_tests("for_no_body",
"Ruby" => "for i in (0..max) do\n # do nothing\nend",
- "RawParseTree" => [:for,
- [:dot2, [:lit, 0], [:vcall, :max]],
- [:lasgn, :i]],
"ParseTree" => s(:for,
s(:dot2,
s(:lit, 0),
- s(:call, nil, :max, s(:arglist))),
+ s(:call, nil, :max)),
s(:lasgn, :i)))
add_tests("gasgn",
"Ruby" => "$x = 42",
- "RawParseTree" => [:gasgn, :$x, [:lit, 42]],
"ParseTree" => s(:gasgn, :$x, s(:lit, 42)))
add_tests("global",
"Ruby" => "$stderr",
- "RawParseTree" => [:gvar, :$stderr],
"ParseTree" => s(:gvar, :$stderr))
add_tests("gvar",
"Ruby" => "$x",
- "RawParseTree" => [:gvar, :$x],
"ParseTree" => s(:gvar, :$x))
add_tests("gvar_underscore",
"Ruby" => "$_",
- "RawParseTree" => [:gvar, :$_],
"ParseTree" => s(:gvar, :$_))
add_tests("gvar_underscore_blah",
"Ruby" => "$__blah",
- "RawParseTree" => [:gvar, :$__blah],
"ParseTree" => s(:gvar, :$__blah))
add_tests("hash",
"Ruby" => "{ 1 => 2, 3 => 4 }",
- "RawParseTree" => [:hash,
- [:lit, 1], [:lit, 2],
- [:lit, 3], [:lit, 4]],
"ParseTree" => s(:hash,
s(:lit, 1), s(:lit, 2),
s(:lit, 3), s(:lit, 4)))
add_tests("hash_rescue",
"Ruby" => "{ 1 => (2 rescue 3) }",
- "RawParseTree" => [:hash,
- [:lit, 1],
- [:rescue,
- [:lit, 2],
- [:resbody, nil, [:lit, 3]]]],
"ParseTree" => s(:hash,
s(:lit, 1),
s(:rescue,
@@ -2447,178 +1842,85 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("iasgn",
"Ruby" => "@a = 4",
- "RawParseTree" => [:iasgn, :@a, [:lit, 4]],
"ParseTree" => s(:iasgn, :@a, s(:lit, 4)))
add_tests("if_block_condition",
"Ruby" => "if (x = 5\n(x + 1)) then\n nil\nend",
- "RawParseTree" => [:if,
- [:block,
- [:lasgn, :x, [:lit, 5]],
- [:call,
- [:lvar, :x],
- :+,
- [:array, [:lit, 1]]]],
- [:nil],
- nil],
"ParseTree" => s(:if,
s(:block,
s(:lasgn, :x, s(:lit, 5)),
- s(:call,
- s(:lvar, :x),
- :+,
- s(:arglist, s(:lit, 1)))),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))),
s(:nil),
nil))
add_tests("if_lasgn_short",
"Ruby" => "if x = obj.x then\n x.do_it\nend",
- "RawParseTree" => [:if,
- [:lasgn, :x,
- [:call, [:vcall, :obj], :x]],
- [:call,
- [:lvar, :x], :do_it],
- nil],
"ParseTree" => s(:if,
s(:lasgn, :x,
s(:call,
- s(:call, nil, :obj, s(:arglist)),
- :x, s(:arglist))),
- s(:call, s(:lvar, :x), :do_it, s(:arglist)),
+ s(:call, nil, :obj),
+ :x)),
+ s(:call, s(:lvar, :x), :do_it),
nil))
add_tests("if_nested",
"Ruby" => "return if false unless true",
- "RawParseTree" => [:if, [:true], nil,
- [:if, [:false], [:return], nil]],
"ParseTree" => s(:if, s(:true), nil,
s(:if, s(:false), s(:return), nil)))
add_tests("if_post",
"Ruby" => "a if b",
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
- s(:call, nil, :a, s(:arglist)), nil))
-
- add_tests("if_post_not",
- "Ruby" => "a if not b",
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
- s(:call, nil, :a, s(:arglist))),
- "Ruby2Ruby" => "a unless b")
+ "ParseTree" => s(:if, s(:call, nil, :b),
+ s(:call, nil, :a), nil))
add_tests("if_pre",
"Ruby" => "if b then a end",
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
- s(:call, nil, :a, s(:arglist)), nil),
+ "ParseTree" => s(:if, s(:call, nil, :b),
+ s(:call, nil, :a), nil),
"Ruby2Ruby" => "a if b")
- add_tests("if_pre_not",
- "Ruby" => "if not b then a end",
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
- s(:call, nil, :a, s(:arglist))),
- "Ruby2Ruby" => "a unless b")
-
add_tests("iter_call_arglist_space",
"Ruby" => "a (1) {|c|d}",
- "RawParseTree" => [:iter,
- [:fcall, :a, [:array, [:lit, 1]]],
- [:dasgn_curr, :c],
- [:vcall, :d]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist, s(:lit, 1))),
- s(:lasgn, :c),
- s(:call, nil, :d, s(:arglist))),
+ s(:call, nil, :a, s(:lit, 1)),
+ s(:args, :c),
+ s(:call, nil, :d)),
"Ruby2Ruby" => "a(1) { |c| d }")
add_tests("iter_dasgn_curr_dasgn_madness",
"Ruby" => "as.each { |a|\n b += a.b(false) }",
- "RawParseTree" => [:iter,
- [:call, [:vcall, :as], :each],
- [:dasgn_curr, :a],
- [:dasgn_curr,
- :b,
- [:call,
- [:dvar, :b],
- :+,
- [:array,
- [:call, [:dvar, :a], :b,
- [:array, [:false]]]]]]],
"ParseTree" => s(:iter,
- s(:call,
- s(:call, nil, :as, s(:arglist)),
- :each, s(:arglist)),
- s(:lasgn, :a),
+ s(:call, s(:call, nil, :as), :each),
+ s(:args, :a),
s(:lasgn, :b,
s(:call,
s(:lvar, :b),
:+,
- s(:arglist,
- s(:call, s(:lvar, :a), :b,
- s(:arglist, s(:false))))))),
+ s(:call, s(:lvar, :a), :b, s(:false))))),
"Ruby2Ruby" => "as.each { |a| b = (b + a.b(false)) }")
add_tests("iter_downto",
"Ruby" => "3.downto(1) { |n| puts(n.to_s) }",
- "RawParseTree" => [:iter,
- [:call, [:lit, 3], :downto, [:array, [:lit, 1]]],
- [:dasgn_curr, :n],
- [:fcall, :puts,
- [:array, [:call, [:dvar, :n], :to_s]]]],
"ParseTree" => s(:iter,
- s(:call, s(:lit, 3), :downto,
- s(:arglist, s(:lit, 1))),
- s(:lasgn, :n),
+ s(:call, s(:lit, 3), :downto, s(:lit, 1)),
+ s(:args, :n),
s(:call, nil, :puts,
- s(:arglist,
- s(:call, s(:lvar, :n),
- :to_s, s(:arglist))))))
+ s(:call, s(:lvar, :n), :to_s))))
add_tests("iter_each_lvar",
"Ruby" => "array = [1, 2, 3]\narray.each { |x| puts(x.to_s) }\n",
- "RawParseTree" => [: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]]]]],
"ParseTree" => s(:block,
s(:lasgn, :array,
s(:array,
s(:lit, 1), s(:lit, 2), s(:lit, 3))),
s(:iter,
- s(:call, s(:lvar, :array), :each,
- s(:arglist)),
- s(:lasgn, :x),
+ s(:call, s(:lvar, :array), :each),
+ s(:args, :x),
s(:call, nil, :puts,
- s(:arglist, s(:call, s(:lvar, :x),
- :to_s, s(:arglist)))))))
+ s(:call, s(:lvar, :x), :to_s)))))
add_tests("iter_each_nested",
"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",
- "RawParseTree" => [:block,
- [:lasgn, :array1,
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
- [:lasgn, :array2,
- [:array,
- [:lit, 4], [:lit, 5], [:lit, 6], [:lit, 7]]],
- [:iter,
- [:call,
- [:lvar, :array1], :each],
- [:dasgn_curr, :x],
- [:iter,
- [:call,
- [:lvar, :array2], :each],
- [:dasgn_curr, :y],
- [:block,
- [:fcall, :puts,
- [:array, [:call, [:dvar, :x], :to_s]]],
- [:fcall, :puts,
- [:array, [:call, [:dvar, :y], :to_s]]]]]]],
"ParseTree" => s(:block,
s(:lasgn, :array1,
s(:array,
@@ -2628,174 +1930,183 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
s(:lit, 4), s(:lit, 5),
s(:lit, 6), s(:lit, 7))),
s(:iter,
- s(:call,
- s(:lvar, :array1), :each, s(:arglist)),
- s(:lasgn, :x),
+ s(:call, s(:lvar, :array1), :each),
+ s(:args, :x),
s(:iter,
- s(:call,
- s(:lvar, :array2), :each, s(:arglist)),
- s(:lasgn, :y),
+ s(:call, s(:lvar, :array2), :each),
+ s(:args, :y),
s(:block,
s(:call, nil, :puts,
- s(:arglist,
- s(:call, s(:lvar, :x),
- :to_s, s(:arglist)))),
+ s(:call, s(:lvar, :x), :to_s)),
s(:call, nil, :puts,
- s(:arglist,
- s(:call, s(:lvar, :y),
- :to_s, s(:arglist)))))))))
+ s(:call, s(:lvar, :y), :to_s)))))))
add_tests("iter_loop_empty",
"Ruby" => "loop { }",
- "RawParseTree" => [:iter, [:fcall, :loop], nil],
- "ParseTree" => s(:iter, s(:call, nil, :loop, s(:arglist)), nil))
+ "ParseTree" => s(:iter, s(:call, nil, :loop), s(:args)))
add_tests("iter_masgn_2",
"Ruby" => "a { |b, c| p(c) }",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:masgn,
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
- nil, nil],
- [:fcall, :p, [:array, [:dvar, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:masgn,
- s(:array, s(:lasgn, :b), s(:lasgn, :c))),
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
+ s(:call, nil, :a),
+ s(:args, :b, :c),
+ s(:call, nil, :p, s(:lvar, :c))))
add_tests("iter_masgn_args_splat",
"Ruby" => "a { |b, c, *d| p(c) }",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:masgn,
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
- [:dasgn_curr, :d], nil],
- [:fcall, :p, [:array, [:dvar, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:masgn,
- s(:array,
- s(:lasgn, :b),
- s(:lasgn, :c),
- s(:splat, s(:lasgn, :d)))),
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
+ s(:call, nil, :a),
+ s(:args, :b, :c, :"*d"),
+ s(:call, nil, :p, s(:lvar, :c))))
add_tests("iter_masgn_args_splat_no_name",
"Ruby" => "a { |b, c, *| p(c) }",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:masgn,
- [:array, [:dasgn_curr, :b], [:dasgn_curr, :c]],
- [:splat], nil],
- [:fcall, :p, [:array, [:dvar, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:masgn,
- s(:array,
- s(:lasgn, :b),
- s(:lasgn, :c),
- s(:splat))),
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
+ s(:call, nil, :a),
+ s(:args, :b, :c, :*),
+ s(:call, nil, :p, s(:lvar, :c))))
add_tests("iter_masgn_splat",
"Ruby" => "a { |*c| p(c) }",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:masgn, nil, [:dasgn_curr, :c], nil],
- [:fcall, :p, [:array, [:dvar, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:masgn, s(:array, s(:splat, s(:lasgn, :c)))),
- s(:call, nil, :p, s(:arglist, s(:lvar, :c)))))
+ s(:call, nil, :a),
+ s(:args, :"*c"),
+ s(:call, nil, :p, s(:lvar, :c))))
add_tests("iter_masgn_splat_no_name",
"Ruby" => "a { |*| p(c) }",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:masgn, nil, [:splat], nil],
- [:fcall, :p, [:array, [:vcall, :c]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:masgn, s(:array, s(:splat))),
- s(:call, nil, :p,
- s(:arglist, s(:call, nil, :c, s(:arglist))))))
+ s(:call, nil, :a),
+ s(:args, :*),
+ s(:call, nil, :p, s(:call, nil, :c))))
add_tests("iter_shadowed_var",
"Ruby" => "a do |x|\n b do |x|\n puts x\n end\nend",
- "RawParseTree" => [:iter,
- [:fcall, :a],
- [:dasgn_curr, :x],
- [:iter,
- [:fcall, :b],
- [:dasgn, :x],
- [:fcall, :puts, [:array, [:dvar, :x]]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :a, s(:arglist)),
- s(:lasgn, :x),
+ s(:call, nil, :a),
+ s(:args, :x),
s(:iter,
- s(:call, nil, :b, s(:arglist)),
- s(:lasgn, :x),
- s(:call, nil, :puts,
- s(:arglist, s(:lvar, :x))))),
+ s(:call, nil, :b),
+ s(:args, :x),
+ s(:call, nil, :puts, s(:lvar, :x)))),
"Ruby2Ruby" => "a { |x| b { |x| puts(x) } }")
add_tests("iter_upto",
"Ruby" => "1.upto(3) { |n| puts(n.to_s) }",
- "RawParseTree" => [:iter,
- [:call, [:lit, 1], :upto, [:array, [:lit, 3]]],
- [:dasgn_curr, :n],
- [:fcall, :puts,
- [:array, [:call, [:dvar, :n], :to_s]]]],
"ParseTree" => s(:iter,
- s(:call, s(:lit, 1), :upto,
- s(:arglist, s(:lit, 3))),
- s(:lasgn, :n),
+ s(:call, s(:lit, 1), :upto, s(:lit, 3)),
+ s(:args, :n),
s(:call, nil, :puts,
- s(:arglist,
- s(:call, s(:lvar, :n), :to_s,
- s(:arglist))))))
+ s(:call, s(:lvar, :n), :to_s))))
add_tests("iter_while",
"Ruby" => "argl = 10\nwhile (argl >= 1) do\n puts(\"hello\")\n argl = (argl - 1)\nend\n",
- "RawParseTree" => [:block,
- [:lasgn, :argl, [:lit, 10]],
- [:while,
- [:call, [:lvar, :argl], :">=",
- [:array, [:lit, 1]]],
- [:block,
- [:fcall, :puts, [:array, [:str, "hello"]]],
- [:lasgn,
- :argl,
- [:call, [:lvar, :argl],
- :"-", [:array, [:lit, 1]]]]], true]],
"ParseTree" => s(:block,
s(:lasgn, :argl, s(:lit, 10)),
s(:while,
- s(:call, s(:lvar, :argl), :">=",
- s(:arglist, s(:lit, 1))),
+ s(:call, s(:lvar, :argl), :">=", s(:lit, 1)),
s(:block,
- s(:call, nil, :puts,
- s(:arglist, s(:str, "hello"))),
+ s(:call, nil, :puts, s(:str, "hello")),
s(:lasgn,
:argl,
s(:call, s(:lvar, :argl), :"-",
- s(:arglist, s(:lit, 1))))), true)))
+ s(:lit, 1)))),
+ true)))
add_tests("ivar",
"Ruby" => [Examples, :reader],
- "RawParseTree" => [:defn, :reader, [:ivar, :@reader]],
- "ParseTree" => s(:defn, :reader, # FIX should be unified?
- s(:args),
+ "ParseTree" => s(:defn, :reader, s(:args),
s(:ivar, :@reader)),
"Ruby2Ruby" => "attr_reader :reader")
+ add_tests("lambda_args_anon_star",
+ "Ruby" => "lambda { |*| nil }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :*),
+ s(:nil)))
+
+ add_tests("lambda_args_anon_star_block",
+ "Ruby" => "lambda { |*, &block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :*, :"&block"),
+ s(:lvar, :block)))
+
+ add_tests("lambda_args_block",
+ "Ruby" => "lambda { |&block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :"&block"),
+ s(:lvar, :block)))
+
+ add_tests("lambda_args_norm_anon_star",
+ "Ruby" => "lambda { |a, *| a }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :*),
+ s(:lvar, :a)))
+
+ add_tests("lambda_args_norm_anon_star_block",
+ "Ruby" => "lambda { |a, *, &block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :*, :"&block"),
+ s(:lvar, :block)))
+
+ add_tests("lambda_args_norm_block",
+ "Ruby" => "lambda { |a, &block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :"&block"),
+ s(:lvar, :block)))
+
+ add_tests("lambda_args_norm_comma",
+ "Ruby" => "lambda { |a,| a }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a),
+ s(:lvar, :a)),
+ "Ruby2Ruby" => "lambda { |a| a }")
+
+ add_tests("lambda_args_norm_comma2",
+ "Ruby" => "lambda { |a,b,| a }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :b),
+ s(:lvar, :a)),
+ "Ruby2Ruby" => "lambda { |a, b| a }")
+
+ add_tests("lambda_args_norm_star",
+ "Ruby" => "lambda { |a, *star| star }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :"*star"),
+ s(:lvar, :star)))
+
+ add_tests("lambda_args_norm_star_block",
+ "Ruby" => "lambda { |a, *star, &block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :a, :"*star", :"&block"),
+ s(:lvar, :block)))
+
+ add_tests("lambda_args_star",
+ "Ruby" => "lambda { |*star| star }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :"*star"),
+ s(:lvar, :star)))
+
+ add_tests("lambda_args_star_block",
+ "Ruby" => "lambda { |*star, &block| block }",
+ "ParseTree" => s(:iter,
+ s(:call, nil, :lambda),
+ s(:args, :"*star", :"&block"),
+ s(:lvar, :block)))
+
add_tests("lasgn_array",
"Ruby" => "var = [\"foo\", \"bar\"]",
- "RawParseTree" => [:lasgn, :var,
- [:array,
- [:str, "foo"],
- [:str, "bar"]]],
"ParseTree" => s(:lasgn, :var,
s(:array,
s(:str, "foo"),
@@ -2803,143 +2114,92 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("lasgn_call",
"Ruby" => "c = (2 + 3)",
- "RawParseTree" => [:lasgn, :c, [:call, [:lit, 2], :+,
- [:array, [:lit, 3]]]],
- "ParseTree" => s(:lasgn, :c, s(:call, s(:lit, 2), :+,
- s(:arglist, s(:lit, 3)))))
+ "ParseTree" => s(:lasgn, :c,
+ s(:call, s(:lit, 2), :+, s(:lit, 3))))
add_tests("lit_bool_false",
"Ruby" => "false",
- "RawParseTree" => [:false],
"ParseTree" => s(:false))
add_tests("lit_bool_true",
"Ruby" => "true",
- "RawParseTree" => [:true],
"ParseTree" => s(:true))
add_tests("lit_float",
"Ruby" => "1.1",
- "RawParseTree" => [:lit, 1.1],
"ParseTree" => s(:lit, 1.1))
add_tests("lit_long",
"Ruby" => "1",
- "RawParseTree" => [:lit, 1],
"ParseTree" => s(:lit, 1))
add_tests("lit_long_negative",
"Ruby" => "-1",
- "RawParseTree" => [:lit, -1],
"ParseTree" => s(:lit, -1))
add_tests("lit_range2",
"Ruby" => "(1..10)",
- "RawParseTree" => [:lit, 1..10],
"ParseTree" => s(:lit, 1..10))
add_tests("lit_range3",
"Ruby" => "(1...10)",
- "RawParseTree" => [:lit, 1...10],
"ParseTree" => s(:lit, 1...10))
-# TODO: discuss and decide which lit we like
-# it "converts a regexp to an sexp" do
-# "/blah/".to_sexp.should == s(:regex, "blah", 0)
-# "/blah/i".to_sexp.should == s(:regex, "blah", 1)
-# "/blah/u".to_sexp.should == s(:regex, "blah", 64)
-# end
-
add_tests("lit_regexp",
"Ruby" => "/x/",
- "RawParseTree" => [:lit, /x/],
"ParseTree" => s(:lit, /x/))
add_tests("lit_regexp_i_wwtt",
"Ruby" => 'str.split(//i)',
- "RawParseTree" => [:call, [:vcall, :str], :split,
- [:array, [:lit, //i]]],
- "ParseTree" => s(:call, s(:call, nil, :str, s(:arglist)), :split,
- s(:arglist, s(:lit, //i))))
+ "ParseTree" => s(:call,
+ s(:call, nil, :str),
+ :split,
+ s(:lit, //i)))
add_tests("lit_regexp_n",
"Ruby" => "/x/n", # HACK differs on 1.9 - this is easiest
- "RawParseTree" => [:lit, /x/n],
"ParseTree" => s(:lit, /x/n),
"Ruby2Ruby" => /x/n.inspect)
add_tests("lit_regexp_once",
"Ruby" => "/x/o",
- "RawParseTree" => [:lit, /x/],
"ParseTree" => s(:lit, /x/),
"Ruby2Ruby" => "/x/")
add_tests("lit_sym",
"Ruby" => ":x",
- "RawParseTree" => [:lit, :x],
"ParseTree" => s(:lit, :x))
add_tests("lit_sym_splat",
"Ruby" => ":\"*args\"",
- "RawParseTree" => [:lit, :"*args"],
"ParseTree" => s(:lit, :"*args"))
add_tests("lvar_def_boundary",
"Ruby" => "b = 42\ndef a\n c do\n begin\n do_stuff\n rescue RuntimeError => b\n puts(b)\n end\n end\nend\n",
- "RawParseTree" => [:block,
- [:lasgn, :b, [:lit, 42]],
- [:defn, :a,
- [:scope,
- [:block,
- [:args],
- [:iter,
- [:fcall, :c],
- nil,
- [: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,
- s(:block,
- s(:iter,
- s(:call, nil, :c, s(:arglist)),
- nil,
- s(:rescue,
- s(:call, nil, :do_stuff, s(:arglist)),
- s(:resbody,
- s(:array,
- s(:const, :RuntimeError),
- s(:lasgn, :b, s(:gvar, :$!))),
- s(:call, nil, :puts,
- s(:arglist,
- s(:lvar, :b)))))))))))
+ s(:defn, :a, s(:args),
+ s(:iter,
+ s(:call, nil, :c),
+ s(:args),
+ s(:rescue,
+ s(:call, nil, :do_stuff),
+ s(:resbody,
+ s(:array,
+ s(:const, :RuntimeError),
+ s(:lasgn, :b, s(:gvar, :$!))),
+ s(:call, nil, :puts,
+ s(:lvar, :b))))))))
add_tests("masgn",
"Ruby" => "a, b = c, d",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
- [:array, [:vcall, :c], [:vcall, :d]]],
"ParseTree" => s(:masgn,
s(:array, s(:lasgn, :a), s(:lasgn, :b)),
- s(:array, s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist)))))
+ s(:array, s(:call, nil, :c),
+ s(:call, nil, :d))))
add_tests("masgn_argscat",
"Ruby" => "a, b, *c = 1, 2, *[3, 4]",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- [:lasgn, :c],
- [:argscat,
- [:array, [:lit, 1], [:lit, 2]],
- [:array, [:lit, 3], [:lit, 4]]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
@@ -2952,59 +2212,32 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("masgn_attrasgn",
"Ruby" => "a, b.c = d, e",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a],
- [:attrasgn, [:vcall, :b], :c=]], nil,
- [:array, [:vcall, :d], [:vcall, :e]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
s(:attrasgn,
- s(:call, nil, :b, s(:arglist)),
- :c=, s(:arglist))),
+ s(:call, nil, :b),
+ :c=)),
s(:array,
- s(:call, nil, :d, s(:arglist)),
- s(:call, nil, :e, s(:arglist)))))
+ s(:call, nil, :d),
+ s(:call, nil, :e))))
add_tests("masgn_attrasgn_array_rhs",
"Ruby" => "a.b, a.c, _ = q",
- "RawParseTree" => [:masgn,
- [:array,
- [:attrasgn, [:vcall, :a], :b=],
- [:attrasgn, [:vcall, :a], :c=],
- [:lasgn, :_]], nil,
- [:to_ary, [:vcall, :q]]],
"ParseTree" => s(:masgn,
s(:array,
s(:attrasgn,
- s(:call, nil, :a, s(:arglist)),
- :b=, s(:arglist)),
+ s(:call, nil, :a),
+ :b=),
s(:attrasgn,
- s(:call, nil, :a, s(:arglist)),
- :c=, s(:arglist)),
+ s(:call, nil, :a),
+ :c=),
s(:lasgn, :_)),
s(:to_ary,
- s(:call, nil, :q, s(:arglist)))))
+ s(:call, nil, :q))))
add_tests("masgn_attrasgn_idx",
"Ruby" => "a, i, j = [], 1, 2\na[i], a[j] = a[j], a[i]\n",
- "RawParseTree" => [:block,
- [:masgn,
- [:array,
- [:lasgn, :a], [:lasgn, :i], [:lasgn, :j]], nil,
- [:array, [:zarray], [:lit, 1], [:lit, 2]]],
- [:masgn,
- [:array,
- [:attrasgn,
- [:lvar, :a], :[]=, [:array, [:lvar, :i]]],
- [:attrasgn,
- [:lvar, :a], :[]=, [:array, [:lvar, :j]]]],
- nil,
- [:array,
- [:call, [:lvar, :a], :[],
- [:array, [:lvar, :j]]],
- [:call, [:lvar, :a], :[],
- [:array, [:lvar, :i]]]]]],
"ParseTree" => s(:block,
s(:masgn,
s(:array,
@@ -3013,55 +2246,33 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
s(:array, s(:array), s(:lit, 1), s(:lit, 2))),
s(:masgn,
s(:array,
- s(:attrasgn, s(:lvar, :a), :[]=,
- s(:arglist, s(:lvar, :i))),
- s(:attrasgn, s(:lvar, :a), :[]=,
- s(:arglist, s(:lvar, :j)))),
+ s(:attrasgn,
+ s(:lvar, :a), :[]=, s(:lvar, :i)),
+ s(:attrasgn,
+ s(:lvar, :a), :[]=, s(:lvar, :j))),
s(:array,
- s(:call, s(:lvar, :a), :[],
- s(:arglist, s(:lvar, :j))),
- s(:call, s(:lvar, :a), :[],
- s(:arglist, s(:lvar, :i)))))))
+ s(:call,
+ s(:lvar, :a), :[], s(:lvar, :j)),
+ s(:call,
+ s(:lvar, :a), :[], s(:lvar, :i))))))
add_tests("masgn_cdecl",
"Ruby" => "A, B, C = 1, 2, 3",
- "RawParseTree" => [:masgn,
- [:array, [:cdecl, :A], [:cdecl, :B],
- [:cdecl, :C]], nil,
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
"ParseTree" => s(:masgn,
s(:array, s(:cdecl, :A), s(:cdecl, :B),
s(:cdecl, :C)),
s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))))
-
add_tests("masgn_iasgn",
"Ruby" => "a, @b = c, d",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:iasgn, :"@b"]], nil,
- [:array, [:vcall, :c], [:vcall, :d]]],
"ParseTree" => s(:masgn,
s(:array, s(:lasgn, :a), s(:iasgn, :"@b")),
s(:array,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist)))))
+ s(:call, nil, :c),
+ s(:call, nil, :d))))
add_tests("masgn_masgn",
"Ruby" => "a, (b, c) = [1, [2, 3]]",
- "RawParseTree" => [:masgn,
- [:array,
- [:lasgn, :a],
- [:masgn,
- [:array,
- [:lasgn, :b],
- [:lasgn, :c]], nil, nil]],
- nil,
- [:to_ary,
- [:array,
- [:lit, 1],
- [:array,
- [:lit, 2],
- [:lit, 3]]]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
@@ -3078,96 +2289,63 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("masgn_splat_lhs",
"Ruby" => "a, b, *c = d, e, f, g",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- [:lasgn, :c],
- [:array,
- [:vcall, :d], [:vcall, :e],
- [:vcall, :f], [:vcall, :g]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
s(:lasgn, :b),
s(:splat, s(:lasgn, :c))),
s(:array,
- s(:call, nil, :d, s(:arglist)),
- s(:call, nil, :e, s(:arglist)),
- s(:call, nil, :f, s(:arglist)),
- s(:call, nil, :g, s(:arglist)))))
+ s(:call, nil, :d),
+ s(:call, nil, :e),
+ s(:call, nil, :f),
+ s(:call, nil, :g))))
+
+ add_tests("masgn_splat_no_name_to_ary",
+ "Ruby" => "a, b, * = c",
+ "ParseTree" => s(:masgn,
+ s(:array,
+ s(:lasgn, :a),
+ s(:lasgn, :b),
+ s(:splat)),
+ s(:to_ary, s(:call, nil, :c))))
+
+ add_tests("masgn_splat_no_name_trailing",
+ "Ruby" => "a, b, = c",
+ "ParseTree" => s(:masgn,
+ s(:array, s(:lasgn, :a), s(:lasgn, :b)),
+ s(:to_ary, s(:call, nil, :c))),
+ "Ruby2Ruby" => "a, b = c") # TODO: check this is right
add_tests("masgn_splat_rhs_1",
"Ruby" => "a, b = *c",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- nil,
- [:splat, [:vcall, :c]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
s(:lasgn, :b)),
- s(:splat, s(:call, nil, :c, s(:arglist)))))
+ s(:splat, s(:call, nil, :c))))
add_tests("masgn_splat_rhs_n",
"Ruby" => "a, b = c, d, *e",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- nil,
- [:argscat,
- [:array, [:vcall, :c], [:vcall, :d]],
- [:vcall, :e]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
s(:lasgn, :b)),
s(:array,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist)),
- s(:splat, s(:call, nil, :e, s(:arglist))))))
-
- add_tests("masgn_splat_no_name_to_ary",
- "Ruby" => "a, b, * = c",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- [:splat],
- [:to_ary, [:vcall, :c]]],
- "ParseTree" => s(:masgn,
- s(:array,
- s(:lasgn, :a),
- s(:lasgn, :b),
- s(:splat)),
- s(:to_ary, s(:call, nil, :c, s(:arglist)))))
-
- add_tests("masgn_splat_no_name_trailing",
- "Ruby" => "a, b, = c",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
- [:to_ary, [:vcall, :c]]],
- "ParseTree" => s(:masgn,
- s(:array, s(:lasgn, :a), s(:lasgn, :b)),
- s(:to_ary, s(:call, nil, :c, s(:arglist)))),
- "Ruby2Ruby" => "a, b = c") # TODO: check this is right
+ s(:call, nil, :c),
+ s(:call, nil, :d),
+ s(:splat, s(:call, nil, :e)))))
add_tests("masgn_splat_to_ary",
"Ruby" => "a, b, *c = d",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- [:lasgn, :c],
- [:to_ary, [:vcall, :d]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
s(:lasgn, :b),
s(:splat, s(:lasgn, :c))),
- s(:to_ary, s(:call, nil, :d, s(:arglist)))))
+ s(:to_ary, s(:call, nil, :d))))
add_tests("masgn_splat_to_ary2",
"Ruby" => "a, b, *c = d.e(\"f\")",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]],
- [:lasgn, :c],
- [:to_ary,
- [:call, [:vcall, :d], :e,
- [:array, [:str, 'f']]]]],
"ParseTree" => s(:masgn,
s(:array,
s(:lasgn, :a),
@@ -3175,93 +2353,63 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
s(:splat, s(:lasgn, :c))),
s(:to_ary,
s(:call,
- s(:call, nil, :d, s(:arglist)),
+ s(:call, nil, :d),
:e,
- s(:arglist, s(:str, 'f'))))))
+ s(:str, 'f')))))
add_tests("match",
"Ruby" => "1 if /x/",
- "RawParseTree" => [:if, [:match, [:lit, /x/]], [:lit, 1], nil],
"ParseTree" => s(:if, s(:match, s(:lit, /x/)), s(:lit, 1), nil))
add_tests("match2",
"Ruby" => "/x/ =~ \"blah\"",
- "RawParseTree" => [:match2, [:lit, /x/], [:str, "blah"]],
"ParseTree" => s(:match2, s(:lit, /x/), s(:str, "blah")))
add_tests("match3",
"Ruby" => "\"blah\" =~ /x/",
- "RawParseTree" => [:match3, [:lit, /x/], [:str, "blah"]],
"ParseTree" => s(:match3, s(:lit, /x/), s(:str, "blah")))
add_tests("module",
"Ruby" => "module X\n def y\n # do nothing\n end\nend",
- "RawParseTree" => [:module, :X,
- [:scope,
- [:defn, :y,
- [:scope, [:block, [:args], [:nil]]]]]],
"ParseTree" => s(:module, :X,
- s(:scope,
- s(:defn, :y,
- s(:args),
- s(:scope, s(:block, s(:nil)))))))
+ s(:defn, :y, s(:args), s(:nil))))
+
+ add_tests("module2",
+ "Ruby" => "module X\n def y\n # do nothing\n end\n \n def z\n # do nothing\n end\nend",
+ "ParseTree" => s(:module, :X,
+ s(:defn, :y, s(:args), s(:nil)),
+ s(:defn, :z, s(:args), s(:nil))))
add_tests("module_scoped",
"Ruby" => "module X::Y\n c\nend",
- "RawParseTree" => [:module, [:colon2, [:const, :X], :Y],
- [:scope, [:vcall, :c]]],
"ParseTree" => s(:module, s(:colon2, s(:const, :X), :Y),
- s(:scope, s(:call, nil, :c, s(:arglist)))))
+ s(:call, nil, :c)))
add_tests("module_scoped3",
"Ruby" => "module ::Y\n c\nend",
- "RawParseTree" => [:module, [:colon3, :Y], [:scope, [:vcall, :c]]],
- "ParseTree" => s(:module,
- s(:colon3, :Y),
- s(:scope, s(:call, nil, :c, s(:arglist)))))
+ "ParseTree" => s(:module, s(:colon3, :Y),
+ s(:call, nil, :c)))
add_tests("next",
"Ruby" => "loop { next if false }",
- "RawParseTree" => [:iter,
- [:fcall, :loop],
- nil,
- [:if, [:false], [:next], nil]],
"ParseTree" => s(:iter,
- s(:call, nil, :loop, s(:arglist)),
- nil,
+ s(:call, nil, :loop),
+ s(:args),
s(:if, s(:false), s(:next), nil)))
add_tests("next_arg",
"Ruby" => "loop { next 42 if false }",
- "RawParseTree" => [:iter,
- [:fcall, :loop],
- nil,
- [:if, [:false], [:next, [:lit, 42]], nil]],
"ParseTree" => s(:iter,
- s(:call, nil, :loop, s(:arglist)),
- nil,
+ s(:call, nil, :loop),
+ s(:args),
s(:if, s(:false), s(:next, s(:lit, 42)), nil)))
- add_tests("not",
- "Ruby" => "(not true)",
- "RawParseTree" => [:not, [:true]],
- "ParseTree" => s(:not, s(:true)))
-
add_tests("nth_ref",
"Ruby" => "$1",
- "RawParseTree" => [:nth_ref, 1],
"ParseTree" => s(:nth_ref, 1))
add_tests("op_asgn1",
"Ruby" => "b = []\nb[1] ||= 10\nb[2] &&= 11\nb[3] += 12\n",
- "RawParseTree" => [:block,
- [:lasgn, :b, [:zarray]],
- [:op_asgn1, [:lvar, :b],
- [:array, [:lit, 1]], :"||", [:lit, 10]],
- [:op_asgn1, [:lvar, :b],
- [:array, [:lit, 2]], :"&&", [:lit, 11]],
- [:op_asgn1, [:lvar, :b],
- [:array, [:lit, 3]], :+, [:lit, 12]]],
"ParseTree" => s(:block,
s(:lasgn, :b, s(:array)),
s(:op_asgn1, s(:lvar, :b),
@@ -3273,14 +2421,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("op_asgn1_ivar",
"Ruby" => "@b = []\n at b[1] ||= 10\n at b[2] &&= 11\n at b[3] += 12\n",
- "RawParseTree" => [:block,
- [:iasgn, :@b, [:zarray]],
- [:op_asgn1, [:ivar, :@b],
- [:array, [:lit, 1]], :"||", [:lit, 10]],
- [:op_asgn1, [:ivar, :@b],
- [:array, [:lit, 2]], :"&&", [:lit, 11]],
- [:op_asgn1, [:ivar, :@b],
- [:array, [:lit, 3]], :+, [:lit, 12]]],
"ParseTree" => s(:block,
s(:iasgn, :@b, s(:array)),
s(:op_asgn1, s(:ivar, :@b),
@@ -3292,30 +2432,14 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("op_asgn2",
"Ruby" => "s = Struct.new(:var)\nc = s.new(nil)\nc.var ||= 20\nc.var &&= 21\nc.var += 22\nc.d.e.f ||= 42\n",
- "RawParseTree" => [:block,
- [:lasgn, :s,
- [:call, [:const, :Struct],
- :new, [:array, [:lit, :var]]]],
- [:lasgn, :c,
- [:call, [:lvar, :s], :new, [:array, [:nil]]]],
-
- [:op_asgn2, [:lvar, :c], :var=, :"||",
- [:lit, 20]],
- [:op_asgn2, [:lvar, :c], :var=, :"&&",
- [:lit, 21]],
- [:op_asgn2, [:lvar, :c], :var=, :+, [:lit, 22]],
-
- [:op_asgn2,
- [:call,
- [:call, [:lvar, :c], :d], :e], :f=, :"||",
- [:lit, 42]]],
"ParseTree" => s(:block,
s(:lasgn, :s,
- s(:call, s(:const, :Struct),
- :new, s(:arglist, s(:lit, :var)))),
+ s(:call,
+ s(:const, :Struct),
+ :new,
+ s(:lit, :var))),
s(:lasgn, :c,
- s(:call, s(:lvar, :s),
- :new, s(:arglist, s(:nil)))),
+ s(:call, s(:lvar, :s), :new, s(:nil))),
s(:op_asgn2, s(:lvar, :c),
:var=, :"||", s(:lit, 20)),
s(:op_asgn2, s(:lvar, :c),
@@ -3324,23 +2448,17 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
:var=, :+, s(:lit, 22)),
s(:op_asgn2,
s(:call,
- s(:call, s(:lvar, :c), :d, s(:arglist)),
- :e, s(:arglist)),
+ s(:call, s(:lvar, :c), :d),
+ :e),
:f=, :"||", s(:lit, 42))))
add_tests("op_asgn2_self",
"Ruby" => "self.Bag ||= Bag.new",
- "RawParseTree" => [:op_asgn2, [:self], :"Bag=", :"||",
- [:call, [:const, :Bag], :new]],
"ParseTree" => s(:op_asgn2, s(:self), :"Bag=", :"||",
- s(:call, s(:const, :Bag), :new, s(:arglist))))
+ s(:call, s(:const, :Bag), :new)))
add_tests("op_asgn_and",
"Ruby" => "a = 0\na &&= 2\n",
- "RawParseTree" => [:block,
- [:lasgn, :a, [:lit, 0]],
- [:op_asgn_and,
- [:lvar, :a], [:lasgn, :a, [:lit, 2]]]],
"ParseTree" => s(:block,
s(:lasgn, :a, s(:lit, 0)),
s(:op_asgn_and,
@@ -3348,37 +2466,19 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("op_asgn_and_ivar2",
"Ruby" => "@fetcher &&= new(Gem.configuration[:http_proxy])",
- "RawParseTree" => [:op_asgn_and,
- [:ivar, :@fetcher],
- [:iasgn,
- :@fetcher,
- [:fcall,
- :new,
- [:array,
- [:call,
- [:call, [:const, :Gem], :configuration],
- :[],
- [:array, [:lit, :http_proxy]]]]]]],
"ParseTree" => s(:op_asgn_and,
s(:ivar, :@fetcher),
s(:iasgn,
:@fetcher,
s(:call, nil,
:new,
- s(:arglist,
- s(:call,
- s(:call, s(:const, :Gem),
- :configuration,
- s(:arglist)),
- :[],
- s(:arglist, s(:lit, :http_proxy))))))))
+ s(:call,
+ s(:call, s(:const, :Gem), :configuration),
+ :[],
+ s(:lit, :http_proxy))))))
add_tests("op_asgn_or",
"Ruby" => "a = 0\na ||= 1\n",
- "RawParseTree" => [:block,
- [:lasgn, :a, [:lit, 0]],
- [:op_asgn_or,
- [:lvar, :a], [:lasgn, :a, [:lit, 1]]]],
"ParseTree" => s(:block,
s(:lasgn, :a, s(:lit, 0)),
s(:op_asgn_or,
@@ -3386,273 +2486,161 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("op_asgn_or_block",
"Ruby" => "a ||= begin\n b\n rescue\n c\n end",
- "RawParseTree" => [:op_asgn_or,
- [:lvar, :a],
- [:lasgn, :a,
- [:rescue,
- [:vcall, :b],
- [:resbody, nil, [:vcall, :c]]]]],
"ParseTree" => s(:op_asgn_or,
s(:lvar, :a),
s(:lasgn, :a,
s(:rescue,
- s(:call, nil, :b, s(:arglist)),
+ s(:call, nil, :b),
s(:resbody, s(:array),
- s(:call, nil, :c, s(:arglist)))))),
+ s(:call, nil, :c))))),
"Ruby2Ruby" => "a ||= b rescue c")
add_tests("op_asgn_or_ivar",
- "Ruby" => "@v ||= { }",
- "RawParseTree" => [:op_asgn_or,
- [:ivar, :@v],
- [:iasgn, :@v, [:hash]]],
+ "Ruby" => "@v ||= {}",
"ParseTree" => s(:op_asgn_or,
s(:ivar, :@v),
s(:iasgn, :@v, s(:hash))))
add_tests("op_asgn_or_ivar2",
"Ruby" => "@fetcher ||= new(Gem.configuration[:http_proxy])",
- "RawParseTree" => [:op_asgn_or,
- [:ivar, :@fetcher],
- [:iasgn,
- :@fetcher,
- [:fcall,
- :new,
- [:array,
- [:call,
- [:call, [:const, :Gem], :configuration],
- :[],
- [:array, [:lit, :http_proxy]]]]]]],
"ParseTree" => s(:op_asgn_or,
s(:ivar, :@fetcher),
s(:iasgn,
:@fetcher,
s(:call, nil, :new,
- s(:arglist,
- s(:call,
- s(:call, s(:const, :Gem),
- :configuration,
- s(:arglist)),
- :[],
- s(:arglist, s(:lit, :http_proxy))))))))
+ s(:call,
+ s(:call, s(:const, :Gem), :configuration),
+ :[],
+ s(:lit, :http_proxy))))))
add_tests("or",
"Ruby" => "(a or b)",
- "RawParseTree" => [:or, [:vcall, :a], [:vcall, :b]],
"ParseTree" => s(:or,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))))
+ s(:call, nil, :a),
+ s(:call, nil, :b)))
add_tests("or_big",
"Ruby" => "((a or b) or (c and d))",
- "RawParseTree" => [:or,
- [:or, [:vcall, :a], [:vcall, :b]],
- [:and, [:vcall, :c], [:vcall, :d]]],
"ParseTree" => s(:or,
s(:or,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))),
+ s(:call, nil, :a),
+ s(:call, nil, :b)),
s(:and,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist)))))
+ s(:call, nil, :c),
+ s(:call, nil, :d))))
add_tests("or_big2",
"Ruby" => "((a || b) || (c && d))",
- "RawParseTree" => [:or,
- [:or, [:vcall, :a], [:vcall, :b]],
- [:and, [:vcall, :c], [:vcall, :d]]],
"ParseTree" => s(:or,
s(:or,
- s(:call, nil, :a, s(:arglist)),
- s(:call, nil, :b, s(:arglist))),
+ s(:call, nil, :a),
+ s(:call, nil, :b)),
s(:and,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist)))),
+ s(:call, nil, :c),
+ s(:call, nil, :d))),
"Ruby2Ruby" => "((a or b) or (c and d))")
add_tests("parse_floats_as_args",
"Ruby" => "def x(a=0.0,b=0.0)\n a+b\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :a, :b,
- [:block,
- [:lasgn, :a, [:lit, 0.0]],
- [:lasgn, :b, [:lit, 0.0]]]],
- [:call, [:lvar, :a], :+,
- [:array, [:lvar, :b]]]]]],
"ParseTree" => s(:defn, :x,
- s(:args, :a, :b,
- s(:block,
- s(:lasgn, :a, s(:lit, 0.0)),
- s(:lasgn, :b, s(:lit, 0.0)))),
- s(:scope,
- s(:block,
- s(:call, s(:lvar, :a), :+,
- s(:arglist, s(:lvar, :b)))))),
+ s(:args,
+ s(:lasgn, :a, s(:lit, 0.0)),
+ s(:lasgn, :b, s(:lit, 0.0))),
+ s(:call, s(:lvar, :a), :+, s(:lvar, :b))),
"Ruby2Ruby" => "def x(a = 0.0, b = 0.0)\n (a + b)\nend")
add_tests("postexe",
"Ruby" => "END { 1 }",
- "RawParseTree" => [:iter, [:postexe], nil, [:lit, 1]],
- "ParseTree" => s(:iter, s(:postexe), nil, s(:lit, 1)))
+ "ParseTree" => s(:iter, s(:postexe), s(:args), s(:lit, 1)))
add_tests("proc_args_0",
"Ruby" => "proc { || (x + 1) }",
- "RawParseTree" => [:iter,
- [:fcall, :proc],
- 0,
- [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :proc, s(:arglist)),
+ s(:call, nil, :proc),
0,
- s(:call,
- s(:call, nil, :x, s(:arglist)),
- :+,
- s(:arglist, s(:lit, 1)))))
+ s(:call, s(:call, nil, :x), :+, s(:lit, 1))))
add_tests("proc_args_1",
"Ruby" => "proc { |x| (x + 1) }",
- "RawParseTree" => [:iter,
- [:fcall, :proc],
- [:dasgn_curr, :x],
- [:call, [:dvar, :x], :+, [:array, [:lit, 1]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :proc, s(:arglist)),
- s(:lasgn, :x),
- s(:call, s(:lvar, :x), :+,
- s(:arglist, s(:lit, 1)))))
+ s(:call, nil, :proc),
+ s(:args, :x),
+ s(:call, s(:lvar, :x), :+, s(:lit, 1))))
add_tests("proc_args_2",
"Ruby" => "proc { |x, y| (x + y) }",
- "RawParseTree" => [:iter,
- [:fcall, :proc],
- [:masgn, [:array,
- [:dasgn_curr, :x],
- [:dasgn_curr, :y]], nil, nil],
- [:call, [:dvar, :x], :+, [:array, [:dvar, :y]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :proc, s(:arglist)),
- s(:masgn,
- s(:array,
- s(:lasgn, :x),
- s(:lasgn, :y))),
- s(:call, s(:lvar, :x), :+,
- s(:arglist, s(:lvar, :y)))))
+ s(:call, nil, :proc),
+ s(:args, :x, :y),
+ s(:call, s(:lvar, :x), :+, s(:lvar, :y))))
add_tests("proc_args_no",
"Ruby" => "proc { (x + 1) }",
- "RawParseTree" => [:iter,
- [:fcall, :proc],
- nil,
- [:call, [:vcall, :x], :+, [:array, [:lit, 1]]]],
"ParseTree" => s(:iter,
- s(:call, nil, :proc, s(:arglist)),
- nil,
- s(:call, s(:call, nil, :x, s(:arglist)),
- :+, s(:arglist, s(:lit, 1)))))
+ s(:call, nil, :proc),
+ s(:args),
+ s(:call, s(:call, nil, :x), :+, s(:lit, 1))))
add_tests("redo",
"Ruby" => "loop { redo if false }",
- "RawParseTree" => [:iter,
- [:fcall, :loop], nil,
- [:if, [:false], [:redo], nil]],
"ParseTree" => s(:iter,
- s(:call, nil, :loop, s(:arglist)),
- nil,
+ s(:call, nil, :loop),
+ s(:args),
s(:if, s(:false), s(:redo), nil)))
- # TODO: need a resbody w/ multiple classes and a splat
-
- add_tests("rescue",
+ add_tests("rescue", # TODO: need a resbody w/ multiple classes and a splat
"Ruby" => "blah rescue nil",
- "RawParseTree" => [:rescue,
- [:vcall, :blah], [:resbody, nil, [:nil]]],
"ParseTree" => s(:rescue,
- s(:call, nil, :blah, s(:arglist)),
+ s(:call, nil, :blah),
s(:resbody, s(:array), s(:nil))))
add_tests("rescue_block_body",
"Ruby" => "begin\n a\nrescue => e\n c\n d\nend",
- "RawParseTree" => [:rescue,
- [:vcall, :a],
- [:resbody, nil,
- [:block,
- [:lasgn, :e, [:gvar, :$!]],
- [:vcall, :c],
- [:vcall, :d]]]],
"ParseTree" => s(:rescue,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
s(:resbody,
s(:array, s(:lasgn, :e, s(:gvar, :$!))),
- s(:block,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist))))))
+ s(:call, nil, :c),
+ s(:call, nil, :d))))
add_tests("rescue_block_body_3",
"Ruby" => "begin\n a\nrescue A\n b\nrescue B\n c\nrescue C\n d\nend",
- "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(:call, nil, :a),
s(:resbody, s(:array, s(:const, :A)),
- s(:call, nil, :b, s(:arglist))),
+ s(:call, nil, :b)),
s(:resbody, s(:array, s(:const, :B)),
- s(:call, nil, :c, s(:arglist))),
+ s(:call, nil, :c)),
s(:resbody, s(:array, s(:const, :C)),
- s(:call, nil, :d, s(:arglist)))))
+ s(:call, nil, :d))))
add_tests("rescue_block_body_ivar",
"Ruby" => "begin\n a\nrescue => @e\n c\n d\nend",
- "RawParseTree" => [:rescue,
- [:vcall, :a],
- [:resbody, nil,
- [:block,
- [:iasgn, :@e, [:gvar, :$!]],
- [:vcall, :c],
- [:vcall, :d]]]],
"ParseTree" => s(:rescue,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
s(:resbody,
s(:array, s(:iasgn, :@e, s(:gvar, :$!))),
- s(:block,
- s(:call, nil, :c, s(:arglist)),
- s(:call, nil, :d, s(:arglist))))))
+ s(:call, nil, :c),
+ s(:call, nil, :d))))
add_tests("rescue_block_nada",
"Ruby" => "begin\n blah\nrescue\n # do nothing\nend",
- "RawParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil]],
"ParseTree" => s(:rescue,
- s(:call, nil, :blah, s(:arglist)),
+ s(:call, nil, :blah),
s(:resbody, s(:array), nil)))
add_tests("rescue_exceptions",
"Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend",
- "RawParseTree" => [:rescue,
- [:vcall, :blah],
- [:resbody,
- [:array, [:const, :RuntimeError]],
- [:lasgn, :r, [:gvar, :$!]]]],
"ParseTree" => s(:rescue,
- s(:call, nil, :blah, s(:arglist)),
+ s(:call, nil, :blah),
s(:resbody,
s(:array,
s(:const, :RuntimeError),
s(:lasgn, :r, s(:gvar, :$!))),
nil)))
-
add_tests("rescue_iasgn_var_empty",
"Ruby" => "begin\n 1\nrescue => @e\n # do nothing\nend",
- "RawParseTree" => [:rescue,
- [:lit, 1],
- [:resbody, nil, [:iasgn, :@e, [:gvar, :$!]]]],
"ParseTree" => s(:rescue,
s(:lit, 1),
s(:resbody,
@@ -3661,9 +2649,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("rescue_lasgn",
"Ruby" => "begin\n 1\nrescue\n var = 2\nend",
- "RawParseTree" => [:rescue,
- [:lit, 1],
- [:resbody, nil, [:lasgn, :var, [:lit, 2]]]],
"ParseTree" => s(:rescue,
s(:lit, 1),
s(:resbody,
@@ -3673,12 +2658,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("rescue_lasgn_var",
"Ruby" => "begin\n 1\nrescue => e\n var = 2\nend",
- "RawParseTree" => [:rescue,
- [:lit, 1],
- [:resbody, nil,
- [:block,
- [:lasgn, :e, [:gvar, :$!]],
- [:lasgn, :var, [:lit, 2]]]]],
"ParseTree" => s(:rescue,
s(:lit, 1),
s(:resbody,
@@ -3687,9 +2666,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("rescue_lasgn_var_empty",
"Ruby" => "begin\n 1\nrescue => e\n # do nothing\nend",
- "RawParseTree" => [:rescue,
- [:lit, 1],
- [:resbody, nil, [:lasgn, :e, [:gvar, :$!]]]],
"ParseTree" => s(:rescue,
s(:lit, 1),
s(:resbody,
@@ -3698,412 +2674,278 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("retry",
"Ruby" => "retry",
- "RawParseTree" => [:retry],
"ParseTree" => s(:retry))
add_tests("return_0",
"Ruby" => "return",
- "RawParseTree" => [:return],
"ParseTree" => s(:return))
add_tests("return_1",
"Ruby" => "return 1",
- "RawParseTree" => [:return, [:lit, 1]],
"ParseTree" => s(:return, s(:lit, 1)))
add_tests("return_1_splatted",
"Ruby" => "return *1",
- "RawParseTree" => [:return, [:svalue, [:splat, [:lit, 1]]]],
"ParseTree" => s(:return, s(:svalue, s(:splat, s(:lit, 1)))))
add_tests("return_n",
"Ruby" => "return 1, 2, 3",
- "RawParseTree" => [:return, [:array,
- [:lit, 1], [:lit, 2], [:lit, 3]]],
"ParseTree" => s(:return, s(:array,
s(:lit, 1), s(:lit, 2), s(:lit, 3))),
"Ruby2Ruby" => "return [1, 2, 3]")
add_tests("sclass",
"Ruby" => "class << self\n 42\nend",
- "RawParseTree" => [:sclass, [:self], [:scope, [:lit, 42]]],
- "ParseTree" => s(:sclass, s(:self), s(:scope, s(:lit, 42))))
+ "ParseTree" => s(:sclass, s(:self), s(:lit, 42)))
+
+ add_tests("sclass_multiple",
+ "Ruby" => "class << self\n x\n y\nend",
+ "ParseTree" => s(:sclass, s(:self),
+ s(:call, nil, :x), s(:call, nil, :y)))
add_tests("sclass_trailing_class",
- "Ruby" => "class A\n class << self\n a\n end\n class B\n end\nend",
- "RawParseTree" => [:class, :A, nil,
- [:scope,
- [:block,
- [:sclass, [:self], [:scope, [:vcall, :a]]],
- [:class, :B, nil, [:scope]]]]],
+ "Ruby" => "class A\n class << self\n a\n end\n \n class B\n end\nend",
"ParseTree" => s(:class, :A, nil,
- s(:scope,
- s(:block,
- s(:sclass, s(:self),
- s(:scope,
- s(:call, nil, :a, s(:arglist)))),
- s(:class, :B, nil, s(:scope))))))
+ s(:sclass, s(:self),
+ s(:call, nil, :a)),
+ s(:class, :B, nil)))
add_tests("splat",
"Ruby" => "def x(*b)\n a(*b)\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args, :"*b"],
- [:fcall, :a, [:splat, [:lvar, :b]]]]]],
"ParseTree" => s(:defn, :x,
s(:args, :"*b"),
- s(:scope,
- s(:block,
- s(:call, nil, :a,
- s(:arglist, s(:splat, s(:lvar, :b))))))))
+ s(:call, nil, :a, s(:splat, s(:lvar, :b)))))
add_tests("splat_array",
"Ruby" => "[*[1]]",
- "RawParseTree" => [:splat, [:array, [:lit, 1]]],
"ParseTree" => s(:array, s(:splat, s(:array, s(:lit, 1)))))
add_tests("splat_break",
"Ruby" => "break *[1]",
- "RawParseTree" => [:break, [:svalue, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:break, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_break_array",
"Ruby" => "break [*[1]]",
- "RawParseTree" => [:break, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:break, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_fcall",
"Ruby" => "meth(*[1])",
- "RawParseTree" => [:fcall, :meth,
- [:splat, [:array, [:lit, 1]]]],
- "ParseTree" => s(:call, nil, :meth,
- s(:arglist, s(:splat, s(:array, s(:lit, 1))))))
+ "ParseTree" => s(:call,
+ nil,
+ :meth,
+ s(:splat, s(:array, s(:lit, 1)))))
add_tests("splat_fcall_array",
"Ruby" => "meth([*[1]])",
- "RawParseTree" => [:fcall, :meth,
- [:array, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:call, nil, :meth,
- s(:arglist,
- s(:array, s(:splat, s(:array, s(:lit, 1)))))))
+ s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_lasgn",
"Ruby" => "x = *[1]",
- "RawParseTree" => [:lasgn, :x, [:svalue, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:lasgn, :x, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_lasgn_array",
"Ruby" => "x = [*[1]]",
- "RawParseTree" => [:lasgn, :x, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:lasgn, :x, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_lit_1",
"Ruby" => "[*1]",
- "RawParseTree" => [:splat, [:lit, 1]], # UGH - damn MRI
+# UGH - damn MRI
"ParseTree" => s(:array, s(:splat, s(:lit, 1))))
add_tests("splat_lit_n",
"Ruby" => "[1, *2]",
- "RawParseTree" => [:argscat, [:array, [:lit, 1]], [:lit, 2]],
"ParseTree" => s(:array, s(:lit, 1), s(:splat, s(:lit, 2))))
add_tests("splat_next",
"Ruby" => "next *[1]",
- "RawParseTree" => [:next, [:svalue, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:next, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_next_array",
"Ruby" => "next [*[1]]",
- "RawParseTree" => [:next, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:next, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_return",
"Ruby" => "return *[1]",
- "RawParseTree" => [:return, [:svalue, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:return, s(:svalue, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_return_array",
"Ruby" => "return [*[1]]",
- "RawParseTree" => [:return, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:return, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_super",
"Ruby" => "super(*[1])",
- "RawParseTree" => [:super, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:super, s(:splat, s(:array, s(:lit, 1)))))
add_tests("splat_super_array",
"Ruby" => "super([*[1]])",
- "RawParseTree" => [:super, [:array, [:splat, [:array, [:lit, 1]]]]],
"ParseTree" => s(:super, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("splat_yield",
"Ruby" => "yield(*[1])",
- "RawParseTree" => [:yield, [:splat, [:array, [:lit, 1]]]],
"ParseTree" => s(:yield, s(:splat, s(:array, s(:lit, 1)))))
add_tests("splat_yield_array",
"Ruby" => "yield([*[1]])",
- "RawParseTree" => [:yield, [:splat, [:array, [:lit, 1]]], true],
"ParseTree" => s(:yield, s(:array, s(:splat, s(:array, s(:lit, 1))))))
add_tests("str",
"Ruby" => '"x"',
- "RawParseTree" => [:str, "x"],
"ParseTree" => s(:str, "x"))
add_tests("str_concat_newline", # FIX? make prettier? possible?
"Ruby" => '"before" \\
" after"',
- "RawParseTree" => [:str, "before after"],
"ParseTree" => s(:str, "before after"),
"Ruby2Ruby" => '"before after"')
add_tests("str_concat_space",
"Ruby" => '"before" " after"',
- "RawParseTree" => [:str, "before after"],
"ParseTree" => s(:str, "before after"),
"Ruby2Ruby" => '"before after"')
add_tests("str_heredoc",
"Ruby" => "<<'EOM'\n blah\nblah\nEOM",
- "RawParseTree" => [:str, " blah\nblah\n"],
"ParseTree" => s(:str, " blah\nblah\n"),
"Ruby2Ruby" => "\" blah\\nblah\\n\"")
add_tests("str_heredoc_call",
"Ruby" => "<<'EOM'.strip\n blah\nblah\nEOM",
- "RawParseTree" => [:call, [:str, " blah\nblah\n"], :strip],
"ParseTree" => s(:call, s(:str, " blah\nblah\n"),
- :strip, s(:arglist)),
+ :strip),
"Ruby2Ruby" => "\" blah\\nblah\\n\".strip")
add_tests("str_heredoc_double",
"Ruby" => "a += <<-H1 + b + <<-H2\n first\nH1\n second\nH2",
- "RawParseTree" => [:lasgn, :a,
- [:call,
- [:lvar, :a],
- :+,
- [:array,
- [:call,
- [:call, [:str, " first\n"], :+,
- [:array, [:vcall, :b]]],
- :+,
- [:array, [:str, " second\n"]]]]]],
"ParseTree" => s(:lasgn, :a,
s(:call,
s(:lvar, :a),
:+,
- s(:arglist,
+ s(:call,
s(:call,
- s(:call, s(:str, " first\n"), :+,
- s(:arglist,
- s(:call, nil, :b, s(:arglist)))),
+ s(:str, " first\n"),
:+,
- s(:arglist, s(:str, " second\n")))))),
+ s(:call, nil, :b)),
+ :+,
+ s(:str, " second\n")))),
"Ruby2Ruby" => "a = (a + ((\" first\\n\" + b) + \" second\\n\"))")
add_tests("str_heredoc_empty", # yes... tarded
"Ruby" => "<<'EOM'\nEOM",
- "RawParseTree" => [:str, ""],
"ParseTree" => s(:str, ""),
"Ruby2Ruby" => '""')
add_tests("str_heredoc_indent",
"Ruby" => "<<-EOM\n blah\nblah\n\n EOM",
- "RawParseTree" => [:str, " blah\nblah\n\n"],
"ParseTree" => s(:str, " blah\nblah\n\n"),
"Ruby2Ruby" => "\" blah\\nblah\\n\\n\"")
add_tests("str_interp_file",
"Ruby" => '"file = #{__FILE__}\n"',
- "RawParseTree" => [:str, "file = (string)\n"],
"ParseTree" => s(:str, "file = (string)\n"),
"Ruby2Ruby" => '"file = (string)\\n"')
add_tests("structure_extra_block_for_dvar_scoping",
"Ruby" => "a.b do |c, d|\n unless e.f(c) then\n g = false\n d.h { |x, i| g = true }\n end\nend",
- "RawParseTree" => [:iter,
- [:call, [:vcall, :a], :b],
- [:masgn, [:array,
- [:dasgn_curr, :c],
- [:dasgn_curr, :d]], nil, nil],
- [:if,
- [:call, [:vcall, :e], :f,
- [:array, [:dvar, :c]]],
- nil,
- [:block,
- [:dasgn_curr, :g, [:false]],
- [:iter,
- [:call, [:dvar, :d], :h],
- [:masgn, [:array,
- [:dasgn_curr, :x],
- [:dasgn_curr, :i]], nil, nil],
- [:dasgn, :g, [:true]]]]]],
"ParseTree" => s(:iter,
- s(:call,
- s(:call, nil, :a, s(:arglist)),
- :b, s(:arglist)),
- s(:masgn, s(:array,
- s(:lasgn, :c),
- s(:lasgn, :d))),
+ s(:call, s(:call, nil, :a), :b),
+ s(:args, :c, :d),
s(:if,
- s(:call, s(:call, nil, :e, s(:arglist)), :f,
- s(:arglist, s(:lvar, :c))),
+ s(:call, s(:call, nil, :e), :f, s(:lvar, :c)),
nil,
s(:block,
s(:lasgn, :g, s(:false)),
s(:iter,
- s(:call, s(:lvar, :d), :h, s(:arglist)),
- s(:masgn, s(:array,
- s(:lasgn, :x),
- s(:lasgn, :i))),
+ s(:call, s(:lvar, :d), :h),
+ s(:args, :x, :i),
s(:lasgn, :g, s(:true)))))))
add_tests("structure_remove_begin_1",
"Ruby" => "a << begin\n b\n rescue\n c\n end",
- "RawParseTree" => [:call, [:vcall, :a], :<<,
- [:array, [:rescue, [:vcall, :b],
- [:resbody, nil, [:vcall, :c]]]]],
- "ParseTree" => s(:call, s(:call, nil, :a, s(:arglist)), :<<,
- s(:arglist,
- s(:rescue,
- s(:call, nil, :b, s(:arglist)),
- s(:resbody, s(:array),
- s(:call, nil, :c, s(:arglist)))))),
- "Ruby2Ruby" => "(a << b rescue c)")
+ "ParseTree" => s(:call, s(:call, nil, :a), :<<,
+ s(:rescue,
+ s(:call, nil, :b),
+ s(:resbody, s(:array),
+ s(:call, nil, :c)))),
+ "Ruby2Ruby" => "(a << (b rescue c))")
add_tests("structure_remove_begin_2",
"Ruby" => "a = if c\n begin\n b\n rescue\n nil\n end\n end\na",
- "RawParseTree" => [:block,
- [:lasgn,
- :a,
- [:if, [:vcall, :c],
- [:rescue,
- [:vcall, :b],
- [:resbody, nil, [:nil]]],
- nil]],
- [:lvar, :a]],
"ParseTree" => s(:block,
s(:lasgn,
:a,
- s(:if, s(:call, nil, :c, s(:arglist)),
- s(:rescue, s(:call, nil, :b, s(:arglist)),
+ s(:if, s(:call, nil, :c),
+ s(:rescue, s(:call, nil, :b),
s(:resbody,
s(:array), s(:nil))),
nil)),
s(:lvar, :a)),
"Ruby2Ruby" => "a = b rescue nil if c\na\n") # OMG that's awesome
- add_tests("structure_unused_literal_wwtt",
- "Ruby" => "\"prevent the above from infecting rdoc\"\n\nmodule Graffle\nend",
- "RawParseTree" => [:module, :Graffle, [:scope]],
- "ParseTree" => s(:module, :Graffle, s(:scope)),
- "Ruby2Ruby" => "module Graffle\nend")
-
add_tests("super_0",
"Ruby" => "def x\n super()\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block, [:args], [:super]]]],
- "ParseTree" => s(:defn, :x,
- s(:args),
- s(:scope, s(:block, s(:super)))))
+ "ParseTree" => s(:defn, :x, s(:args), s(:super)))
add_tests("super_1",
"Ruby" => "def x\n super(4)\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args],
- [:super, [:array, [:lit, 4]]]]]],
- "ParseTree" => s(:defn, :x,
- s(:args),
- s(:scope,
- s(:block,
- s(:super, s(:lit, 4))))))
+ "ParseTree" => s(:defn, :x, s(:args),
+ s(:super, s(:lit, 4))))
add_tests("super_1_array",
"Ruby" => "def x\n super([24, 42])\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args],
- [:super,
- [:array,
- [:array, [:lit, 24], [:lit, 42]]]]]]],
- "ParseTree" => s(:defn, :x,
- s(:args),
- s(:scope,
- s(:block,
- s(:super, s(:array,
- s(:lit, 24),
- s(:lit, 42)))))))
+ "ParseTree" => s(:defn, :x, s(:args),
+ s(:super, s(:array, s(:lit, 24), s(:lit, 42)))))
add_tests("super_block_pass",
"Ruby" => "super(a, &b)",
- "RawParseTree" => [:block_pass,
- [:vcall, :b], [:super, [:array, [:vcall, :a]]]],
"ParseTree" => s(:super,
- s(:call, nil, :a, s(:arglist)),
+ s(:call, nil, :a),
s(:block_pass,
- s(:call, nil, :b, s(:arglist)))))
+ s(:call, nil, :b))))
add_tests("super_block_splat",
"Ruby" => "super(a, *b)",
- "RawParseTree" => [:super,
- [:argscat,
- [:array, [:vcall, :a]],
- [:vcall, :b]]],
"ParseTree" => s(:super,
- s(:call, nil, :a, s(:arglist)),
- s(:splat, s(:call, nil, :b, s(:arglist)))))
+ s(:call, nil, :a),
+ s(:splat, s(:call, nil, :b))))
add_tests("super_n",
"Ruby" => "def x\n super(24, 42)\nend",
- "RawParseTree" => [:defn, :x,
- [:scope,
- [:block,
- [:args],
- [:super, [:array, [:lit, 24], [:lit, 42]]]]]],
- "ParseTree" => s(:defn, :x,
- s(:args),
- s(:scope,
- s(:block,
- s(:super, s(:lit, 24), s(:lit, 42))))))
+ "ParseTree" => s(:defn, :x, s(:args),
+ s(:super, s(:lit, 24), s(:lit, 42))))
add_tests("svalue",
"Ruby" => "a = *b",
- "RawParseTree" => [:lasgn, :a, [:svalue, [:splat, [:vcall, :b]]]],
"ParseTree" => s(:lasgn, :a,
s(:svalue,
- s(:splat, s(:call, nil, :b, s(:arglist))))))
+ s(:splat, s(:call, nil, :b)))))
+
+ add_tests("ternary_nil_no_space",
+ "Ruby" => "1 ? nil: 1",
+ "ParseTree" => s(:if, s(:lit, 1), s(:nil), s(:lit, 1)),
+ "Ruby2Ruby" => "1 ? (nil) : (1)")
+
+ add_tests("ternary_symbol_no_spaces",
+ "Ruby" => "1?:x:1",
+ "ParseTree" => s(:if, s(:lit, 1), s(:lit, :x), s(:lit, 1)),
+ "Ruby2Ruby" => "1 ? (:x) : (1)")
add_tests("to_ary",
"Ruby" => "a, b = c",
- "RawParseTree" => [:masgn,
- [:array, [:lasgn, :a], [:lasgn, :b]], nil,
- [:to_ary, [:vcall, :c]]],
"ParseTree" => s(:masgn,
s(:array, s(:lasgn, :a), s(:lasgn, :b)),
- s(:to_ary, s(:call, nil, :c, s(:arglist)))))
+ s(:to_ary, s(:call, nil, :c))))
add_tests("true",
"Ruby" => "true",
- "RawParseTree" => [:true],
"ParseTree" => s(:true))
add_tests("undef",
"Ruby" => "undef :x",
- "RawParseTree" => [:undef, [:lit, :x]],
"ParseTree" => s(:undef, s(:lit, :x)))
add_tests("undef_2",
"Ruby" => "undef :x, :y",
- "RawParseTree" => [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]]],
"ParseTree" => s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y))),
@@ -4111,10 +2953,6 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("undef_3",
"Ruby" => "undef :x, :y, :z",
- "RawParseTree" => [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]],
- [:undef, [:lit, :z]]],
"ParseTree" => s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y)),
@@ -4123,23 +2961,14 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("undef_block_1",
"Ruby" => "f1\nundef :x\n", # TODO: don't like the extra return
- "RawParseTree" => [:block,
- [:vcall, :f1],
- [:undef, [:lit, :x]]],
"ParseTree" => s(:block,
- s(:call, nil, :f1, s(:arglist)),
+ s(:call, nil, :f1),
s(:undef, s(:lit, :x))))
add_tests("undef_block_2",
"Ruby" => "f1\nundef :x, :y",
- "RawParseTree" => [:block,
- [:vcall, :f1],
- [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]],
- ]],
"ParseTree" => s(:block,
- s(:call, nil, :f1, s(:arglist)),
+ s(:call, nil, :f1),
s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y)))),
@@ -4147,15 +2976,8 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("undef_block_3",
"Ruby" => "f1\nundef :x, :y, :z",
- "RawParseTree" => [:block,
- [:vcall, :f1],
- [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]],
- [:undef, [:lit, :z]],
- ]],
"ParseTree" => s(:block,
- s(:call, nil, :f1, s(:arglist)),
+ s(:call, nil, :f1),
s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y)),
@@ -4164,254 +2986,128 @@ class ParseTreeTestCase < MiniTest::Unit::TestCase
add_tests("undef_block_3_post",
"Ruby" => "undef :x, :y, :z\nf2",
- "RawParseTree" => [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]],
- [:undef, [:lit, :z]],
- [:vcall, :f2]],
"ParseTree" => s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y)),
s(:undef, s(:lit, :z)),
- s(:call, nil, :f2, s(:arglist))),
+ s(:call, nil, :f2)),
"Ruby2Ruby" => "undef :x\nundef :y\nundef :z\nf2\n")
add_tests("undef_block_wtf",
"Ruby" => "f1\nundef :x, :y, :z\nf2",
- "RawParseTree" => [:block,
- [:vcall, :f1],
- [:block,
- [:undef, [:lit, :x]],
- [:undef, [:lit, :y]],
- [:undef, [:lit, :z]]],
- [:vcall, :f2]],
"ParseTree" => s(:block,
- s(:call, nil, :f1, s(:arglist)),
+ s(:call, nil, :f1),
s(:block,
s(:undef, s(:lit, :x)),
s(:undef, s(:lit, :y)),
s(:undef, s(:lit, :z))),
- s(:call, nil, :f2, s(:arglist))),
+ s(:call, nil, :f2)),
"Ruby2Ruby" => "f1\n(undef :x\nundef :y\nundef :z)\nf2\n")
-
add_tests("unless_post",
"Ruby" => "a unless b",
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
- s(:call, nil, :a, s(:arglist))))
-
- add_tests("unless_post_not",
- "Ruby" => "a unless not b",
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
- s(:call, nil, :a, s(:arglist)), nil),
- "Ruby2Ruby" => "a if b")
+ "ParseTree" => s(:if, s(:call, nil, :b), nil,
+ s(:call, nil, :a)))
add_tests("unless_pre",
"Ruby" => "unless b then a end",
- "RawParseTree" => [:if, [:vcall, :b], nil, [:vcall, :a]],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)), nil,
- s(:call, nil, :a, s(:arglist))),
+ "ParseTree" => s(:if, s(:call, nil, :b), nil,
+ s(:call, nil, :a)),
"Ruby2Ruby" => "a unless b")
- add_tests("unless_pre_not",
- "Ruby" => "unless not b then a end",
- "RawParseTree" => [:if, [:vcall, :b], [:vcall, :a], nil],
- "ParseTree" => s(:if, s(:call, nil, :b, s(:arglist)),
- s(:call, nil, :a, s(:arglist)), nil),
- "Ruby2Ruby" => "a if b")
-
add_tests("until_post",
"Ruby" => "begin\n (1 + 1)\nend until false",
- "RawParseTree" => [:until, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], false],
"ParseTree" => s(:until, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), false))
-
- add_tests("until_post_not",
- "Ruby" => "begin\n (1 + 1)\nend until not true",
- "RawParseTree" => [:while, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], false],
- "ParseTree" => s(:while, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), false),
- "Ruby2Ruby" => "begin\n (1 + 1)\nend while true")
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false))
add_tests("until_pre",
"Ruby" => "until false do\n (1 + 1)\nend",
- "RawParseTree" => [:until, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
"ParseTree" => s(:until, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true))
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true))
add_tests("until_pre_mod",
"Ruby" => "(1 + 1) until false",
- "RawParseTree" => [:until, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
"ParseTree" => s(:until, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
"Ruby2Ruby" => "until false do\n (1 + 1)\nend")
- add_tests("until_pre_not",
- "Ruby" => "until not true do\n (1 + 1)\nend",
- "RawParseTree" => [:while, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
- "ParseTree" => s(:while, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
- "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
-
- add_tests("until_pre_not_mod",
- "Ruby" => "(1 + 1) until not true",
- "RawParseTree" => [:while, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
- "ParseTree" => s(:while, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
- "Ruby2Ruby" => "while true do\n (1 + 1)\nend")
-
add_tests("valias",
"Ruby" => "alias $y $x",
- "RawParseTree" => [:valias, :$y, :$x],
"ParseTree" => s(:valias, :$y, :$x))
add_tests("vcall",
"Ruby" => "method",
- "RawParseTree" => [:vcall, :method],
- "ParseTree" => s(:call, nil, :method, s(:arglist)))
+ "ParseTree" => s(:call, nil, :method))
add_tests("while_post",
"Ruby" => "begin\n (1 + 1)\nend while false",
- "RawParseTree" => [:while, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], false],
"ParseTree" => s(:while, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), false))
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), false))
add_tests("while_post2",
"Ruby" => "begin\n (1 + 2)\n (3 + 4)\nend while false",
- "RawParseTree" => [:while, [:false],
- [:block,
- [:call, [:lit, 1], :+, [:array, [:lit, 2]]],
- [:call, [:lit, 3], :+, [:array, [:lit, 4]]]],
- false],
"ParseTree" => s(:while, s(:false),
s(:block,
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 2))),
- s(:call, s(:lit, 3), :+,
- s(:arglist, s(:lit, 4)))),
+ s(:call, s(:lit, 1), :+, s(:lit, 2)),
+ s(:call, s(:lit, 3), :+, s(:lit, 4))),
false))
- add_tests("while_post_not",
- "Ruby" => "begin\n (1 + 1)\nend while not true",
- "RawParseTree" => [:until, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], false],
- "ParseTree" => s(:until, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), false),
- "Ruby2Ruby" => "begin\n (1 + 1)\nend until true")
-
add_tests("while_pre",
"Ruby" => "while false do\n (1 + 1)\nend",
- "RawParseTree" => [:while, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
"ParseTree" => s(:while, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true))
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true))
add_tests("while_pre_mod",
"Ruby" => "(1 + 1) while false",
- "RawParseTree" => [:while, [:false],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
"ParseTree" => s(:while, s(:false),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
+ s(:call, s(:lit, 1), :+, s(:lit, 1)), true),
"Ruby2Ruby" => "while false do\n (1 + 1)\nend") # FIX can be one liner
add_tests("while_pre_nil",
"Ruby" => "while false do\nend",
- "RawParseTree" => [:while, [:false], nil, true],
"ParseTree" => s(:while, s(:false), nil, true))
- add_tests("while_pre_not",
- "Ruby" => "while not true do\n (1 + 1)\nend",
- "RawParseTree" => [:until, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
- "ParseTree" => s(:until, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
- "Ruby2Ruby" => "until true do\n (1 + 1)\nend")
-
- add_tests("while_pre_not_mod",
- "Ruby" => "(1 + 1) while not true",
- "RawParseTree" => [:until, [:true],
- [:call, [:lit, 1], :+,
- [:array, [:lit, 1]]], true],
- "ParseTree" => s(:until, s(:true),
- s(:call, s(:lit, 1), :+,
- s(:arglist, s(:lit, 1))), true),
- "Ruby2Ruby" => "until true do\n (1 + 1)\nend") # FIX
-
add_tests("xstr",
"Ruby" => "`touch 5`",
- "RawParseTree" => [:xstr, 'touch 5'],
"ParseTree" => s(:xstr, 'touch 5'))
add_tests("yield_0",
"Ruby" => "yield",
- "RawParseTree" => [:yield],
"ParseTree" => s(:yield))
add_tests("yield_1",
"Ruby" => "yield(42)",
- "RawParseTree" => [:yield, [:lit, 42]],
"ParseTree" => s(:yield, s(:lit, 42)))
add_tests("yield_array_0",
"Ruby" => "yield([])",
- "RawParseTree" => [:yield, [:zarray], true],
"ParseTree" => s(:yield, s(:array)))
add_tests("yield_array_1",
"Ruby" => "yield([42])",
- "RawParseTree" => [:yield, [:array, [:lit, 42]], true],
"ParseTree" => s(:yield, s(:array, s(:lit, 42))))
add_tests("yield_array_n",
"Ruby" => "yield([42, 24])",
- "RawParseTree" => [:yield, [:array, [:lit, 42], [:lit, 24]], true],
"ParseTree" => s(:yield, s(:array, s(:lit, 42), s(:lit, 24))))
add_tests("yield_n",
"Ruby" => "yield(42, 24)",
- "RawParseTree" => [:yield, [:array, [:lit, 42], [:lit, 24]]],
"ParseTree" => s(:yield, s(:lit, 42), s(:lit, 24)))
add_tests("zarray",
"Ruby" => "a = []",
- "RawParseTree" => [:lasgn, :a, [:zarray]],
"ParseTree" => s(:lasgn, :a, s(:array)))
add_tests("zsuper",
"Ruby" => "def x\n super\nend",
- "RawParseTree" => [:defn, :x,
- [:scope, [:block, [:args], [:zsuper]]]],
- "ParseTree" => s(:defn, :x, s(:args),
- s(:scope, s(:block, s(:zsuper)))))
+ "ParseTree" => s(:defn, :x, s(:args), s(:zsuper)))
+
+# TODO: discuss and decide which lit we like
+# it "converts a regexp to an sexp" do
+# "/blah/".to_sexp.should == s(:regex, "blah", 0)
+# "/blah/i".to_sexp.should == s(:regex, "blah", 1)
+# "/blah/u".to_sexp.should == s(:regex, "blah", 64)
+# end
+
end
diff --git a/rubygem-ruby2ruby.spec b/rubygem-ruby2ruby.spec
index 0479371..3f02a91 100644
--- a/rubygem-ruby2ruby.spec
+++ b/rubygem-ruby2ruby.spec
@@ -4,8 +4,8 @@
Summary: Generate pure ruby from RubyParser compatible Sexps
Name: rubygem-%{gem_name}
-Version: 2.0.6
-Release: 2%{?dist}
+Version: 2.1.1
+Release: 1%{?dist}
Group: Development/Languages
License: MIT
URL: http://seattlerb.rubyforge.org/ruby2ruby/
@@ -15,10 +15,6 @@ Source0: http://gems.rubyforge.org/gems/%{gem_name}-%{version}.gem
# dependency
Source1: pt_testcase.rb
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-Requires: rubygem(sexp_processor)
-Requires: rubygem(ruby_parser)
-Requires: ruby(rubygems)
-Requires: ruby(release)
BuildRequires: rubygems-devel
BuildRequires: ruby(release)
BuildRequires: rubygem(minitest)
@@ -42,15 +38,20 @@ Requires: %{name} = %{version}-%{release}
This package contains documentation for %{name}.
%prep
-%setup -q -c -T
+gem unpack %{SOURCE0}
+
+%setup -q -D -T -n %{gem_name}-%{version}
+
+gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec
%build
-%gem_install -n %{SOURCE0}
+gem build %{gem_name}.gemspec
+
+%gem_install
cp -p %{SOURCE1} $(pwd)/%{gem_instdir}/test/
%install
-rm -rf %{buildroot}
mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* %{buildroot}%{gem_dir}/
@@ -70,12 +71,9 @@ find %{buildroot}%{gem_instdir} -type f | \
find %{buildroot}%{gem_instdir}/bin -type f | \
xargs chmod 0755
-%clean
-rm -rf %{buildroot}
-
%check
pushd .%{gem_instdir}
-testrb test
+ruby -Ilib:test test/test_ruby2ruby.rb
popd
%files
@@ -99,6 +97,10 @@ popd
%{gem_docdir}
%changelog
+* Thu Jul 31 2014 Mo Morsi <mmorsi at redhat.com> - 2.1.1-1
+- Update to 2.1.1
+- fix build against rawhide (use latest pt_testcase.rb from sexp_processor)
+
* Sun Jun 08 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 2.0.6-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
More information about the scm-commits
mailing list