diff options
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 + )); + } } |
