(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestOptionFieldSerialization(t *testing.T) { |
| 85 | type Nested struct { |
| 86 | Name string |
| 87 | } |
| 88 | type OptionStruct struct { |
| 89 | OptInt optional.Optional[int32] |
| 90 | OptZero optional.Optional[int32] |
| 91 | OptString optional.Optional[string] |
| 92 | OptBool optional.Optional[bool] |
| 93 | } |
| 94 | |
| 95 | f := New(WithXlang(true), WithCompatible(false)) |
| 96 | require.NoError(t, f.RegisterStruct(OptionStruct{}, 1100)) |
| 97 | |
| 98 | obj := OptionStruct{ |
| 99 | OptInt: optional.Some[int32](123), |
| 100 | OptZero: optional.Some[int32](0), |
| 101 | OptString: optional.Some("hello"), |
| 102 | OptBool: optional.Some(true), |
| 103 | } |
| 104 | |
| 105 | data, err := f.Serialize(&obj) |
| 106 | require.NoError(t, err) |
| 107 | |
| 108 | var result any |
| 109 | err = testDeserialize(t, f, data, &result) |
| 110 | require.NoError(t, err) |
| 111 | |
| 112 | out := result.(*OptionStruct) |
| 113 | require.True(t, out.OptInt.IsSome()) |
| 114 | require.Equal(t, int32(123), out.OptInt.Unwrap()) |
| 115 | require.True(t, out.OptZero.IsSome()) |
| 116 | require.Equal(t, int32(0), out.OptZero.Unwrap()) |
| 117 | require.True(t, out.OptString.IsSome()) |
| 118 | require.Equal(t, "hello", out.OptString.Unwrap()) |
| 119 | require.True(t, out.OptBool.IsSome()) |
| 120 | require.Equal(t, true, out.OptBool.Unwrap()) |
| 121 | } |
| 122 | |
| 123 | type evolvingStruct struct { |
| 124 | ID int32 |
nothing calls this directly
no test coverage detected