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

Function TestSerializeStruct

go/fory/fory_test.go:391–416  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

389}
390
391func TestSerializeStruct(t *testing.T) {
392 for _, referenceTracking := range []bool{false, true} {
393 fory := NewFory(WithXlang(true), WithCompatible(false), WithRefTracking(referenceTracking))
394 require.Nil(t, fory.RegisterStructByName(Bar{}, "example.Bar"))
395 serde(t, fory, &Bar{})
396 bar := Bar{F1: 1, F2: "str"}
397 serde(t, fory, bar)
398 serde(t, fory, &bar)
399
400 type A struct {
401 F1 Bar
402 F2 any
403 }
404 require.Nil(t, fory.RegisterStructByName(A{}, "example.A"))
405 serde(t, fory, A{})
406 serde(t, fory, &A{})
407 // Use int64 for any fields since xlang deserializes integers to int64
408 serde(t, fory, A{F1: Bar{F1: 1, F2: "str"}, F2: int64(-1)})
409 serde(t, fory, &A{F1: Bar{F1: 1, F2: "str"}, F2: int64(-1)})
410
411 require.Nil(t, fory.RegisterStructByName(Foo{}, "example.Foo"))
412 foo := newFoo()
413 serde(t, fory, foo)
414 serde(t, fory, &foo)
415 }
416}
417
418func TestSerializeCircularReference(t *testing.T) {
419 fory := NewFory(WithXlang(true), WithCompatible(false), WithRefTracking(true))

Callers

nothing calls this directly

Calls 8

RegisterStructByNameMethod · 0.95
NewForyFunction · 0.85
WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
WithRefTrackingFunction · 0.85
serdeFunction · 0.85
newFooFunction · 0.85
int64Function · 0.50

Tested by

no test coverage detected