diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java | 45 |
1 files changed, 45 insertions, 0 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 new file mode 100644 index 0000000..7929e7d --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java @@ -0,0 +1,45 @@ +package org.zwobble.hobgoblin.compiler.typechecker; + +import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.types.NamespaceName; + +import java.util.Optional; + +import static org.zwobble.hobgoblin.compiler.typechecker.NamespaceNameResolution.resolveNamespaceName; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.equalTo; + +public class NamespaceNameResolutionTests { + @Test + public void whenAncestorDepthIsEmptyThenImportedNamespaceIsUsedAsAbsoluteName() { + var current = NamespaceName.of("a", "b"); + var importedAncestorDepth = Optional.<Integer>empty(); + var importedNamespaceName = NamespaceName.of("x", "y"); + + var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + + assertThat(result, equalTo(NamespaceName.of("x", "y"))); + } + + @Test + public void whenAncestorDepthIsZeroThenImportedNamespaceIsJoinedToCurrentNamespace() { + var current = NamespaceName.of("a", "b"); + var importedAncestorDepth = Optional.of(0); + var importedNamespaceName = NamespaceName.of("x", "y"); + + var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + + assertThat(result, equalTo(NamespaceName.of("a", "b", "x", "y"))); + } + + @Test + public void whenAncestorDepthIsGreaterThanZeroThenThatManyPartsAreStrippedOffCurrentNamespaceBeforeJoining() { + var current = NamespaceName.of("a", "b", "c"); + var importedAncestorDepth = Optional.of(2); + var importedNamespaceName = NamespaceName.of("x", "y"); + + var result = resolveNamespaceName(current, importedAncestorDepth, importedNamespaceName); + + assertThat(result, equalTo(NamespaceName.of("a", "x", "y"))); + } +} |
