MCPcopy
hub / github.com/tinylib/msgp / TestString_NilHandling

Function TestString_NilHandling

msgp/setof/generated_test.go:110–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestString_NilHandling(t *testing.T) {
111 var nilSet String
112
113 // Test nil encoding
114 var buf bytes.Buffer
115 writer := msgp.NewWriter(&buf)
116 err := nilSet.EncodeMsg(writer)
117 if err != nil {
118 t.Fatalf("EncodeMsg failed for nil: %v", err)
119 }
120 writer.Flush()
121
122 // Test nil decoding
123 reader := msgp.NewReader(&buf)
124 var decoded String
125 err = decoded.DecodeMsg(reader)
126 if err != nil {
127 t.Fatalf("DecodeMsg failed for nil: %v", err)
128 }
129
130 if decoded != nil {
131 t.Fatal("expected nil, got non-nil")
132 }
133
134 // Test nil marshaling
135 data, err := nilSet.MarshalMsg(nil)
136 if err != nil {
137 t.Fatalf("MarshalMsg failed for nil: %v", err)
138 }
139
140 // Test nil unmarshaling
141 var unmarshaled String
142 _, err = unmarshaled.UnmarshalMsg(data)
143 if err != nil {
144 t.Fatalf("UnmarshalMsg failed for nil: %v", err)
145 }
146
147 if unmarshaled != nil {
148 t.Fatal("expected nil, got non-nil")
149 }
150
151 // Test AsSlice on nil
152 slice := nilSet.AsSlice()
153 if slice != nil {
154 t.Fatal("expected nil slice, got non-nil")
155 }
156
157 // Test FromSlice with nil
158 fromNilSlice := StringFromSlice(nil)
159 if fromNilSlice != nil {
160 t.Fatal("expected nil from nil slice, got non-nil")
161 }
162}
163
164func TestString_EmptySet(t *testing.T) {
165 set := make(String)

Callers

nothing calls this directly

Calls 9

EncodeMsgMethod · 0.95
FlushMethod · 0.95
DecodeMsgMethod · 0.95
MarshalMsgMethod · 0.95
UnmarshalMsgMethod · 0.95
AsSliceMethod · 0.95
NewWriterFunction · 0.92
NewReaderFunction · 0.92
StringFromSliceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…