TestStringSetMsgpEncodeDecodeMsg tests EncodeMsg/DecodeMsg for StringSet
(t *testing.T)
| 72 | |
| 73 | // TestStringSetMsgpEncodeDecodeMsg tests EncodeMsg/DecodeMsg for StringSet |
| 74 | func TestStringSetMsgpEncodeDecodeMsg(t *testing.T) { |
| 75 | testCases := []struct { |
| 76 | name string |
| 77 | set StringSet |
| 78 | }{ |
| 79 | { |
| 80 | name: "empty set", |
| 81 | set: NewStringSet(), |
| 82 | }, |
| 83 | { |
| 84 | name: "populated set", |
| 85 | set: CreateStringSet("alpha", "beta", "gamma"), |
| 86 | }, |
| 87 | } |
| 88 | |
| 89 | for _, tc := range testCases { |
| 90 | t.Run(tc.name, func(t *testing.T) { |
| 91 | var buf bytes.Buffer |
| 92 | writer := msgp.NewWriter(&buf) |
| 93 | |
| 94 | // Encode |
| 95 | err := tc.set.EncodeMsg(writer) |
| 96 | if err != nil { |
| 97 | t.Fatalf("EncodeMsg() error = %v", err) |
| 98 | } |
| 99 | writer.Flush() |
| 100 | |
| 101 | // Decode |
| 102 | reader := msgp.NewReader(&buf) |
| 103 | var decoded StringSet |
| 104 | err = decoded.DecodeMsg(reader) |
| 105 | if err != nil { |
| 106 | t.Fatalf("DecodeMsg() error = %v", err) |
| 107 | } |
| 108 | |
| 109 | if !tc.set.Equals(decoded) { |
| 110 | t.Errorf("EncodeMsg/DecodeMsg roundtrip failed: original=%v, decoded=%v", tc.set.ToSlice(), decoded.ToSlice()) |
| 111 | } |
| 112 | }) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // TestStringSetMsgpBinary tests MarshalBinary/UnmarshalBinary for StringSet |
| 117 | func TestStringSetMsgpBinary(t *testing.T) { |
nothing calls this directly
no test coverage detected