From 862359008799b4038c32d909cd31808421e60739 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 28 Sep 2023 14:21:12 +0100 Subject: Store struct type instead of name in typed struct definition node --- .../compiler/ast/typed/TypedStructDefinitionNodeMatcher.java | 6 +++--- .../compiler/typechecker/TypeCheckerNamespaceTests.java | 10 ++++++---- .../compiler/typechecker/TypeCheckerStructDefinitionTests.java | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java index 489fb558..b80aff1d 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java @@ -2,10 +2,10 @@ package org.shedlang.compiler.ast.typed; import org.pcollections.PVector; import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.types.StructType; import org.shedlang.compiler.util.P; import org.zwobble.precisely.Matcher; -import static org.zwobble.precisely.Matchers.equalTo; import static org.zwobble.precisely.Matchers.has; public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< @@ -31,8 +31,8 @@ public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< return new TypedStructDefinitionNodeMatcher(submatchers); } - public TypedStructDefinitionNodeMatcher withName(String name) { - return with(has("name", x -> x.name(), equalTo(name))); + public TypedStructDefinitionNodeMatcher withType(Matcher type) { + return with(has("type", x -> x.type(), type)); } public TypedStructDefinitionNodeMatcher withFields( diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java index 226769bf..2c4f844d 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java @@ -306,7 +306,8 @@ public class TypeCheckerNamespaceTests { result.value(), isTypedNamespaceNode() .withBody(isSequence( - isTypedStructDefinitionNode().withName("User"), + isTypedStructDefinitionNode() + .withType(isStructType(NamespaceName.of("Example", "Project"), "User")), isTypedFunctionDefinitionNode() .withName("printUser") .withParams(isTypedParamsNode( @@ -356,7 +357,8 @@ public class TypeCheckerNamespaceTests { )), isSequence() )), - isTypedStructDefinitionNode().withName("User") + isTypedStructDefinitionNode() + .withType(isStructType(NamespaceName.of("Example", "Project"), "User")) )) ); } @@ -416,14 +418,14 @@ public class TypeCheckerNamespaceTests { isTypedNamespaceNode() .withBody(isSequence( isTypedStructDefinitionNode() - .withName("A") + .withType(isStructType(NamespaceName.of("Example", "Project"), "A")) .withFields(isSequence( isTypedStructFieldDefinitionNode() .withName("b") .withType(isTypedTypeLevelExpressionNode(Types.struct(namespaceName, "B"))) )), isTypedStructDefinitionNode() - .withName("B") + .withType(isStructType(NamespaceName.of("Example", "Project"), "B")) .withFields(isSequence( isTypedStructFieldDefinitionNode() .withName("a") diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java index e8628411..a0efeac3 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -14,6 +14,7 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.*; +import static org.shedlang.compiler.types.TypeMatchers.isStructType; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -45,7 +46,7 @@ public class TypeCheckerStructDefinitionTests { assertThat( typed.value(), isTypedStructDefinitionNode() - .withName("ExampleStruct") + .withType(isStructType(NAMESPACE_NAME, "ExampleStruct")) .withFields(isSequence()) ); } @@ -86,7 +87,7 @@ public class TypeCheckerStructDefinitionTests { assertThat( typed.value(), isTypedStructDefinitionNode() - .withName("ExampleStruct") + .withType(isStructType(NAMESPACE_NAME, "ExampleStruct")) .withFields(isSequence( isTypedStructFieldDefinitionNode() .withName("b") -- cgit v1.2.3