summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-06-16 21:36:49 +0100
committerMichael Williamson <mike@zwobble.org>2026-06-16 21:36:49 +0100
commit9716e0f30b5db95b0fa7ca54908ec5fbf9f1e088 (patch)
tree2c76d7ec02180de8884c0378cb3f8261f9a46f4a /src/test/java/org
parent365d53ad8a7bf21602e37970a34b2de116a794b2 (diff)
Implement full namespace name resolution
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/NamespaceNameResolutionTests.java45
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")));
+ }
+}