Sha256: eb7429709bba7b05ff9a50dfea37814ec95a7fa4815495a1818e733edde976b5
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
require 'test/unit' require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION def outside(a) return eval('a', RubyVM::Frame.new(Thread::current).binding) end $a = 10 class TestBinding < Test::Unit::TestCase def test_basic a = 1 c = 0 assert_equal(5, outside(5)) tf = RubyVM::Frame.new(Thread::current) b = tf.binding assert_equal(1, eval('a', b)) assert_equal(10, eval('$a', b)) assert_equal(self, tf.self) 1.times do |i;a| tf2 = Thread::current.frame() b2 = tf2.binding a = 2 assert_equal(2, eval('a', b2)) assert_equal(0, eval('c', b2)) # Times is C inline so prev we can't get a binding for it # But we can for use the instruction sequence before that. assert_equal(1, eval('a', tf2.prev(2).binding)) end def inner(a) tf3 = Thread::current.frame() b3 = tf3.binding if a == 4 assert_equal(4, eval('a', b3)) inner(a-1) else assert_equal(3, eval('a', b3)) assert_equal(4, eval('a', tf3.prev.binding)) end end inner(4) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rb-threadframe-0.41 | test/unit/test-binding.rb |
rb-threadframe-0.40 | test/unit/test-binding.rb |