Skip to content

Commit

Permalink
Add a test for transition order
Browse files Browse the repository at this point in the history
We only cache the destination shape id, but that can lead to false cache
hits.  This patch tests that we correctly handle false cache hits
  • Loading branch information
tenderlove committed Oct 14, 2022
1 parent 9a5684b commit cbd3d65
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/ruby/test_shapes.rb
Expand Up @@ -3,6 +3,20 @@

# These test the functionality of object shapes
class TestShapes < Test::Unit::TestCase
class ShapeOrder
def initialize
@b = :b # 5 => 6
end

def set_b
@b = :b # 5 => 6
end

def set_c
@c = :c # 5 => 7
end
end

class Example
def initialize
@a = 1
Expand Down Expand Up @@ -37,6 +51,17 @@ def refute_shape_equal(shape1, shape2)
refute_equal(shape1.id, shape2.id)
end

def test_shape_order
bar = ShapeOrder.new # 0 => 1
bar.set_c # 1 => 2
bar.set_b # 2 => 2

foo = ShapeOrder.new # 0 => 1
shape_id = RubyVM::Shape.of(foo).id
foo.set_b # should not transition
assert_equal shape_id, RubyVM::Shape.of(foo).id
end

def test_iv_index
example = RemoveAndAdd.new
shape = RubyVM::Shape.of(example)
Expand Down

0 comments on commit cbd3d65

Please sign in to comment.