diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-21 22:45:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-21 22:45:56 +0100 |
| commit | f365095e567847620edfa6af6f72b5bc50f9537e (patch) | |
| tree | 3b9f7f281dc5b318d99df7a90489524790861078 /src/test/java | |
| parent | 126533bf5210d1bf311628a18af6e46f765c922e (diff) | |
Support import of cuntions in WASM binary format
Diffstat (limited to 'src/test/java')
2 files changed, 30 insertions, 0 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 d53ffc62..ad63f317 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.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.testing.ProcessRunner; @@ -42,6 +44,29 @@ public class WasmBinaryFormatModuleTests { expect.toMatchSnapshot(result); } + @Test + public void canSerializeModuleWithImports() throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addType(new WasmFuncType(List.of(), List.of())) + .addType(new WasmFuncType(List.of(WasmValueType.I32), List.of())) + .addImport(new WasmImport( + "ModuleName1", + "EntityName1", + "Identifier1", + new WasmImportDescriptor.Func(new WasmFuncType(List.of(), List.of())) + )) + .addImport(new WasmImport( + "ModuleName2", + "EntityName2", + "Identifier2", + new WasmImportDescriptor.Func(new WasmFuncType(List.of(WasmValueType.I32), List.of())) + )); + + var result = serializeModule(module); + + expect.toMatchSnapshot(result); + } + private String serializeModule(WasmModule module) throws IOException, InterruptedException { Files.createDirectories(Path.of("tests-tmp")); var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); 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 c205ed8e..ccd82568 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 @@ -3,6 +3,11 @@ module.wasm: file format wasm 0x1Section Details:Code Disassembly: ] +org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests.canSerializeModuleWithImports=[ +module.wasm: file format wasm 0x1Section Details:Type[2]: - type[0] () -> nil - type[1] (i32) -> nilImport[2]: - func[0] sig=0 <ModuleName1.EntityName1> <- ModuleName1.EntityName1 - func[1] sig=1 <ModuleName2.EntityName2> <- ModuleName2.EntityName2Code 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 |
