diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-13 03:37:06 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-13 03:37:06 +0000 |
commit | df058ea0e3e13ad52fd3a3490b1e3bd56db044b2 (patch) | |
tree | e9e288a7d4d13a8259245a1dedc97e2f4c107ea2 /test/test_weakref.rb | |
parent | 826cdd67a043b520c70cc9fcf66028603a130560 (diff) | |
download | ruby-df058ea0e3e13ad52fd3a3490b1e3bd56db044b2.tar.gz |
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
Diffstat (limited to 'test/test_weakref.rb')
-rw-r--r-- | test/test_weakref.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/test_weakref.rb b/test/test_weakref.rb new file mode 100644 index 0000000000..97274c1f3f --- /dev/null +++ b/test/test_weakref.rb @@ -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 |