Skip to content

Commit 22c2edb

Browse files
committed
Ignore cached type ids in tests.
1 parent c3cd29d commit 22c2edb

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

interpreter/runtimetype_test.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ import (
2727
. "github.com/onflow/cadence/test_utils/common_utils"
2828

2929
"github.com/stretchr/testify/assert"
30+
"github.com/stretchr/testify/require"
3031
)
3132

33+
// assertTypeValuesEqual compares two TypeValues using their Equal method,
34+
// which properly ignores cache fields like cachedID
35+
func assertTypeValuesEqual(t *testing.T, expected, actual interpreter.Value) {
36+
expectedTypeValue, ok := expected.(interpreter.TypeValue)
37+
require.True(t, ok, "expected value is not a TypeValue")
38+
39+
require.True(t,
40+
expectedTypeValue.Equal(nil, actual),
41+
"TypeValues are not equal: expected %v, got %v",
42+
expected, actual,
43+
)
44+
}
45+
3246
func TestInterpretOptionalType(t *testing.T) {
3347

3448
t.Parallel()
@@ -44,7 +58,7 @@ func TestInterpretOptionalType(t *testing.T) {
4458
let e = Type<String?>()
4559
`)
4660

47-
assert.Equal(t,
61+
assertTypeValuesEqual(t,
4862
interpreter.TypeValue{
4963
Type: &interpreter.OptionalStaticType{
5064
Type: interpreter.PrimitiveStaticTypeString,
@@ -53,7 +67,7 @@ func TestInterpretOptionalType(t *testing.T) {
5367
inter.GetGlobal("a"),
5468
)
5569

56-
assert.Equal(t,
70+
assertTypeValuesEqual(t,
5771
interpreter.TypeValue{
5872
Type: &interpreter.OptionalStaticType{
5973
Type: interpreter.PrimitiveStaticTypeInt,
@@ -62,7 +76,7 @@ func TestInterpretOptionalType(t *testing.T) {
6276
inter.GetGlobal("b"),
6377
)
6478

65-
assert.Equal(t,
79+
assertTypeValuesEqual(t,
6680
interpreter.TypeValue{
6781
Type: &interpreter.OptionalStaticType{
6882
Type: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"),
@@ -71,7 +85,7 @@ func TestInterpretOptionalType(t *testing.T) {
7185
inter.GetGlobal("c"),
7286
)
7387

74-
assert.Equal(t,
88+
assertTypeValuesEqual(t,
7589
interpreter.TypeValue{
7690
Type: &interpreter.OptionalStaticType{
7791
Type: &interpreter.OptionalStaticType{
@@ -82,7 +96,7 @@ func TestInterpretOptionalType(t *testing.T) {
8296
inter.GetGlobal("d"),
8397
)
8498

85-
assert.Equal(t,
99+
assertTypeValuesEqual(t,
86100
inter.GetGlobal("a"),
87101
inter.GetGlobal("e"),
88102
)
@@ -438,7 +452,7 @@ func TestInterpretReferenceType(t *testing.T) {
438452
let f = ReferenceType(entitlements: ["X"], type: Type<@R>())
439453
`)
440454

441-
assert.Equal(t,
455+
assertTypeValuesEqual(t,
442456
interpreter.TypeValue{
443457
Type: &interpreter.ReferenceStaticType{
444458
ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "R"),
@@ -453,7 +467,7 @@ func TestInterpretReferenceType(t *testing.T) {
453467
inter.GetGlobal("a"),
454468
)
455469

456-
assert.Equal(t,
470+
assertTypeValuesEqual(t,
457471
interpreter.TypeValue{
458472
Type: &interpreter.ReferenceStaticType{
459473
ReferencedType: interpreter.PrimitiveStaticTypeString,
@@ -463,7 +477,7 @@ func TestInterpretReferenceType(t *testing.T) {
463477
inter.GetGlobal("b"),
464478
)
465479

466-
assert.Equal(t,
480+
assertTypeValuesEqual(t,
467481
interpreter.TypeValue{
468482
Type: &interpreter.ReferenceStaticType{
469483
ReferencedType: interpreter.NewCompositeStaticTypeComputeTypeID(nil, TestLocation, "S"),
@@ -478,7 +492,7 @@ func TestInterpretReferenceType(t *testing.T) {
478492
inter.GetGlobal("c"),
479493
)
480494

481-
assert.Equal(t,
495+
assertTypeValuesEqual(t,
482496
inter.GetGlobal("a"),
483497
inter.GetGlobal("d"),
484498
)
@@ -522,7 +536,7 @@ func TestInterpretIntersectionType(t *testing.T) {
522536
let k = IntersectionType(types: ["S.test.S", "S.test.S2"])!
523537
`)
524538

525-
assert.Equal(t,
539+
assertTypeValuesEqual(t,
526540
interpreter.TypeValue{
527541
Type: &interpreter.IntersectionStaticType{
528542
Types: []*interpreter.InterfaceStaticType{
@@ -538,7 +552,7 @@ func TestInterpretIntersectionType(t *testing.T) {
538552
inter.GetGlobal("c"),
539553
)
540554

541-
assert.Equal(t,
555+
assertTypeValuesEqual(t,
542556
interpreter.TypeValue{
543557
Type: &interpreter.IntersectionStaticType{
544558
Types: []*interpreter.InterfaceStaticType{
@@ -554,7 +568,7 @@ func TestInterpretIntersectionType(t *testing.T) {
554568
inter.GetGlobal("j"),
555569
)
556570

557-
assert.Equal(t,
571+
assertTypeValuesEqual(t,
558572
interpreter.TypeValue{
559573
Type: &interpreter.IntersectionStaticType{
560574
Types: []*interpreter.InterfaceStaticType{
@@ -571,12 +585,12 @@ func TestInterpretIntersectionType(t *testing.T) {
571585
inter.GetGlobal("f"),
572586
)
573587

574-
assert.Equal(t,
588+
assertTypeValuesEqual(t,
575589
inter.GetGlobal("a"),
576590
inter.GetGlobal("h"),
577591
)
578592

579-
assert.Equal(t,
593+
assertTypeValuesEqual(t,
580594
inter.GetGlobal("b"),
581595
inter.GetGlobal("i"),
582596
)
@@ -597,7 +611,7 @@ func TestInterpretCapabilityType(t *testing.T) {
597611
let e = Type<Capability<&String>>()
598612
`)
599613

600-
assert.Equal(t,
614+
assertTypeValuesEqual(t,
601615
interpreter.TypeValue{
602616
Type: &interpreter.CapabilityStaticType{
603617
BorrowType: &interpreter.ReferenceStaticType{
@@ -609,7 +623,7 @@ func TestInterpretCapabilityType(t *testing.T) {
609623
inter.GetGlobal("a"),
610624
)
611625

612-
assert.Equal(t,
626+
assertTypeValuesEqual(t,
613627
interpreter.TypeValue{
614628
Type: &interpreter.CapabilityStaticType{
615629
BorrowType: &interpreter.ReferenceStaticType{
@@ -621,7 +635,7 @@ func TestInterpretCapabilityType(t *testing.T) {
621635
inter.GetGlobal("b"),
622636
)
623637

624-
assert.Equal(t,
638+
assertTypeValuesEqual(t,
625639
interpreter.TypeValue{
626640
Type: &interpreter.CapabilityStaticType{
627641
BorrowType: &interpreter.ReferenceStaticType{

0 commit comments

Comments
 (0)