diff options
author | Jean Boussier <[email protected]> | 2023-03-30 16:23:14 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2023-04-15 16:29:46 +0200 |
commit | 52449b5b75068872ce568ed00c4c7fb8e6c28072 (patch) | |
tree | 15c4ee12b472b863609d04344473986a79343608 /test/ruby/test_weakmap.rb | |
parent | 4dc2e5a850e6b44e715ca8fa31d21dddf5ec1491 (diff) |
Implement ObjectSpace::WeakMap#delete and ObjectSpace::WeakKeyMap#delete
[Feature #19561]
It's useful to be able to remove references from weak maps.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7629
Diffstat (limited to 'test/ruby/test_weakmap.rb')
-rw-r--r-- | test/ruby/test_weakmap.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index 7fc956dfae..f9358e11f3 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -82,6 +82,22 @@ class TestWeakMap < Test::Unit::TestCase @wm.inspect) end + def test_delete + k1 = "foo" + x1 = Object.new + @wm[k1] = x1 + assert_equal x1, @wm[k1] + assert_equal x1, @wm.delete(k1) + assert_nil @wm[k1] + assert_nil @wm.delete(k1) + + fallback = @wm.delete(k1) do |key| + assert_equal k1, key + 42 + end + assert_equal 42, fallback + end + def test_each m = __callee__[/test_(.*)/, 1] x1 = Object.new |