diff options
Diffstat (limited to 'src/test/java/org/shedlang/compiler/patio')
3 files changed, 244 insertions, 298 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java index 2f2990bb..ae554bb8 100644 --- a/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java +++ b/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java @@ -8,9 +8,8 @@ import org.shedlang.compiler.patio.operands.PatioOperand; import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.patio.values.PatioDataPtrValue; import org.shedlang.compiler.patio.values.PatioIntValue; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.Sources; +import java.io.IOException; import java.util.List; import java.util.Optional; @@ -21,11 +20,11 @@ public abstract class PatioSerializationTests { // == Compilation unit == - protected abstract PatioCompilationUnit deserializeCompilationUnit(byte[] buffer); - protected abstract byte[] serializeCompilationUnit(PatioCompilationUnit value); + protected abstract PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) throws IOException; + protected abstract byte[] serializeCompilationUnit(PatioCompilationUnit value) throws IOException; @Test - public void canSerializeCompilationUnit() { + public void canSerializeCompilationUnit() throws IOException { var element = PatioFunctionDefinition.builder() .withName("f") .build(); @@ -40,11 +39,11 @@ public abstract class PatioSerializationTests { // == Compilation unit elements == - protected abstract PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer, Source parentSource); - protected abstract byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value, Source parentSource); + protected abstract PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer) throws IOException; + protected abstract byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value) throws IOException; @Test - public void canSerializeDataElementImmutableDefinition() { + public void canSerializeDataElementImmutableDefinition() throws IOException { var element = Patio.dataElementImmutableDefinition( "x", PatioVisibility.PRIVATE, @@ -55,30 +54,28 @@ public abstract class PatioSerializationTests { ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeDataElementMutableDeclaration() { + public void canSerializeDataElementMutableDeclaration() throws IOException { var element = Patio.dataElementMutableDeclaration( "x", PatioDataLayouts.INT ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeDataElementMutableDefinition() { + public void canSerializeDataElementMutableDefinition() throws IOException { var element = Patio.dataElementMutableDefinition( "x", PatioVisibility.PRIVATE, @@ -86,27 +83,25 @@ public abstract class PatioSerializationTests { ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeExceptionTypeDefinition() { + public void canSerializeExceptionTypeDefinition() throws IOException { var element = Patio.exceptionTypeDefinition("Error", PatioTypes.INT); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeFunctionDeclaration() { + public void canSerializeFunctionDeclaration() throws IOException { var element = PatioFunctionDeclaration.builder() .withName("f") .addParam(Patio.param("param1", PatioTypes.INT)) @@ -115,15 +110,14 @@ public abstract class PatioSerializationTests { .build(); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeFunctionDefinition() { + public void canSerializeFunctionDefinition() throws IOException { var element = PatioFunctionDefinition.builder() .withName("f") .withVisibility(PatioVisibility.PRIVATE) @@ -136,8 +130,7 @@ public abstract class PatioSerializationTests { .build(); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); @@ -145,11 +138,11 @@ public abstract class PatioSerializationTests { // == Instructions == - protected abstract PatioInstruction deserializeInstruction(byte[] buffer, Source parentSource); - protected abstract byte[] serializeInstruction(PatioInstruction value, Source parentSource); + protected abstract PatioInstruction deserializeInstruction(byte[] buffer) throws IOException; + protected abstract byte[] serializeInstruction(PatioInstruction value) throws IOException; @Test - public void canSerializeBlock() { + public void canSerializeBlock() throws IOException { var instruction = Patio.block( List.of( Patio.localStore(Patio.localRef("x1"), Patio.intConst(1)), @@ -162,27 +155,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeBoolToInt() { + public void canSerializeBoolToInt() throws IOException { var instruction = Patio.boolToInt(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallWithoutDestination() { + public void canSerializeCallWithoutDestination() throws IOException { var instruction = Patio.call( Optional.empty(), "f", @@ -190,15 +181,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallWithDestination() { + public void canSerializeCallWithDestination() throws IOException { var instruction = Patio.call( Optional.of(Patio.localRef("destination")), "f", @@ -206,15 +196,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallPointer() { + public void canSerializeCallPointer() throws IOException { var instruction = Patio.callPointer( Patio.localRef("destination"), Patio.localRef("f"), @@ -222,27 +211,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeDataPtrToInt() { + public void canSerializeDataPtrToInt() throws IOException { var instruction = Patio.dataPtrToInt(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIf() { + public void canSerializeIf() throws IOException { var instruction = Patio.if_( List.of( Patio.localRef("x"), @@ -272,15 +259,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntAdd() { + public void canSerializeIntAdd() throws IOException { var instruction = Patio.intAdd( Patio.localRef("destination"), Patio.localRef("left"), @@ -288,15 +274,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntEquals() { + public void canSerializeIntEquals() throws IOException { var instruction = Patio.intEquals( Patio.localRef("destination"), Patio.localRef("left"), @@ -304,15 +289,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntNotEqual() { + public void canSerializeIntNotEqual() throws IOException { var instruction = Patio.intNotEqual( Patio.localRef("destination"), Patio.localRef("left"), @@ -320,15 +304,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntSub() { + public void canSerializeIntSub() throws IOException { var instruction = Patio.intSub( Patio.localRef("destination"), Patio.localRef("left"), @@ -336,57 +319,53 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntToBool() { + public void canSerializeIntToBool() throws IOException { var instruction = Patio.intToBool(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntToDataPtr() { + public void canSerializeIntToDataPtr() throws IOException { var instruction = Patio.intToDataPtr( Patio.localRef("destination"), Patio.localRef("value") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLocalStore() { + public void canSerializeLocalStore() throws IOException { var instruction = Patio.localStore( Patio.localRef("destination"), Patio.localRef("x") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoop() { + public void canSerializeLoop() throws IOException { var instruction = Patio.loop( List.of( Patio.localStore(Patio.localRef("x"), Patio.intConst(1)) @@ -394,39 +373,36 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoopBreak() { + public void canSerializeLoopBreak() throws IOException { var instruction = Patio.loopBreak(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoopContinue() { + public void canSerializeLoopContinue() throws IOException { var instruction = Patio.loopContinue(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeMemoryLoad() { + public void canSerializeMemoryLoad() throws IOException { var instruction = Patio.memoryLoad( Patio.localRef("destination"), Patio.localRef("pointer"), @@ -435,15 +411,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeMemoryStore() { + public void canSerializeMemoryStore() throws IOException { var instruction = Patio.memoryStore( Patio.localRef("pointer"), PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)), @@ -452,39 +427,36 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeReturn() { + public void canSerializeReturn() throws IOException { var instruction = Patio.return_(Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeReturnVoid() { + public void canSerializeReturnVoid() throws IOException { var instruction = Patio.returnVoid(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeSwitch() { + public void canSerializeSwitch() throws IOException { var instruction = Patio.switch_( List.of( Patio.localRef("x"), @@ -532,27 +504,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeThrow() { + public void canSerializeThrow() throws IOException { var instruction = Patio.throw_("Error", Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeTry() { + public void canSerializeTry() throws IOException { var instruction = Patio.try_( List.of(Patio.localRef("x"), Patio.localRef("y")), List.of( @@ -589,50 +559,46 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeUnreachable() { + public void canSerializeUnreachable() throws IOException { var instruction = Patio.unreachable(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeVarLoad() { + public void canSerializeVarLoad() throws IOException { var instruction = Patio.varLoad( Patio.localRef("destination"), Patio.localRef("v") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeVarStore() { + public void canSerializeVarStore() throws IOException { var instruction = Patio.varStore( Patio.localRef("destination"), Patio.localRef("value") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); @@ -640,11 +606,11 @@ public abstract class PatioSerializationTests { // == Operands == - protected abstract PatioOperand deserializeOperand(byte[] buffer); - protected abstract byte[] serializeOperand(PatioOperand value); + protected abstract PatioOperand deserializeOperand(byte[] buffer) throws IOException; + protected abstract byte[] serializeOperand(PatioOperand value) throws IOException; @Test - public void canSerializeBoolConst() { + public void canSerializeBoolConst() throws IOException { var operand = Patio.boolConst(true); var deserializedOperand = deserializeOperand( @@ -655,7 +621,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeByteConst() { + public void canSerializeByteConst() throws IOException { var operand = Patio.byteConst((byte) 42); var deserializedOperand = deserializeOperand( @@ -666,7 +632,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrConst() { + public void canSerializeDataPtrConst() throws IOException { var operand = Patio.dataPtrConst("x"); var deserializedOperand = deserializeOperand( @@ -677,7 +643,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeFunctionPtrConst() { + public void canSerializeFunctionPtrConst() throws IOException { var operand = Patio.functionPtrConst("x"); var deserializedOperand = deserializeOperand( @@ -688,7 +654,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntConst() { + public void canSerializeIntConst() throws IOException { var operand = Patio.intConst(42); var deserializedOperand = deserializeOperand( @@ -699,7 +665,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeInt32Const() { + public void canSerializeInt32Const() throws IOException { var operand = Patio.int32Const(42); var deserializedOperand = deserializeOperand( @@ -710,7 +676,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeLocalRef() { + public void canSerializeLocalRef() throws IOException { var operand = Patio.localRef("x"); var deserializedOperand = deserializeOperand( @@ -722,11 +688,11 @@ public abstract class PatioSerializationTests { // == Data ptr values == - protected abstract PatioDataPtrValue deserializeDataPtrValue(byte[] buffer); - protected abstract byte[] serializeDataPtrValue(PatioDataPtrValue value); + protected abstract PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataPtrValue(PatioDataPtrValue value) throws IOException; @Test - public void canSerializeDataPtrValueDataElement() { + public void canSerializeDataPtrValueDataElement() throws IOException { var dataPtrValue = Patio.dataPtrValueDataElement("string"); var deserializedDataPtrValue = deserializeDataPtrValue( @@ -737,7 +703,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrValueNull() { + public void canSerializeDataPtrValueNull() throws IOException { var dataPtrValue = Patio.dataPtrValueNull(); var deserializedDataPtrValue = deserializeDataPtrValue( @@ -749,11 +715,11 @@ public abstract class PatioSerializationTests { // == Int values == - protected abstract PatioIntValue deserializeIntValue(byte[] buffer); - protected abstract byte[] serializeIntValue(PatioIntValue value); + protected abstract PatioIntValue deserializeIntValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeIntValue(PatioIntValue value) throws IOException; @Test - public void canSerializeIntValueByteOffsetOf() { + public void canSerializeIntValueByteOffsetOf() throws IOException { var intValue = Patio.intValueByteOffsetOf( PatioDataLayouts.struct(List.of( PatioDataLayouts.INT, @@ -770,7 +736,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntValueByteSizeOf() { + public void canSerializeIntValueByteSizeOf() throws IOException { var intValue = Patio.intValueByteSizeOf( PatioDataLayouts.struct(List.of( PatioDataLayouts.INT, @@ -786,7 +752,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntValueLiteral() { + public void canSerializeIntValueLiteral() throws IOException { var intValue = Patio.intValueLiteral(42); var deserializedIntValue = deserializeIntValue( @@ -798,11 +764,11 @@ public abstract class PatioSerializationTests { // == Types == - protected abstract PatioType deserializeType(byte[] buffer); - protected abstract byte[] serializeType(PatioType value); + protected abstract PatioType deserializeType(byte[] buffer) throws IOException; + protected abstract byte[] serializeType(PatioType value) throws IOException; @Test - public void canSerializeBoolType() { + public void canSerializeBoolType() throws IOException { var type = PatioTypes.BOOL; var deserializedType = deserializeType( @@ -813,7 +779,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeByteType() { + public void canSerializeByteType() throws IOException { var type = PatioTypes.BYTE; var deserializedType = deserializeType( @@ -824,7 +790,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrType() { + public void canSerializeDataPtrType() throws IOException { var type = PatioTypes.DATA_PTR; var deserializedType = deserializeType( @@ -835,7 +801,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeFunctionPtrType() { + public void canSerializeFunctionPtrType() throws IOException { var type = PatioTypes.FUNCTION_PTR; var deserializedType = deserializeType( @@ -846,7 +812,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntType() { + public void canSerializeIntType() throws IOException { var type = PatioTypes.INT; var deserializedType = deserializeType( @@ -857,7 +823,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeInt32Type() { + public void canSerializeInt32Type() throws IOException { var type = PatioTypes.INT32; var deserializedType = deserializeType( @@ -869,11 +835,11 @@ public abstract class PatioSerializationTests { // == Data layouts == - protected abstract PatioDataLayout deserializeDataLayout(byte[] buffer); - protected abstract byte[] serializeDataLayout(PatioDataLayout value); + protected abstract PatioDataLayout deserializeDataLayout(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataLayout(PatioDataLayout value) throws IOException; @Test - public void canSerializeDataLayoutArray() { + public void canSerializeDataLayoutArray() throws IOException { var layout = PatioDataLayouts.array(PatioDataLayouts.INT, 4); var deserializedLayout = deserializeDataLayout( @@ -884,7 +850,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutBool() { + public void canSerializeDataLayoutBool() throws IOException { var layout = PatioDataLayouts.BOOL; var deserializedLayout = deserializeDataLayout( @@ -895,7 +861,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutByte() { + public void canSerializeDataLayoutByte() throws IOException { var layout = PatioDataLayouts.BYTE; var deserializedLayout = deserializeDataLayout( @@ -906,7 +872,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutDataPtr() { + public void canSerializeDataLayoutDataPtr() throws IOException { var layout = PatioDataLayouts.DATA_PTR; var deserializedLayout = deserializeDataLayout( @@ -917,7 +883,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutFunctionPtr() { + public void canSerializeDataLayoutFunctionPtr() throws IOException { var layout = PatioDataLayouts.FUNCTION_PTR; var deserializedLayout = deserializeDataLayout( @@ -928,7 +894,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutInt() { + public void canSerializeDataLayoutInt() throws IOException { var layout = PatioDataLayouts.INT; var deserializedLayout = deserializeDataLayout( @@ -939,7 +905,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutInt32() { + public void canSerializeDataLayoutInt32() throws IOException { var layout = PatioDataLayouts.INT32; var deserializedLayout = deserializeDataLayout( @@ -950,7 +916,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutStruct() { + public void canSerializeDataLayoutStruct() throws IOException { var layout = PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)); var deserializedLayout = deserializeDataLayout( @@ -962,12 +928,11 @@ public abstract class PatioSerializationTests { // == Data values == - protected abstract PatioDataValue deserializeDataValue(byte[] buffer); - protected abstract byte[] serializeDataValue(PatioDataValue value); - + protected abstract PatioDataValue deserializeDataValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataValue(PatioDataValue value) throws IOException; @Test - public void canSerializeDataValueArray() { + public void canSerializeDataValueArray() throws IOException { var value = PatioDataValues.array( PatioDataLayouts.BYTE, List.of( @@ -985,7 +950,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueBool() { + public void canSerializeDataValueBool() throws IOException { var value = PatioDataValues.bool(true); var deserializedValue = deserializeDataValue( @@ -996,7 +961,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueByte() { + public void canSerializeDataValueByte() throws IOException { var value = PatioDataValues.byte_(0xc8); var deserializedValue = deserializeDataValue( @@ -1007,7 +972,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueDataPtr() { + public void canSerializeDataValueDataPtr() throws IOException { var value = PatioDataValues.dataPtrNull(); var deserializedValue = deserializeDataValue( @@ -1018,7 +983,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueInt() { + public void canSerializeDataValueInt() throws IOException { var value = PatioDataValues.int_(42); var deserializedValue = deserializeDataValue( @@ -1029,7 +994,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueInt32() { + public void canSerializeDataValueInt32() throws IOException { var value = PatioDataValues.int32(42); var deserializedValue = deserializeDataValue( @@ -1040,7 +1005,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueStruct() { + public void canSerializeDataValueStruct() throws IOException { var value = PatioDataValues.struct(List.of( PatioDataValues.byte_(0x01), PatioDataValues.byte_(0x02), diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java deleted file mode 100644 index 9ff08678..00000000 --- a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.shedlang.compiler.patio.serialization; - -import com.google.flatbuffers.FlatBufferBuilder; -import org.shedlang.compiler.patio.PatioCompilationUnit; -import org.shedlang.compiler.patio.PatioCompilationUnitElement; -import org.shedlang.compiler.patio.flatbuffers.*; -import org.shedlang.compiler.patio.instructions.PatioInstruction; -import org.shedlang.compiler.patio.operands.PatioOperand; -import org.shedlang.compiler.patio.types.PatioDataLayout; -import org.shedlang.compiler.patio.types.PatioDataValue; -import org.shedlang.compiler.patio.types.PatioType; -import org.shedlang.compiler.patio.values.PatioDataPtrValue; -import org.shedlang.compiler.patio.values.PatioIntValue; -import org.shedlang.compiler.sources.Source; - -import java.nio.ByteBuffer; - -public class PatioToFlatbuffersTests extends PatioSerializationTests { - @Override - protected byte[] serializeCompilationUnit(PatioCompilationUnit value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeCompilationUnit(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) { - var valueFbs = PatioCompilationUnitFbs.getRootAsPatioCompilationUnitFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeCompilationUnit(valueFbs); - } - - @Override - protected byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value, Source parentSource) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeCompilationUnitElement(builder, value, parentSource); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer, Source parentSource) { - var valueFbs = PatioCompilationUnitElementFbs.getRootAsPatioCompilationUnitElementFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeCompilationUnitElement(valueFbs, parentSource); - } - - @Override - protected byte[] serializeInstruction(PatioInstruction value, Source parentSource) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeInstruction(builder, value, parentSource); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioInstruction deserializeInstruction(byte[] buffer, Source parentSource) { - var valueFbs = PatioInstructionFbs.getRootAsPatioInstructionFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeInstruction(valueFbs, parentSource); - } - - @Override - protected byte[] serializeOperand(PatioOperand value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeOperand(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioOperand deserializeOperand(byte[] buffer) { - var valueFbs = PatioOperandFbs.getRootAsPatioOperandFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeOperand(valueFbs); - } - - @Override - protected byte[] serializeDataPtrValue(PatioDataPtrValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataPtrValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) { - var valueFbs = PatioDataPtrValueFbs.getRootAsPatioDataPtrValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataPtrValue(valueFbs); - } - - @Override - protected byte[] serializeIntValue(PatioIntValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeIntValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioIntValue deserializeIntValue(byte[] buffer) { - var valueFbs = PatioIntValueFbs.getRootAsPatioIntValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeIntValue(valueFbs); - } - - @Override - protected byte[] serializeType(PatioType value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeType(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioType deserializeType(byte[] buffer) { - var valueFbs = PatioTypeFbs.getRootAsPatioTypeFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeType(valueFbs); - } - - @Override - protected byte[] serializeDataLayout(PatioDataLayout value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataLayout(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataLayout deserializeDataLayout(byte[] buffer) { - var valueFbs = PatioDataLayoutFbs.getRootAsPatioDataLayoutFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataLayout(valueFbs); - } - - @Override - protected byte[] serializeDataValue(PatioDataValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataValue deserializeDataValue(byte[] buffer) { - var valueFbs = PatioDataValueFbs.getRootAsPatioDataValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataValue(valueFbs); - } -} diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java new file mode 100644 index 00000000..34d54ca2 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java @@ -0,0 +1,125 @@ +package org.shedlang.compiler.patio.serialization; + +import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioCompilationUnitElement; +import org.shedlang.compiler.patio.instructions.PatioInstruction; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.values.PatioDataPtrValue; +import org.shedlang.compiler.patio.values.PatioIntValue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class PatioToTransient0Tests extends PatioSerializationTests { + @Override + protected byte[] serializeCompilationUnit(PatioCompilationUnit value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeCompilationUnit(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeCompilationUnit(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeCompilationUnitElement(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeCompilationUnitElement(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeInstruction(PatioInstruction value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeInstruction(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioInstruction deserializeInstruction(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeInstruction(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeOperand(PatioOperand value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeOperand(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioOperand deserializeOperand(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeOperand(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataPtrValue(PatioDataPtrValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataPtrValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataPtrValue(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeIntValue(PatioIntValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeIntValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioIntValue deserializeIntValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeIntValue(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeType(PatioType value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeType(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioType deserializeType(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeType(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataLayout(PatioDataLayout value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataLayout(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataLayout deserializeDataLayout(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataLayout(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataValue(PatioDataValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataValue deserializeDataValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataValue(new ByteArrayInputStream(buffer)); + } +} |
