aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-21 23:52:44 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-21 23:52:44 +0100
commit4f8c81e479b5e83bc301f04f01a12466f9e1edf2 (patch)
tree4e521f2b12b70e4cf8f57cf5e71a9773cebf1791 /src/test/java
parent0984cad6e314800cf1bc3fe604e1e48f0ed85ed7 (diff)
Support table imports
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java
index e77b976d..e8de81a4 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmBinaryFormatModuleTests.java
@@ -5,8 +5,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.shedlang.compiler.backends.wasm.structure.ast.WasmModule;
import org.shedlang.compiler.backends.wasm.structure.ast.imports.WasmImport;
import org.shedlang.compiler.backends.wasm.structure.ast.imports.WasmImportDescriptor;
-import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType;
-import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType;
+import org.shedlang.compiler.backends.wasm.structure.ast.types.*;
import org.shedlang.compiler.testing.ProcessRunner;
import org.shedlang.compiler.testing.snapshots.SnapshotResolver;
import org.shedlang.compiler.testing.snapshots.Snapshotter;
@@ -43,7 +42,7 @@ public class WasmBinaryFormatModuleTests {
}
@Test
- public void canSerializeModuleWithImports(Snapshotter snapshotter) throws IOException, InterruptedException {
+ public void canSerializeModuleWithFunctionImports(Snapshotter snapshotter) throws IOException, InterruptedException {
var module = WasmModule.EMPTY
.addType(new WasmFuncType(List.of(), List.of()))
.addType(new WasmFuncType(List.of(WasmValueType.I32), List.of()))
@@ -63,6 +62,31 @@ public class WasmBinaryFormatModuleTests {
snapshotter.assertSnapshot(result);
}
+ @Test
+ public void canSerializeModuleWithTableImports(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var module = WasmModule.EMPTY
+ .addImport(new WasmImport(
+ "ModuleName1",
+ "EntityName1",
+ new WasmImportDescriptor.Table(new WasmTableType(
+ WasmReferenceType.EXTERN_REF,
+ WasmLimits.min(1)
+ ))
+ ))
+ .addImport(new WasmImport(
+ "ModuleName2",
+ "EntityName2",
+ new WasmImportDescriptor.Table(new WasmTableType(
+ WasmReferenceType.FUNC_REF,
+ WasmLimits.range(2, 5)
+ ))
+ ));
+
+ var result = serializeModule(module);
+
+ snapshotter.assertSnapshot(result);
+ }
+
private String serializeModule(WasmModule module) throws IOException, InterruptedException {
Files.createDirectories(Path.of("tests-tmp"));
var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat");