[前][次][番号順一覧][スレッド一覧]

ruby-changes:36456

From: nobu <ko1@a...>
Date: Sat, 22 Nov 2014 16:10:42 +0900 (JST)
Subject: [ruby-changes:36456] nobu:r48537 (trunk): dummyparser.rb: on_rescue

nobu	2014-11-22 16:10:31 +0900 (Sat, 22 Nov 2014)

  New Revision: 48537

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48537

  Log:
    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.

  Modified files:
    trunk/test/ripper/dummyparser.rb
    trunk/test/ripper/test_parser_events.rb
Index: test/ripper/test_parser_events.rb
===================================================================
--- test/ripper/test_parser_events.rb	(revision 48536)
+++ test/ripper/test_parser_events.rb	(revision 48537)
@@ -842,6 +842,14 @@ class TestRipper::ParserEvents < Test::U https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L842
     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}
Index: test/ripper/dummyparser.rb
===================================================================
--- test/ripper/dummyparser.rb	(revision 48536)
+++ test/ripper/dummyparser.rb	(revision 48537)
@@ -26,8 +26,8 @@ class Node https://github.com/ruby/ruby/blob/trunk/test/ripper/dummyparser.rb#L26
 end
 
 class NodeList
-  def initialize
-    @list = []
+  def initialize(list = [])
+    @list = list
   end
 
   attr_reader :list
@@ -208,6 +208,10 @@ class DummyParser < Ripper https://github.com/ruby/ruby/blob/trunk/test/ripper/dummyparser.rb#L208
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]