summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java36
-rw-r--r--examples/10-transient-0/src/data.hob5
2 files changed, 41 insertions, 0 deletions
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];
+}