aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-02 23:07:44 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-02 23:07:44 +0000
commitc9ffb931adc50091fd86ea9d09c423ab16020416 (patch)
tree88f7d0b258ff083293e0fb292765252c5676a3f8 /src/test/java
parent298700108a286fa7154e4a638017c9fbebf5c3ff (diff)
Add typed unit node
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/ast/typed/Typed.java4
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java22
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
index 09e7f080..31586620 100644
--- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
+++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
@@ -249,6 +249,10 @@ public class Typed {
return new TypedTypeLevelReferenceNode<>(name, value, Sources.NULL);
}
+ public static TypedUnitLiteralNode unitLiteral() {
+ return new TypedUnitLiteralNode(Sources.NULL);
+ }
+
public static TypedAssignNode val(
String targetName,
TypedExpressionNode expression
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java
new file mode 100644
index 00000000..024b9561
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java
@@ -0,0 +1,22 @@
+package org.shedlang.compiler.stackir;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.ast.typed.Typed;
+
+import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushUnitInstruction;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class StackCompilerUnitLiteralTests {
+ @Test
+ public void unitLiteralIsCompiledToPushUnitInstruction() {
+ var node = Typed.unitLiteral();
+ var context = StackCompiler.Context.EMPTY;
+
+ var result = StackCompiler.compileExpression(node, context);
+
+ assertThat(result.instructions(), isSequence(
+ isPushUnitInstruction()
+ ));
+ }
+}