mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Bug #5350
* gc.c: add ObjectSpace::WeakMap. [ruby-dev:44565][Bug #5350] * lib/weakref.rb: use WeakMap instead of _id2ref. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
826cdd67a0
commit
df058ea0e3
4 changed files with 249 additions and 46 deletions
22
test/test_weakref.rb
Normal file
22
test/test_weakref.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'test/unit'
|
||||
require 'weakref'
|
||||
|
||||
class TestWeakRef < Test::Unit::TestCase
|
||||
def make_weakref
|
||||
obj = Object.new
|
||||
return WeakRef.new(obj), obj.to_s
|
||||
end
|
||||
|
||||
def test_ref
|
||||
weak, str = make_weakref
|
||||
assert_equal(str, weak.to_s)
|
||||
end
|
||||
|
||||
def test_recycled
|
||||
weak, str = make_weakref
|
||||
assert_nothing_raised(WeakRef::RefError) {weak.to_s}
|
||||
ObjectSpace.garbage_collect
|
||||
ObjectSpace.garbage_collect
|
||||
assert_raise(WeakRef::RefError) {weak.to_s}
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue