1 assert('ObjectSpace.count_objects') do
3 f = Fiber.new {} if Object.const_defined?(:Fiber)
4 ObjectSpace.count_objects(h)
5 assert_kind_of(Hash, h)
6 assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
7 assert_true(h.values.all? {|x| x.is_a?(Integer) })
9 assert_true(h.has_key?(:TOTAL))
10 assert_true(h.has_key?(:FREE))
11 assert_true(h.has_key?(:T_FIBER)) if Object.const_defined? :Fiber
13 assert_equal(h[:TOTAL] * 2, h.values.reduce(:+))
15 h = ObjectSpace.count_objects
16 assert_kind_of(Hash, h)
17 assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
18 assert_true(h.values.all? {|x| x.is_a?(Integer) })
20 assert_raise(TypeError) { ObjectSpace.count_objects(1) }
23 h = ObjectSpace.count_objects(h0)
24 assert_false(h0.has_key?(:T_FOO))
28 h_before = ObjectSpace.count_objects
34 ObjectSpace.count_objects(h)
37 ObjectSpace.count_objects(h_after)
39 assert_equal(h[:T_HASH], h_before[:T_HASH] + 1000)
40 assert_equal(h_after[:T_HASH], h_before[:T_HASH])
43 assert('ObjectSpace.each_object') do
45 objs_count = ObjectSpace.each_object { |obj|
48 assert_equal objs.length, objs_count
51 arys_count = ObjectSpace.each_object(Array) { |obj|
54 assert_equal arys.length, arys_count
55 assert_true arys.length < objs.length
58 assert 'Check class pointer of ObjectSpace.each_object.' do
59 ObjectSpace.each_object { |obj| !obj }