From 1c085ab26815a2f61ae822f54925090f836a04e4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 25 Jun 2023 09:28:58 +0100 Subject: WASM binary format: support element segments --- .../structure/WasmBinaryFormatModuleTests.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (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 7cf142a4..4c26a55c 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 @@ -212,6 +212,44 @@ public class WasmBinaryFormatModuleTests { snapshotter.assertSnapshot(result); } + @Test + public void canSerializeModuleWithElementSegments(Snapshotter snapshotter) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addFunction(new WasmFunction( + "f1", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addFunction(new WasmFunction( + "f2", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addFunction(new WasmFunction( + "f3", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of()) + )) + .addTable(new WasmTable(new WasmTableType( + WasmReferenceType.FUNC_REF, + WasmLimits.min(1) + ))) + .addElementSegment(WasmElementSegment.funcIndicesActive(List.of( + new WasmFuncIndex(0), + new WasmFuncIndex(2) + ))); + + 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