diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-06-19 17:34:46 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-06-19 17:34:46 +0100 |
| commit | f818776dba8bda2bf6e423da991190f3f4b4ff3f (patch) | |
| tree | 8a226b6ec4ca4b67e625d82310f677ca48771c28 /src/test/java | |
| parent | a31c0145beb998c9f83d61770ba03f9230610c87 (diff) | |
Handle relative import with invalid ancestor depth
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java index 7929e7d..da0eb90 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java @@ -1,10 +1,12 @@ package org.zwobble.hobgoblin.compiler.typechecker; import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.types.NamespaceName; import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zwobble.hobgoblin.compiler.typechecker.NamespaceNameResolution.resolveNamespaceName; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.equalTo; @@ -16,7 +18,12 @@ public class NamespaceNameResolutionTests { var importedAncestorDepth = Optional.<Integer>empty(); var importedNamespaceName = NamespaceName.of("x", "y"); - var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + var result = resolveNamespaceName( + current, + importedAncestorDepth, + importedNamespaceName, + NullSource.INSTANCE + ); assertThat(result, equalTo(NamespaceName.of("x", "y"))); } @@ -27,7 +34,12 @@ public class NamespaceNameResolutionTests { var importedAncestorDepth = Optional.of(0); var importedNamespaceName = NamespaceName.of("x", "y"); - var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + var result = resolveNamespaceName( + current, + importedAncestorDepth, + importedNamespaceName, + NullSource.INSTANCE + ); assertThat(result, equalTo(NamespaceName.of("a", "b", "x", "y"))); } @@ -38,8 +50,27 @@ public class NamespaceNameResolutionTests { var importedAncestorDepth = Optional.of(2); var importedNamespaceName = NamespaceName.of("x", "y"); - var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + var result = resolveNamespaceName( + current, + importedAncestorDepth, + importedNamespaceName, + NullSource.INSTANCE + ); assertThat(result, equalTo(NamespaceName.of("a", "x", "y"))); } + + @Test + public void whenAncestorDepthIsGreaterThanPartsThenErrorIsThrown() { + var current = NamespaceName.of("a", "b", "c"); + var importedAncestorDepth = Optional.of(4); + var importedNamespaceName = NamespaceName.of("x", "y"); + + assertThrows(RootNamespaceHasNoParentError.class, () -> resolveNamespaceName( + current, + importedAncestorDepth, + importedNamespaceName, + NullSource.INSTANCE + )); + } } |
