diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-21 21:27:31 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-21 21:27:31 +0100 |
| commit | 126533bf5210d1bf311628a18af6e46f765c922e (patch) | |
| tree | 6114298e13d96d391564b5eab2dc004e2dfd87d7 /src/test/java | |
| parent | b92d46a9fc641afca93571e1b398b968816b1b57 (diff) | |
Add binary encoding of WASM type section
Diffstat (limited to 'src/test/java')
2 files changed, 23 insertions, 2 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 5ddad366..d53ffc62 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,6 +5,8 @@ import au.com.origin.snapshots.junit5.SnapshotExtension; 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.types.WasmFuncType; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; import org.shedlang.compiler.testing.ProcessRunner; import java.io.FileOutputStream; @@ -19,8 +21,21 @@ public class WasmBinaryFormatModuleTests { @Test public void canSerializeEmptyModule() throws IOException, InterruptedException { - var module = WasmModule.builder() - .build(); + var module = WasmModule.EMPTY; + + var result = serializeModule(module); + + expect.toMatchSnapshot(result); + } + + @Test + public void canSerializeModuleWithTypes() throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addType(new WasmFuncType(List.of(), List.of())) + .addType(new WasmFuncType( + List.of(WasmValueType.I32, WasmValueType.I64), + List.of(WasmValueType.F32, WasmValueType.F64) + )); var result = serializeModule(module); @@ -31,6 +46,7 @@ public class WasmBinaryFormatModuleTests { Files.createDirectories(Path.of("tests-tmp")); var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); var modulePath = temporaryDirectory.resolve("module.wasm"); + System.out.println(modulePath); try (var outputStream = new FileOutputStream(modulePath.toFile())) { WasmBinaryFormat.serializeModule(module, outputStream); diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap b/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap index 370ab0d6..c205ed8e 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/snapshots/WasmBinaryFormatModuleTests.snap @@ -1,3 +1,8 @@ org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeEmptyModule=[ module.wasm: file format wasm 0x1Section Details:Code Disassembly: +] + + +org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeModuleWithTypes=[ +module.wasm: file format wasm 0x1Section Details:Type[2]: - type[0] () -> nil - type[1] (i32, i64) -> (f32, f64)Code Disassembly: ]
\ No newline at end of file |
