diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 12:07:09 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 12:07:09 +0100 |
| commit | fccc76e339651d6451bb8fc7394f21eed96e3318 (patch) | |
| tree | 64353f2cfa78b8a7bc858a63b43a915f42e758f4 /src/test/java | |
| parent | 2f8e32636912e23552f5b43a2c84109b77fe7a92 (diff) | |
Check for namespace name when defining struct
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java index 325f7ea7..818c026f 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -5,12 +5,14 @@ import org.shedlang.compiler.ast.typed.TypedNamespaceStatementNode; import org.shedlang.compiler.ast.untyped.Untyped; import org.shedlang.compiler.ast.untyped.UntypedNamespaceStatementNode; import org.shedlang.compiler.ast.untyped.UntypedStructDefinitionNode; +import org.shedlang.compiler.typechecker.errors.CannotDefineStructOutsideOfNamespace; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; import org.shedlang.compiler.util.P; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -19,6 +21,19 @@ public class TypeCheckerStructDefinitionTests { private static final NamespaceName NAMESPACE_NAME = NamespaceName.of("Example"); @Test + public void whenOutsideOfNamespaceThenErrorIsThrown() { + var untyped = UntypedStructDefinitionNode.builder() + .withName("ExampleStruct") + .build(); + var context = TypeCheckerContext.EMPTY; + + assertThrows( + CannotDefineStructOutsideOfNamespace.class, + () -> TypeChecker.typeCheckNamespaceStatement(untyped).typeCheckAllPhases(context) + ); + } + + @Test public void canTypeCheckStructDefinitionWithNoFields() { var untyped = UntypedStructDefinitionNode.builder() .withName("ExampleStruct") |
