(t *testing.T)
| 724 | } |
| 725 | |
| 726 | func TestAllowNilFunctionality(t *testing.T) { |
| 727 | // Test allownil functionality with DecodeMsg and UnmarshalMsg |
| 728 | |
| 729 | t.Run("AllowNil_NilValues_DecodeMsg", func(t *testing.T) { |
| 730 | data := AllowNilTestData{} |
| 731 | |
| 732 | // Create message with nil values for allownil fields |
| 733 | buf := msgp.AppendMapHeader(nil, 8) |
| 734 | |
| 735 | // NilSlice - send nil |
| 736 | buf = msgp.AppendString(buf, "nil_slice") |
| 737 | buf = msgp.AppendNil(buf) |
| 738 | |
| 739 | // NilTightSlice - send nil |
| 740 | buf = msgp.AppendString(buf, "nil_tight_slice") |
| 741 | buf = msgp.AppendNil(buf) |
| 742 | |
| 743 | // NilLooseSlice - send nil |
| 744 | buf = msgp.AppendString(buf, "nil_loose_slice") |
| 745 | buf = msgp.AppendNil(buf) |
| 746 | |
| 747 | // NilMap - send nil |
| 748 | buf = msgp.AppendString(buf, "nil_map") |
| 749 | buf = msgp.AppendNil(buf) |
| 750 | |
| 751 | // NilTightMap - send nil |
| 752 | buf = msgp.AppendString(buf, "nil_tight_map") |
| 753 | buf = msgp.AppendNil(buf) |
| 754 | |
| 755 | // NilLooseMap - send nil |
| 756 | buf = msgp.AppendString(buf, "nil_loose_map") |
| 757 | buf = msgp.AppendNil(buf) |
| 758 | |
| 759 | // RegularSlice - send empty slice |
| 760 | buf = msgp.AppendString(buf, "regular_slice") |
| 761 | buf = msgp.AppendBytes(buf, []byte{}) |
| 762 | |
| 763 | // RegularMap - send empty map |
| 764 | buf = msgp.AppendString(buf, "regular_map") |
| 765 | buf = msgp.AppendMapHeader(buf, 0) |
| 766 | |
| 767 | reader := msgp.NewReader(bytes.NewReader(buf)) |
| 768 | err := data.DecodeMsg(reader) |
| 769 | if err != nil { |
| 770 | t.Fatalf("DecodeMsg failed with allownil fields: %v", err) |
| 771 | } |
| 772 | |
| 773 | // Verify nil fields are properly handled |
| 774 | if data.NilSlice != nil { |
| 775 | t.Errorf("Expected NilSlice to be nil, got %v", data.NilSlice) |
| 776 | } |
| 777 | if data.NilTightSlice != nil { |
| 778 | t.Errorf("Expected NilTightSlice to be nil, got %v", data.NilTightSlice) |
| 779 | } |
| 780 | if data.NilLooseSlice != nil { |
| 781 | t.Errorf("Expected NilLooseSlice to be nil, got %v", data.NilLooseSlice) |
| 782 | } |
| 783 | if data.NilMap != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…