Sha256: 0c6e49b5a4535e3c1de4b7dbe7ae5a659cefddc5e46f9f2216e2bfc75c44f5b4

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require 'test/unit'

require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION

# Test accessing and settign RubyVM::Frame stack data
class TestSpSize < Test::Unit::TestCase

  def sizes
    tf = RubyVM::Frame::current
    ary = []
    0.upto(2) do |i|
      ary << tf.sp_size
      tf = tf.prev
    end
    # Swap first two items. The item that generally 
    # will vary is the a[0].
    ary[0], ary[1] = ary[1], ary[0]
    # p ary
    return ary
  end

  def f0; return sizes end
  def f1; a=1; return sizes end
  def f1a(a) return sizes end
  def f2(a,b) return sizes end

  def test_sp_size
    f0_s   = f0
    f1_s   = f1
    f1a_s  = f1a(1)
    f2_s   = f2(1,2)
    assert_equal(f0_s[0]+1,   f1_s[0])
    assert_equal(f0_s[1..-1], f1_s[1..-1])
    assert_equal(f1_s, f1a_s)
    assert_equal(f1_s[0]+1,   f2_s[0])
    assert_equal(f1_s[1..-1], f2_s[1..-1])

    assert_raises ArgumentError do 
      tf = RubyVM::Frame.current
      tf.sp_set(tf.sp_size, "Should not be able to set this.")
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rb-threadframe-0.41 test/unit/test-sp-size.rb
rb-threadframe-0.40 test/unit/test-sp-size.rb