summaryrefslogtreecommitdiff
path: root/test/ruby/test_weakmap.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_weakmap.rb')
-rw-r--r--test/ruby/test_weakmap.rb34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb
index a2904776bc..2f5c747339 100644
--- a/test/ruby/test_weakmap.rb
+++ b/test/ruby/test_weakmap.rb
@@ -39,6 +39,13 @@ class TestWeakMap < Test::Unit::TestCase
assert_same(:foo, @wm[x])
end
+ def test_aset_returns_value
+ key = Object.new
+ value = Object.new
+
+ assert_same(value, @wm.send(:[]=, key, value))
+ end
+
def assert_weak_include(m, k, n = 100)
if n > 0
return assert_weak_include(m, k, n-1)
@@ -203,7 +210,7 @@ class TestWeakMap < Test::Unit::TestCase
@wm[i] = obj
end
- assert_separately([], <<-'end;')
+ assert_ruby_status([], <<-'end;')
wm = ObjectSpace::WeakMap.new
obj = Object.new
100.times do
@@ -224,7 +231,7 @@ class TestWeakMap < Test::Unit::TestCase
assert_equal(val, wm[key])
end;
- assert_separately(["-W0"], <<-'end;')
+ assert_ruby_status(["-W0"], <<-'end;')
wm = ObjectSpace::WeakMap.new
ary = 10_000.times.map do
@@ -265,4 +272,27 @@ class TestWeakMap < Test::Unit::TestCase
10_000.times { weakmap[Object.new] = Object.new }
RUBY
end
+
+ def test_generational_gc
+ EnvUtil.without_gc do
+ wmap = ObjectSpace::WeakMap.new
+
+ (GC::INTERNAL_CONSTANTS[:RVALUE_OLD_AGE] - 1).times { GC.start }
+
+ retain = []
+ 50.times do
+ k = Object.new
+ wmap[k] = true
+ retain << k
+ end
+
+ GC.start # WeakMap promoted, other objects still young
+
+ retain.clear
+
+ GC.start(full_mark: false)
+
+ wmap.keys.each(&:itself) # call method on keys to cause crash
+ end
+ end
end