diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-31 10:50:10 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-31 10:50:10 +0100 |
| commit | 578bf1f04b48f48225cfa794a27426cca4f6384a (patch) | |
| tree | fc5c2737ffa65e20305f165a593111463a36166d /examples/11-transient-0/output/java/src/test | |
| parent | 1831d27671abe87bcbea5da40517093c37efb9b7 (diff) | |
Support singleton structs
Diffstat (limited to 'examples/11-transient-0/output/java/src/test')
| -rw-r--r-- | examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java | 295 |
1 files changed, 0 insertions, 295 deletions
diff --git a/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java deleted file mode 100644 index a924d1e..0000000 --- a/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java +++ /dev/null @@ -1,295 +0,0 @@ -package org.zwobble.example; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.zwobble.example.types.data.EnumWithVariants; -import org.zwobble.example.types.data.StructWithBool; -import org.zwobble.example.types.data.StructWithDifferentSharedTypes; -import org.zwobble.example.types.data.StructWithEnum; -import org.zwobble.example.types.data.StructWithInt32; -import org.zwobble.example.types.data.StructWithInt64; -import org.zwobble.example.types.data.StructWithList; -import org.zwobble.example.types.data.StructWithListOfShared; -import org.zwobble.example.types.data.StructWithOption; -import org.zwobble.example.types.data.StructWithSharedSumAndVariant; -import org.zwobble.example.types.data.StructWithString; -import org.zwobble.example.types.data.StructWithStruct; -import org.zwobble.example.types.data.StructWithSum; -import org.zwobble.example.types.data.VariantOne; -import org.zwobble.example.types.data.VariantTwo; -import org.zwobble.example.types.data.transient0.HobgoblinTransient0Data; -import org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue; - -public class Transient0Tests { - @Test - public void structWithBool() throws IOException { - var value = new StructWithBool(true, false); - - assertRoundTripEncoding( - "StructWithBool", - value, - HobgoblinTransient0Data::encodeStructWithBool, - HobgoblinTransient0Data::decodeStructWithBool - ); - } - - @Test - public void structWithInt32() throws IOException { - var value = new StructWithInt32(10, 25); - - assertRoundTripEncoding( - "StructWithInt32", - value, - HobgoblinTransient0Data::encodeStructWithInt32, - HobgoblinTransient0Data::decodeStructWithInt32 - ); - } - - @Test - public void structWithInt64() throws IOException { - var value = new StructWithInt64(10, 25); - - assertRoundTripEncoding( - "StructWithInt64", - value, - HobgoblinTransient0Data::encodeStructWithInt64, - HobgoblinTransient0Data::decodeStructWithInt64 - ); - } - - @Test - public void structWithString() throws IOException { - var value = new StructWithString("abc", "def"); - - assertRoundTripEncoding( - "StructWithString", - value, - HobgoblinTransient0Data::encodeStructWithString, - HobgoblinTransient0Data::decodeStructWithString - ); - } - - @Test - public void structWithStruct() throws IOException { - var value = new StructWithStruct(new StructWithInt32(10, 25), 42); - - assertRoundTripEncoding( - "StructWithStruct", - value, - HobgoblinTransient0Data::encodeStructWithStruct, - HobgoblinTransient0Data::decodeStructWithStruct - ); - } - - @Test - public void structWithList() throws IOException { - var value = new StructWithList( - List.of(10L, 25L), - List.of( - new StructWithInt32(42, 47), - new StructWithInt32(52, 57), - new StructWithInt32(62, 67) - ) - ); - - assertRoundTripEncoding( - "StructWithList", - value, - HobgoblinTransient0Data::encodeStructWithList, - HobgoblinTransient0Data::decodeStructWithList - ); - } - - @Test - public void structWithOptionNone() throws IOException { - var value = new StructWithOption( - Optional.empty(), - Optional.empty() - ); - - assertRoundTripEncoding( - "StructWithOption_None", - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void structWithOptionSome() throws IOException { - var value = new StructWithOption( - Optional.of(10L), - Optional.of(new StructWithInt32(42, 47)) - ); - - assertRoundTripEncoding( - "StructWithOption_Some", - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void enumWithVariants() throws IOException { - assertRoundTripEncoding( - "EnumWithVariants_zero", - EnumWithVariants.ZERO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - "EnumWithVariants_one", - EnumWithVariants.ONE, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - "EnumWithVariants_two", - EnumWithVariants.TWO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - } - - @Test - public void structWithEnum() throws IOException { - var value = new StructWithEnum( - EnumWithVariants.ONE, - 42 - ); - - assertRoundTripEncoding( - "StructWithEnum", - value, - HobgoblinTransient0Data::encodeStructWithEnum, - HobgoblinTransient0Data::decodeStructWithEnum - ); - } - - @Test - public void sumWithVariants() throws IOException { - assertRoundTripEncoding( - "SumWithVariants_VariantOne", - new VariantOne(10), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - - assertRoundTripEncoding( - "SumWithVariants_VariantTwo", - new VariantTwo(25), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - } - - @Test - public void structWithSum() throws IOException { - var value = new StructWithSum( - new VariantTwo(25), - 42 - ); - - assertRoundTripEncoding( - "StructWithSum", - value, - HobgoblinTransient0Data::encodeStructWithSum, - HobgoblinTransient0Data::decodeStructWithSum - ); - } - - @Test - public void structWithListOfShared() throws IOException { - var a = new StructWithInt32(10, 25); - var b = new StructWithInt32(42, 47); - - var value = new StructWithListOfShared(List.of(a, a, b, a, b)); - - var decodedValue = assertRoundTripEncoding( - "StructWithListOfShared", - value, - HobgoblinTransient0Data::encodeStructWithListOfShared, - HobgoblinTransient0Data::decodeStructWithListOfShared - ); - Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(1)); - Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(3)); - Assertions.assertSame(decodedValue.inner().get(2), decodedValue.inner().get(4)); - } - - @Test - public void structWithDifferentSharedTypes() throws IOException { - var a = new StructWithInt32(10, 25); - var b = new StructWithInt64(42, 47); - var c = new StructWithInt32(52, 57); - - var value = new StructWithDifferentSharedTypes(a, b, c); - - assertRoundTripEncoding( - "StructWithDifferentSharedTypes", - value, - HobgoblinTransient0Data::encodeStructWithDifferentSharedTypes, - HobgoblinTransient0Data::decodeStructWithDifferentSharedTypes - ); - } - - @Test - public void structWithSharedSumAndVariant() throws IOException { - var a = new VariantOne(10); - - var value = new StructWithSharedSumAndVariant(a, a); - - assertRoundTripEncoding( - "StructWithSharedSumAndVariant", - value, - HobgoblinTransient0Data::encodeStructWithSharedSumAndVariant, - HobgoblinTransient0Data::decodeStructWithSharedSumAndVariant - ); - } - - private <T> T assertRoundTripEncoding( - String name, - T value, - Encoder<T> encoder, - Decoder<T> decoder - ) throws IOException { - var outputStream = new ByteArrayOutputStream(); - encoder.encode(value, outputStream, new HashMap<>()); - var bytes = outputStream.toByteArray(); - - var outputDir = System.getenv("HOBGOBLIN_OUTPUT_DIR"); - var transient0OutputDir = Path.of(outputDir).resolve("transient-0"); - Files.createDirectories(transient0OutputDir); - var transient0OutputPath = transient0OutputDir.resolve(name); - Files.write(transient0OutputPath, bytes); - - var inputStream = new ByteArrayInputStream(bytes); - var decodedValue = decoder.decode(inputStream, new ArrayList<>()); - - Assertions.assertEquals(value, decodedValue); - - return decodedValue; - } - - private interface Encoder<T> { - void encode(T value, OutputStream outputStream, Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues) throws IOException; - } - - private interface Decoder<T> { - T decode(InputStream inputStream, List<Object> sharedValues) throws IOException; - } -} |
