summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-01-21 09:45:11 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2021-02-04 09:53:31 -0800
commit3a888398a661d7dc3cbcc21b8983809905b07adb (patch)
treeb9db76eaed412f47f7028dd1e85edd4f8b785ceb /test/objspace
parent365326a09e55cacbf6677105db12aa79de9c4404 (diff)
objspace_dump.c: tag singleton classes and reference the superclass
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4104
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 6b956e6d14..841a1e7c2a 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -299,6 +299,21 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal('{"type":"SYMBOL", "value":"foo"}', ObjectSpace.dump(:foo))
end
+ def test_dump_singleton_class
+ assert_include(ObjectSpace.dump(Object), '"name":"Object"')
+ assert_include(ObjectSpace.dump(Kernel), '"name":"Kernel"')
+ assert_include(ObjectSpace.dump(Object.new.singleton_class), '"real_class_name":"Object"')
+
+ singleton = Object.new.singleton_class
+ singleton_dump = ObjectSpace.dump(singleton)
+ assert_include(singleton_dump, '"singleton":true')
+ if defined?(JSON)
+ assert_equal(Object, singleton.superclass)
+ superclass_address = JSON.parse(ObjectSpace.dump(Object)).fetch('address')
+ assert_equal(superclass_address, JSON.parse(singleton_dump).fetch('superclass'))
+ end
+ end
+
def test_dump_special_floats
assert_match(/"value":"NaN"/, ObjectSpace.dump(Float::NAN))
assert_match(/"value":"Inf"/, ObjectSpace.dump(Float::INFINITY))