test/pt_testcase.rb in ParseTree-1.7.0 vs test/pt_testcase.rb in ParseTree-1.7.1
- old
+ new
@@ -122,10 +122,19 @@
"begin" => {
"Ruby" => "begin\n (1 + 1)\nend",
"ParseTree" => [:begin, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
},
+ "begin_rescue_ensure" => {
+ "Ruby" => "begin\n rescue\n # do nothing\n ensure\n nil\nend",
+ "ParseTree" => [:begin,
+ [:ensure,
+ [:rescue,
+ [:resbody, nil]],
+ [:nil]]]
+ },
+
"block_pass" => {
"Ruby" => "a(&b)",
"ParseTree" => [:block_pass, [:vcall, :b], [:fcall, :a]],
},
@@ -150,10 +159,23 @@
[:block_pass,
[:lvar, :block],
[:fcall, :other, [:splat, [:lvar, :args]]]]]]],
},
+ "block_pass_args_and_splat" => {
+ "Ruby" => "def blah(*args, &block)\n other(42, *args, &block)\nend",
+ "ParseTree" => [:defn, :blah,
+ [:scope,
+ [:block,
+ [:args, "*args".intern],
+ [:block_arg, :block],
+ [:block_pass,
+ [:lvar, :block],
+ [:fcall, :other,
+ [:argscat, [:array, [:lit, 42]], [:lvar, :args]]]]]]],
+ },
+
"bmethod" => {
"Ruby" => [Examples, :unsplatted],
"ParseTree" => [:defn,
:unsplatted,
[:bmethod,
@@ -166,11 +188,10 @@
"Ruby" => [Examples, :splatted],
"ParseTree" => [:defn, :splatted,
[:bmethod,
[:masgn, [:dasgn_curr, :args]],
[:block,
- [:dasgn_curr, :y],
[:dasgn_curr, :y, [:call, [:dvar, :args], :first]],
[:call, [:dvar, :y], :+, [:array, [:lit, 42]]]]]],
"Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend",
},
@@ -402,11 +423,10 @@
"Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
"ParseTree" => [:iter,
[:call, [:vcall, :data], :each],
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
[:block,
- [:dasgn_curr, :a, [:dasgn_curr, :b]],
[:dasgn_curr, :a, [:lit, 1]],
[:dasgn_curr, :b, [:dvar, :a]],
[:dasgn_curr, :b, [:dasgn_curr, :a, [:dvar, :x]]]]],
},
@@ -451,16 +471,21 @@
"Ruby" => "def |(o)\n # do nothing\nend",
"ParseTree" => [:defn, :|, [:scope, [:block, [:args, :o], [:nil]]]],
},
"defn_rescue" => {
- "Ruby" => "def blah\n 42\n rescue\n 24\nend",
- "ParseTree" => [:defn, :blah,
- [:scope, [:block, [:args],
- [:rescue,
- [:lit, 42],
- [:resbody, nil, [:lit, 24]]]]]],
+ "Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend",
+ "ParseTree" => [:defn, :eql?,
+ [:scope,
+ [:block,
+ [:args, :resource],
+ [:rescue,
+ [:call,
+ [:call, [:self], :uuid],
+ :==,
+ [:array, [:call, [:lvar, :resource], :uuid]]],
+ [:resbody, nil, [:false]]]]]],
},
"defn_zarray" => { # tests memory allocation for returns
"Ruby" => "def zarray\n a = []\n return a\nend",
"ParseTree" => [:defn, :zarray,
@@ -934,21 +959,24 @@
"Ruby" => "blah rescue nil",
"ParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]],
},
"rescue_block_body" => {
- "Ruby" => "begin\n blah\nrescue\n nil\nend\n",
- "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]]],
+ "Ruby" => "begin\n blah\nrescue\n 42\nend",
+ "ParseTree" => [:begin,
+ [:rescue,
+ [:vcall, :blah],
+ [:resbody, nil, [:lit, 42]]]],
},
"rescue_block_nada" => {
- "Ruby" => "begin\n blah\nrescue\n # do nothing\nend\n",
+ "Ruby" => "begin\n blah\nrescue\n # do nothing\nend",
"ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil]]]
},
"rescue_exceptions" => {
- "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend\n",
+ "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend",
"ParseTree" => [:begin,
[:rescue,
[:vcall, :blah],
[:resbody,
[:array, [:const, :RuntimeError]],
@@ -1176,10 +1204,12 @@
_, expected, extra_expected = *expected if Array === expected and expected.first == :defx
_, input, extra_input = *input if Array === input and input.first == :defx
debug = input.deep_clone
+ $-w = nil if node == "match"
assert_equal expected, processor.process(input), "failed on input: #{debug.inspect}"
+ $-w = true if node == "match"
extra_input.each do |input| processor.process(input) end
extra = processor.extra_methods rescue []
assert_equal extra_expected, extra
end
end