зеркало из https://github.com/github/ruby.git
dummyparser.rb: on_rescue
* test/ripper/dummyparser.rb (on_rescue): add to turn exception class list into NodeList, to test exception class list. * test/ripper/test_parser_events.rb (test_rescue_class): add missing test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d551e813ca
Коммит
f5063b7ea7
|
@ -26,8 +26,8 @@ class Node
|
|||
end
|
||||
|
||||
class NodeList
|
||||
def initialize
|
||||
@list = []
|
||||
def initialize(list = [])
|
||||
@list = list
|
||||
end
|
||||
|
||||
attr_reader :list
|
||||
|
@ -208,6 +208,10 @@ class DummyParser < Ripper
|
|||
words.push word
|
||||
end
|
||||
|
||||
def on_rescue(exc, *rest)
|
||||
Node.new('rescue', (exc && NodeList.new(exc)), *rest)
|
||||
end
|
||||
|
||||
(Ripper::PARSER_EVENTS.map(&:to_s) - instance_methods(false).map {|n|n.to_s.sub(/^on_/, '')}).each do |event|
|
||||
define_method(:"on_#{event}") do |*args|
|
||||
Node.new(event, *args)
|
||||
|
|
|
@ -842,6 +842,14 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
|
|||
assert_match(/rescue\(,var_field\(e\),\[2\]\)/, parsed)
|
||||
end
|
||||
|
||||
def test_rescue_class
|
||||
thru_rescue = false
|
||||
parsed = parse('begin; 1; rescue RuntimeError => e; 2; end', :on_rescue) {thru_rescue = true}
|
||||
assert_equal true, thru_rescue
|
||||
assert_match(/1.*rescue/, parsed)
|
||||
assert_match(/rescue\(\[ref\(RuntimeError\)\],var_field\(e\),\[2\]\)/, parsed)
|
||||
end
|
||||
|
||||
def test_rescue_mod
|
||||
thru_rescue_mod = false
|
||||
parsed = parse('1 rescue 2', :on_rescue_mod) {thru_rescue_mod = true}
|
||||
|
|
Загрузка…
Ссылка в новой задаче