From b70f537b17bd0aa5a06635b5c34e79613e5e5ce9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 27 Sep 2026 10:40:47 +0100 Subject: Throw appropriate error on recognised namespace statement --- .../hobgoblin/compiler/parser/ParserNamespaceTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNamespaceTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNamespaceTests.java index ada6414..f749767 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNamespaceTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNamespaceTests.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode; import org.zwobble.hobgoblin.compiler.types.NamespaceName; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedImportNodeMatcher.isUntypedImportNode; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceNodeMatcher.isUntypedNamespaceNode; import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString; @@ -95,4 +96,20 @@ public class ParserNamespaceTests { )) ); } + + @Test + public void whenNamespaceStatementIsNotRecognisedThenErrorIsThrown() { + var source = "blah"; + + var error = assertThrows( + UnexpectedTokenError.class, + () -> parseString( + source, + tokens -> Parser.parseNamespace(tokens, NamespaceName.of("Example", "Project")) + ) + ); + + assertThat(error.getExpected(), equalTo("namespace statement")); + assertThat(error.getActual().charSequence().toString(), equalTo("blah")); + } } -- cgit v1.2.3