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

Function TestReadInt64Bytes

msgp/read_bytes_test.go:269–322  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

267}
268
269func TestReadInt64Bytes(t *testing.T) {
270 var buf bytes.Buffer
271 wr := NewWriter(&buf)
272
273 ints := []int64{
274 -100000, -5000, -5, 0, 8, 240, int64(tuint16), int64(tuint32), int64(tuint64),
275 -5, -30, 0, 1, 127, 300, 40921, 34908219,
276 }
277
278 uints := []uint64{0, 8, 240, uint64(tuint16), uint64(tuint32), tuint64}
279
280 all := make([]any, 0, len(ints)+len(uints))
281 for _, v := range ints {
282 all = append(all, v)
283 }
284 for _, v := range uints {
285 all = append(all, v)
286 }
287
288 for i, num := range all {
289 buf.Reset()
290 var err error
291
292 var in int64
293 switch num := num.(type) {
294 case int64:
295 err = wr.WriteInt64(num)
296 in = num
297 case uint64:
298 err = wr.WriteUint64(num)
299 in = int64(num)
300 default:
301 panic(num)
302 }
303 if err != nil {
304 t.Fatal(err)
305 }
306 err = wr.Flush()
307 if err != nil {
308 t.Fatal(err)
309 }
310
311 out, left, err := ReadInt64Bytes(buf.Bytes())
312 if out != in {
313 t.Errorf("Test case %d: put %d in and got %d out", i, num, in)
314 }
315 if err != nil {
316 t.Errorf("test case %d: %s", i, err)
317 }
318 if len(left) != 0 {
319 t.Errorf("expected 0 bytes left; found %d", len(left))
320 }
321 }
322}
323
324func TestReadUint64Bytes(t *testing.T) {
325 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 6

WriteInt64Method · 0.95
WriteUint64Method · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
ReadInt64BytesFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…