From 7785c220bcef000aedfbe2b9c95a32272786f370 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 21 Mar 2026 15:36:58 +0000 Subject: Serialize Patio operands to Protobuf --- .../patio/protobuf/PatioToProtobufTests.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/protobuf/PatioToProtobufTests.java b/src/test/java/org/shedlang/compiler/patio/protobuf/PatioToProtobufTests.java index 35ec4221..03ded426 100644 --- a/src/test/java/org/shedlang/compiler/patio/protobuf/PatioToProtobufTests.java +++ b/src/test/java/org/shedlang/compiler/patio/protobuf/PatioToProtobufTests.java @@ -2,6 +2,7 @@ package org.shedlang.compiler.patio.protobuf; import org.junit.jupiter.api.Test; import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioTesting; import org.shedlang.compiler.patio.PatioVisibility; import org.shedlang.compiler.patio.instructions.Patio; import org.shedlang.compiler.patio.types.PatioDataLayouts; @@ -96,6 +97,85 @@ public class PatioToProtobufTests { assertThat(deserializedElement, equalTo(element)); } + // == Operands == + + @Test + public void canSerializeBoolConst() { + var operand = Patio.boolConst(true); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeByteConst() { + var operand = Patio.byteConst((byte) 42); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeDataPtrConst() { + var operand = Patio.dataPtrConst("x"); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeFunctionPtrConst() { + var operand = Patio.functionPtrConst("x"); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeIntConst() { + var operand = Patio.intConst(42); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeInt32Const() { + var operand = Patio.int32Const(42); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + + @Test + public void canSerializeLocalRef() { + var operand = Patio.localRef("x"); + + var deserializedOperand = PatioToProtobuf.deserializeOperand( + PatioToProtobuf.serializeOperand(operand) + ); + + assertThat(deserializedOperand, equalTo(operand)); + } + // == Data ptr values == @Test -- cgit v1.2.3