(t *testing.T, tc compatibilityCase)
| 633 | } |
| 634 | |
| 635 | func 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 | } |
no test coverage detected