From f9fe80fa50e6ac0c3121c0dde6420c79973c4ccc Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 11 Jul 2026 15:47:22 +0100 Subject: Support options in Java transient-0 --- .../java/org/zwobble/example/Transient0Tests.java | 36 ++++++++++++++++++++++ examples/10-transient-0/src/data.hob | 5 +++ 2 files changed, 41 insertions(+) (limited to 'examples/10-transient-0') diff --git a/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java index b7e841c..40acde4 100644 --- a/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java +++ b/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java @@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.zwobble.example.types.data.HobgoblinTransient0Data; @@ -13,6 +14,7 @@ import org.zwobble.example.types.data.StructWithBool; 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.StructWithOption; import org.zwobble.example.types.data.StructWithString; public class Transient0Tests { @@ -106,4 +108,38 @@ public class Transient0Tests { Assertions.assertEquals(value, decodedValue); } + + @Test + public void structWithOptionNone() throws IOException { + var value = new StructWithOption( + Optional.empty(), + Optional.empty() + ); + + var outputStream = new ByteArrayOutputStream(); + HobgoblinTransient0Data.encodeStructWithOption(value, outputStream); + var bytes = outputStream.toByteArray(); + + var inputStream = new ByteArrayInputStream(bytes); + var decodedValue = HobgoblinTransient0Data.decodeStructWithOption(inputStream); + + Assertions.assertEquals(value, decodedValue); + } + + @Test + public void structWithOptionSome() throws IOException { + var value = new StructWithOption( + Optional.of(10L), + Optional.of(new InnerStruct(42, 47)) + ); + + var outputStream = new ByteArrayOutputStream(); + HobgoblinTransient0Data.encodeStructWithOption(value, outputStream); + var bytes = outputStream.toByteArray(); + + var inputStream = new ByteArrayInputStream(bytes); + var decodedValue = HobgoblinTransient0Data.decodeStructWithOption(inputStream); + + Assertions.assertEquals(value, decodedValue); + } } diff --git a/examples/10-transient-0/src/data.hob b/examples/10-transient-0/src/data.hob index 8550d6d..80ba8e5 100644 --- a/examples/10-transient-0/src/data.hob +++ b/examples/10-transient-0/src/data.hob @@ -32,3 +32,8 @@ struct StructWithList { field a: List[Int64]; field b: List[InnerStruct]; } + +struct StructWithOption { + field a: Option[Int64]; + field b: Option[InnerStruct]; +} -- cgit v1.2.3