diff options
Diffstat (limited to 'test/ruby/test_objectspace.rb')
| -rw-r--r-- | test/ruby/test_objectspace.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb index 14d44f0b39..571c725986 100644 --- a/test/ruby/test_objectspace.rb +++ b/test/ruby/test_objectspace.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestObjectSpace < Test::Unit::TestCase def self.deftest_id2ref(obj) @@ -8,7 +9,7 @@ class TestObjectSpace < Test::Unit::TestCase code = <<"End" define_method("test_id2ref_#{line}") {\ o = ObjectSpace._id2ref(obj.object_id);\ - assert_equal(obj, o, "didn't round trip: \#{obj.inspect}");\ + assert_same(obj, o, "didn't round trip: \#{obj.inspect}");\ } End eval code, binding, file, line @@ -33,4 +34,34 @@ End deftest_id2ref(true) deftest_id2ref(false) deftest_id2ref(nil) + + def test_count_objects + h = {} + ObjectSpace.count_objects(h) + assert_kind_of(Hash, h) + assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) + assert(h.values.all? {|x| x.is_a?(Integer) }) + + h = ObjectSpace.count_objects + assert_kind_of(Hash, h) + assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) + assert(h.values.all? {|x| x.is_a?(Integer) }) + + assert_raise(TypeError) { ObjectSpace.count_objects(1) } + + h0 = {:T_FOO=>1000} + h = ObjectSpace.count_objects(h0) + assert_same(h0, h) + assert_equal(0, h0[:T_FOO]) + end + + def test_finalizer + assert_in_out_err(["-e", <<-END], "", %w(:ok :ok :ok :ok), []) + a = [] + ObjectSpace.define_finalizer(a) { p :ok } + b = a.dup + ObjectSpace.define_finalizer(a) { p :ok } + END + assert_raise(ArgumentError) { ObjectSpace.define_finalizer([], Object.new) } + end end |
