From f1c08d241b831023ce9bd71806e4352350b54f74 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 26 Dec 2023 22:36:08 +0000 Subject: Extract serializeInstructions() --- .../binary/WasmBinaryFormatInstructionsTests.java | 57 +++++++++++----------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java index c7c39691..797c8275 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java @@ -20,42 +20,28 @@ public class WasmBinaryFormatInstructionsTests { @Test public void canSerializeI32Add(Snapshotter snapshotter) throws IOException, InterruptedException { - var module = WasmModule.EMPTY - .addFunction(new WasmFunction( - "f", - List.of(), - List.of(), - List.of(), - new WasmExpression(List.of( - new WasmI32Const(0), - new WasmI32Const(0), - new WasmI32Add(), - new WasmDrop() - )) - )); + var instructions = List.of( + new WasmI32Const(0), + new WasmI32Const(0), + new WasmI32Add(), + new WasmDrop() + ); - var result = serializeModuleWasm32(module); + var result = serializeInstructions(instructions); snapshotter.assertSnapshot(result); } @Test public void canSerializeI64Add(Snapshotter snapshotter) throws IOException, InterruptedException { - var module = WasmModule.EMPTY - .addFunction(new WasmFunction( - "f", - List.of(), - List.of(), - List.of(), - new WasmExpression(List.of( - new WasmI64Const(0), - new WasmI64Const(0), - new WasmI64Add(), - new WasmDrop() - )) - )); + var instructions = List.of( + new WasmI64Const(0), + new WasmI64Const(0), + new WasmI64Add(), + new WasmDrop() + ); - var result = serializeModuleWasm32(module); + var result = serializeInstructions(instructions); snapshotter.assertSnapshot(result); } @@ -162,4 +148,19 @@ public class WasmBinaryFormatInstructionsTests { snapshotter.assertSnapshot(result); } + + private String serializeInstructions(List + instructions + ) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addFunction(new WasmFunction( + "f", + List.of(), + List.of(), + List.of(), + new WasmExpression(instructions) + )); + + return serializeModuleWasm32(module); + } } -- cgit v1.2.3