From 4f8c81e479b5e83bc301f04f01a12466f9e1edf2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 21 Jun 2023 23:52:44 +0100 Subject: Support table imports --- .../structure/WasmBinaryFormatModuleTests.java | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/test/java') 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"); -- cgit v1.2.3