aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_weakref.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_weakref.rb')
-rw-r--r--test/test_weakref.rb22
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