summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorlukeg <luke.gru@gmail.com>2023-01-12 12:05:07 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-10-26 13:07:12 -0300
commitb57b7acc20f46b77809d9882ba3fc9169c2610ce (patch)
treee17bda5482a6ad6f24056e9dcbffa0e28edd0de3 /test/ruby
parent4f8a33eb055d5fed76851ac8194851ffb8f79b48 (diff)
add more shapes tests
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_shapes.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index 7849ca546b..dbfbb937a8 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -388,6 +388,8 @@ class TestShapes < Test::Unit::TestCase
assert_predicate RubyVM::Shape.of(tc), :too_complex?
tc.freeze
assert_raise(FrozenError) { tc.a3_m }
+ # doesn't transition to frozen shape in this case
+ assert_predicate RubyVM::Shape.of(tc), :too_complex?
end
def test_read_undefined_iv_after_complex
@@ -397,6 +399,7 @@ class TestShapes < Test::Unit::TestCase
tc.send("a#{RubyVM::Shape::SHAPE_MAX_VARIATIONS}_m")
assert_predicate RubyVM::Shape.of(tc), :too_complex?
assert_equal nil, tc.iv_not_defined
+ assert_predicate RubyVM::Shape.of(tc), :too_complex?
end
def test_shape_order
@@ -447,7 +450,10 @@ class TestShapes < Test::Unit::TestCase
class TestObject; end
def test_new_obj_has_t_object_shape
- assert_shape_equal(RubyVM::Shape.root_shape, RubyVM::Shape.of(TestObject.new).parent)
+ obj = TestObject.new
+ shape = RubyVM::Shape.of(obj)
+ assert_equal RubyVM::Shape::SHAPE_T_OBJECT, shape.type
+ assert_shape_equal(RubyVM::Shape.root_shape, shape.parent)
end
def test_str_has_root_shape
@@ -474,6 +480,10 @@ class TestShapes < Test::Unit::TestCase
assert_equal(RubyVM::Shape::SPECIAL_CONST_SHAPE_ID, RubyVM::Shape.of(nil).id)
end
+ def test_root_shape_transition_to_special_const_on_frozen
+ assert_equal(RubyVM::Shape::SPECIAL_CONST_SHAPE_ID, RubyVM::Shape.of([].freeze).id)
+ end
+
def test_basic_shape_transition
omit "Failing with RJIT for some reason" if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
obj = Example.new
@@ -487,7 +497,7 @@ class TestShapes < Test::Unit::TestCase
shape = shape.parent
assert_equal(RubyVM::Shape.root_shape.id, shape.id)
- assert_equal(obj.instance_variable_get(:@a), 1)
+ assert_equal(1, obj.instance_variable_get(:@a))
end
def test_different_objects_make_same_transition
@@ -538,6 +548,15 @@ class TestShapes < Test::Unit::TestCase
assert_shape_equal(RubyVM::Shape.of(obj), RubyVM::Shape.of(obj2))
end
+ def test_cloning_with_freeze_option
+ obj = Object.new
+ obj2 = obj.clone(freeze: true)
+ assert_predicate(obj2, :frozen?)
+ refute_shape_equal(RubyVM::Shape.of(obj), RubyVM::Shape.of(obj2))
+ assert_equal(RubyVM::Shape::SHAPE_FROZEN, RubyVM::Shape.of(obj2).type)
+ assert_shape_equal(RubyVM::Shape.of(obj), RubyVM::Shape.of(obj2).parent)
+ end
+
def test_freezing_and_cloning_object_with_ivars
obj = Example.new.freeze
obj2 = obj.clone(freeze: true)