aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_iseq.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-23 12:48:24 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-23 12:48:24 +0000
commiteb8c2773cb57628c09b36243d74cb752327819a6 (patch)
tree34f507f3f35722bd5a271b1436d894ef9d1fda1e /test/ruby/test_iseq.rb
parent919fa894f5e0fed105ad1513cb8be0748ae46295 (diff)
downloadruby-eb8c2773cb57628c09b36243d74cb752327819a6.tar.gz
RubyVM::InstructionSequence#each_child.
* iseq.c (iseqw_each_child): add RubyVM::InstructionSequence#each_child method for tools which want to manipulate ISeq. * test/ruby/test_iseq.rb: add a test for this method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_iseq.rb')
-rw-r--r--test/ruby/test_iseq.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 4de2aa7169..2f23f78e23 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -280,4 +280,45 @@ class TestISeq < Test::Unit::TestCase
assert_match /:#{name}@/, ISeq.of(m).inspect, name
end
end
+
+ def test_each_child
+ iseq = ISeq.compile <<-EOS
+ class C
+ def foo
+ begin
+ rescue
+ p :rescue
+ ensure
+ p :ensure
+ end
+ end
+ def bar
+ 1.times{
+ 2.times{
+ }
+ }
+ end
+ end
+ class D < C
+ end
+ EOS
+
+ collect_iseq = lambda{|iseq|
+ iseqs = []
+ iseq.each_child{|child_iseq|
+ iseqs << collect_iseq.call(child_iseq)
+ }
+ ["#{iseq.label}@#{iseq.first_lineno}", *iseqs.sort_by{|k, *| k}]
+ }
+
+ expected = ["<compiled>@1",
+ ["<class:C>@1",
+ ["bar@10", ["block in bar@11",
+ ["block (2 levels) in bar@12"]]],
+ ["foo@2", ["ensure in foo@2"],
+ ["rescue in foo@4"]]],
+ ["<class:D>@17"]]
+
+ assert_equal expected, collect_iseq.call(iseq)
+ end
end