aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-11 18:03:47 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-11 18:03:47 +0000
commit041d35ae5b61d3dd94bcd164b72158de2049ff18 (patch)
tree47bb69c4d678c43a316dcfdad0ff33458a4a32d9 /src/test/java/org/shedlang/compiler/stackir
parentaeb5658434d8090ec8e5cfc054ba6b13758c4da2 (diff)
Generate stack IR for effect definition
Diffstat (limited to 'src/test/java/org/shedlang/compiler/stackir')
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java
new file mode 100644
index 00000000..e167816c
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java
@@ -0,0 +1,31 @@
+package org.shedlang.compiler.stackir;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.ast.typed.Typed;
+import org.shedlang.compiler.stackir.instructions.DefineEffectInstruction;
+import org.shedlang.compiler.types.Effects;
+import org.shedlang.compiler.types.NamespaceName;
+
+import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isLocalStoreInstruction;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.*;
+
+public class StackCompilerEffectDefinitionTests {
+ @Test
+ public void effectDefinitionIsCompiledToDefineEffectInstruction() {
+ var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State");
+ var node = Typed.effectDefinition(effect);
+ var context = StackCompiler.Context.EMPTY
+ .addShedVariable("State");
+
+ var result = StackCompiler.compileNamespaceStatement(node, context);
+
+ assertThat(result.instructions(), isSequence(
+ instanceOf(
+ DefineEffectInstruction.class,
+ has("effect", x -> x.effect(), equalTo(effect))
+ ),
+ isLocalStoreInstruction("State__0")
+ ));
+ }
+}