From 4ea7fb648b0c6f95e6383c34912aad411a43cdbf Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 24 Jun 2023 19:45:54 +0100 Subject: WASM binary format: support tables --- .../structure/WasmBinaryFormatModuleTests.java | 24 +++++++++++++++++++--- 1 file changed, 21 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 8f197b2a..8083a36a 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 @@ -2,9 +2,10 @@ package org.shedlang.compiler.backends.wasm.structure; import org.junit.jupiter.api.Test; 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.modules.WasmModule; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImport; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmImportDescriptor; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmTable; import org.shedlang.compiler.backends.wasm.structure.ast.types.*; import org.shedlang.compiler.testing.ProcessRunner; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; @@ -128,6 +129,23 @@ public class WasmBinaryFormatModuleTests { snapshotter.assertSnapshot(result); } + @Test + public void canSerializeModuleWithTables(Snapshotter snapshotter) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addTable(new WasmTable(new WasmTableType( + WasmReferenceType.FUNC_REF, + WasmLimits.min(1) + ))) + .addTable(new WasmTable(new WasmTableType( + WasmReferenceType.EXTERN_REF, + WasmLimits.range(2, 3) + ))); + + 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