aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-01-12 22:10:24 +0000
committerMichael Williamson <mike@zwobble.org>2025-01-12 22:10:24 +0000
commit519f9c3b940f4dbdde6ecf7861db9102ed43b8eb (patch)
tree8b8ef6ed239129b0df27eb2ea853f141960670a5 /src/test/java
parent56886a8b005bfe6f89b0d8eae59a542ca011149a (diff)
Compile native function declarations into Shid
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java
new file mode 100644
index 00000000..90304a57
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java
@@ -0,0 +1,30 @@
+package org.shedlang.compiler.shid;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.ast.typed.TypedNativeFunctionDeclarationNode;
+import org.shedlang.compiler.shid.instructions.ShidDeclareNativeFunction;
+
+import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalStore;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.*;
+
+public class ShidCodeGenNativeFunctionDeclarationTests {
+ @Test
+ public void nativeFunctionIsCompiledToDeclareNativeFunctionInstruction() {
+ var node = TypedNativeFunctionDeclarationNode.builder()
+ .withName("f")
+ .build();
+ var context = ShidCodeGen.Context.EMPTY
+ .addShedVal("f");
+
+ var result = ShidCodeGen.compileNamespaceStatement(node, context);
+
+ assertThat(result.instructions(), isSequence(
+ instanceOf(
+ ShidDeclareNativeFunction.class,
+ has("name", x -> x.name(), equalTo("f"))
+ ),
+ isShidLocalStore("f__0")
+ ));
+ }
+}