diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 12:48:24 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 12:48:24 +0000 |
commit | dcae7af25d004b49837faf9d1715d41dd5d68225 (patch) | |
tree | 34f507f3f35722bd5a271b1436d894ef9d1fda1e /test | |
parent | 431b660873ca7440e7bf35af124175c9701daa1e (diff) | |
download | ruby-dcae7af25d004b49837faf9d1715d41dd5d68225.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')
-rw-r--r-- | test/ruby/test_iseq.rb | 41 |
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 |