diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-25 17:47:38 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-25 17:47:38 +0100 |
| commit | 71f24eac2de498b76994d901092c56bbfca5a067 (patch) | |
| tree | bad7956606976df217fa3c70f55068178f718e03 | |
| parent | 5de41ad211a542ce1ae26a1db3f219b1aaf4c9f4 (diff) | |
Test shared value of sum and variant in java-transient-0
4 files changed, 37 insertions, 0 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 index dbbeb3c..621f195 100644 --- 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 @@ -22,6 +22,7 @@ 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; @@ -226,6 +227,19 @@ public class Transient0Tests { ); } + @Test + public void structWithSumAndVariant() throws IOException { + var a = new VariantOne(10); + + var value = new StructWithSharedSumAndVariant(a, a); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithSharedSumAndVariant, + HobgoblinTransient0Data::decodeStructWithSharedSumAndVariant + ); + } + private <T> T assertRoundTripEncoding( T value, Encoder<T> encoder, diff --git a/examples/11-transient-0/output/rust/src/gen/data.rs b/examples/11-transient-0/output/rust/src/gen/data.rs index 6703918..cdc5aab 100644 --- a/examples/11-transient-0/output/rust/src/gen/data.rs +++ b/examples/11-transient-0/output/rust/src/gen/data.rs @@ -100,3 +100,9 @@ pub struct StructWithDifferentSharedTypes { pub b: ::std::sync::Arc::<crate::data::StructWithInt64>, pub c: ::std::sync::Arc::<crate::data::StructWithInt32>, } + +#[derive(Debug, PartialEq)] +pub struct StructWithSharedSumAndVariant { + pub a: ::std::sync::Arc::<crate::data::SumWithVariants>, + pub b: ::std::sync::Arc::<crate::data::VariantOne>, +} diff --git a/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs b/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs index fb07229..cffb318 100644 --- a/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs +++ b/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs @@ -257,3 +257,15 @@ pub fn decode_struct_with_different_shared_types(reader: &mut impl std::io::Read let c = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader)?); std::io::Result::Ok(crate::data::StructWithDifferentSharedTypes { a: a, b: b, c: c }) } + +pub fn encode_struct_with_shared_sum_and_variant(value: &crate::data::StructWithSharedSumAndVariant, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + crate::data::transient_0::encode_sum_with_variants((&value.a).as_ref(), writer)?; + crate::data::transient_0::encode_variant_one((&value.b).as_ref(), writer)?; + ::std::io::Result::Ok(()) +} + +pub fn decode_struct_with_shared_sum_and_variant(reader: &mut impl std::io::Read) -> ::std::io::Result::<crate::data::StructWithSharedSumAndVariant> { + let a = ::std::sync::Arc::new(crate::data::transient_0::decode_sum_with_variants(reader)?); + let b = ::std::sync::Arc::new(crate::data::transient_0::decode_variant_one(reader)?); + std::io::Result::Ok(crate::data::StructWithSharedSumAndVariant { a: a, b: b }) +} diff --git a/examples/11-transient-0/src/data.hob b/examples/11-transient-0/src/data.hob index abe9552..9c715e9 100644 --- a/examples/11-transient-0/src/data.hob +++ b/examples/11-transient-0/src/data.hob @@ -71,3 +71,8 @@ struct StructWithDifferentSharedTypes { field b: Shared[StructWithInt64]; field c: Shared[StructWithInt32]; } + +struct StructWithSharedSumAndVariant { + field a: Shared[SumWithVariants]; + field b: Shared[VariantOne]; +} |
