MCPcopy Create free account
hub / github.com/apache/fory / TestCompatibleSerializationScenarios

Function TestCompatibleSerializationScenarios

go/fory/fory_compatible_test.go:199–621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

197}
198
199func TestCompatibleSerializationScenarios(t *testing.T) {
200 cases := []compatibilityCase{
201 {
202 name: "SimpleRoundTrip",
203 tag: "SimpleDataClass",
204 writeType: SimpleDataClass{},
205 readType: SimpleDataClass{},
206 input: SimpleDataClass{Name: "test", Age: 25, Active: true},
207 assertFunc: func(t *testing.T, input any, output any) {
208 in := input.(SimpleDataClass)
209 out := output.(SimpleDataClass)
210 assert.Equal(t, in.Age, out.Age)
211 assert.Equal(t, in.Active, out.Active)
212 assert.Equal(t, in.Name, out.Name)
213 },
214 },
215 {
216 name: "ComplexRoundTrip",
217 tag: "ComplexObject1",
218 writeType: ComplexObject1{},
219 readType: ComplexObject1{},
220 input: func() ComplexObject1 {
221 nested := ComplexObject2{
222 F1: true,
223 F2: map[int8]int32{-1: 2},
224 }
225 return ComplexObject1{
226 F1: nested,
227 F2: "abc",
228 F3: []string{"abc", "abc"},
229 F4: map[int8]int32{1: 2},
230 F5: MaxInt8,
231 F6: MaxInt16,
232 F7: MaxInt32,
233 F8: MaxInt64,
234 F9: float32(0.5),
235 F10: 1 / 3.0,
236 F11: [2]int16{1, 2},
237 F12: []int16{-1, 4},
238 }
239 }(),
240 writerSetup: func(f *Fory) error {
241 return f.RegisterStructByName(ComplexObject2{}, "test.ComplexObject2")
242 },
243 readerSetup: func(f *Fory) error {
244 return f.RegisterStructByName(ComplexObject2{}, "test.ComplexObject2")
245 },
246 assertFunc: func(t *testing.T, input any, output any) {
247 in := input.(ComplexObject1)
248 out := output.(ComplexObject1)
249 // Note: F1 may be either ComplexObject2 or *ComplexObject2 depending on reference tracking
250 inNested := in.F1.(ComplexObject2)
251 var outNested ComplexObject2
252 switch v := out.F1.(type) {
253 case ComplexObject2:
254 outNested = v
255 case *ComplexObject2:
256 outNested = *v

Callers

nothing calls this directly

Calls 6

ptrFunction · 0.85
runCompatibilityCaseFunction · 0.85
float32Function · 0.50
int32Function · 0.50
EqualMethod · 0.45
RegisterStructByNameMethod · 0.45

Tested by

no test coverage detected