aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-08-01 14:41:21 -0400
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-08-29 20:40:52 +0900
commita4a19b114ba94b8f28d5a91aee5d595a516006d5 (patch)
tree9d4bda06b2877673e598a850b19f5ec5acafefc6 /test/ruby
parente4be2fda3dbbfdb1f2ace697c96cf6bdd7dfef21 (diff)
downloadruby-a4a19b114ba94b8f28d5a91aee5d595a516006d5.tar.gz
Allow non-finalizable objects in ObjectSpace::WeakMap
[feature #16035] This goes one step farther than what nobu did in [feature #13498] With this patch, special objects such as static symbols, integers, etc can be used as either key or values inside WeakMap. They simply don't have a finalizer defined on them. This is useful if you need to deduplicate value objects
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_weakmap.rb31
1 files changed, 21 insertions, 10 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb
index 8eb32b574f..3b9eef770a 100644
--- a/test/ruby/test_weakmap.rb
+++ b/test/ruby/test_weakmap.rb
@@ -16,16 +16,27 @@ class TestWeakMap < Test::Unit::TestCase
def test_aset_const
x = Object.new
- assert_raise(ArgumentError) {@wm[true] = x}
- assert_raise(ArgumentError) {@wm[false] = x}
- assert_raise(ArgumentError) {@wm[nil] = x}
- assert_raise(ArgumentError) {@wm[42] = x}
- assert_raise(ArgumentError) {@wm[:foo] = x}
- assert_raise(ArgumentError) {@wm[x] = true}
- assert_raise(ArgumentError) {@wm[x] = false}
- assert_raise(ArgumentError) {@wm[x] = nil}
- assert_raise(ArgumentError) {@wm[x] = 42}
- assert_raise(ArgumentError) {@wm[x] = :foo}
+ @wm[true] = x
+ assert_same(x, @wm[true])
+ @wm[false] = x
+ assert_same(x, @wm[false])
+ @wm[nil] = x
+ assert_same(x, @wm[nil])
+ @wm[42] = x
+ assert_same(x, @wm[42])
+ @wm[:foo] = x
+ assert_same(x, @wm[:foo])
+
+ @wm[x] = true
+ assert_same(true, @wm[x])
+ @wm[x] = false
+ assert_same(false, @wm[x])
+ @wm[x] = nil
+ assert_same(nil, @wm[x])
+ @wm[x] = 42
+ assert_same(42, @wm[x])
+ @wm[x] = :foo
+ assert_same(:foo, @wm[x])
end
def assert_weak_include(m, k, n = 100)