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

Function runCompatibilityCase

go/fory/fory_compatible_test.go:635–680  ·  view source on GitHub ↗
(t *testing.T, tc compatibilityCase)

Source from the content-addressed store, hash-verified

633}
634
635func runCompatibilityCase(t *testing.T, tc compatibilityCase) {
636 t.Helper()
637
638 writer := NewForyWithOptions(WithXlang(true), WithCompatible(true))
639 if tc.writerSetup != nil {
640 err := tc.writerSetup(writer)
641 assert.NoError(t, err)
642 }
643 err := writer.RegisterStructByName(tc.writeType, tc.tag)
644 assert.NoError(t, err)
645
646 marshalInput := tc.input
647 if tc.input != nil {
648 value := reflect.ValueOf(tc.input)
649 if value.Kind() == reflect.Struct {
650 ptr := reflect.New(value.Type())
651 ptr.Elem().Set(value)
652 marshalInput = ptr.Interface()
653 }
654 }
655 data, err := writer.Marshal(marshalInput)
656 assert.NoError(t, err)
657
658 reader := NewForyWithOptions(WithXlang(true), WithCompatible(true))
659 if tc.readerSetup != nil {
660 err = tc.readerSetup(reader)
661 assert.NoError(t, err)
662 }
663 err = reader.RegisterStructByName(tc.readType, tc.tag)
664 assert.NoError(t, err)
665
666 target := reflect.New(reflect.TypeOf(tc.readType))
667 var unmarshalErr error
668 assert.NotPanics(t, func() {
669 unmarshalErr = reader.Unmarshal(data, target.Interface())
670 })
671 if tc.unmarshalErrContains != "" {
672 if assert.Error(t, unmarshalErr) {
673 assert.Contains(t, unmarshalErr.Error(), tc.unmarshalErrContains)
674 }
675 return
676 }
677 assert.NoError(t, unmarshalErr)
678
679 tc.assertFunc(t, tc.input, target.Elem().Interface())
680}

Calls 11

NewForyWithOptionsFunction · 0.85
WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
KindMethod · 0.80
MarshalMethod · 0.80
UnmarshalMethod · 0.80
RegisterStructByNameMethod · 0.45
TypeMethod · 0.45
SetMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected