From c2d7621d8d379980afd0b74870588c1438418fed Mon Sep 17 00:00:00 2001 From: tenderlove Date: Fri, 6 Nov 2009 18:02:30 +0000 Subject: * ext/dl/cptr.c (rb_dlptr_inspect, rb_dlptr_plus, rb_dlptr_minus) documenting +, -, inspect * text/dl/test_cptr.rb (test_minus, test_plus, test_inspect) testing minus, plus, and inspect git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/dl/test_cptr.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/dl') diff --git a/test/dl/test_cptr.rb b/test/dl/test_cptr.rb index 3c4b5e6867..43605f84ce 100644 --- a/test/dl/test_cptr.rb +++ b/test/dl/test_cptr.rb @@ -3,6 +3,28 @@ require_relative '../ruby/envutil' module DL class TestCPtr < TestBase + def test_minus + str = "hello world" + ptr = CPtr[str] + assert_equal ptr.to_s, (ptr + 3 - 3).to_s + end + + # TODO: what if the pointer size is 0? raise an exception? do we care? + def test_plus + str = "hello world" + ptr = CPtr[str] + new_str = ptr + 3 + assert_equal 'lo world', new_str.to_s + end + + def test_inspect + ptr = CPtr.new(0) + inspect = ptr.inspect + assert_match(/size=#{ptr.size}/, inspect) + assert_match(/free=#{ptr.free}/, inspect) + assert_match(/ptr=#{ptr.to_i}/, inspect) + end + def test_to_ptr_string str = "hello world" ptr = CPtr[str] -- cgit v1.2.3