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

Function TestReadUint64Bytes

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

Source from the content-addressed store, hash-verified

322}
323
324func TestReadUint64Bytes(t *testing.T) {
325 var buf bytes.Buffer
326 wr := NewWriter(&buf)
327
328 vs := []any{
329 int64(0), int64(8), int64(240), int64(tuint16), int64(tuint32), int64(tuint64),
330 uint64(0), uint64(8), uint64(240), uint64(tuint16), uint64(tuint32), tuint64,
331 uint64(math.MaxUint64),
332 }
333
334 for i, num := range vs {
335 buf.Reset()
336 var err error
337
338 var in uint64
339 switch num := num.(type) {
340 case int64:
341 err = wr.WriteInt64(num)
342 in = uint64(num)
343 case uint64:
344 err = wr.WriteUint64(num)
345 in = (num)
346 default:
347 panic(num)
348 }
349 if err != nil {
350 t.Fatal(err)
351 }
352 err = wr.Flush()
353 if err != nil {
354 t.Fatal(err)
355 }
356
357 out, left, err := ReadUint64Bytes(buf.Bytes())
358 if out != in {
359 t.Errorf("Test case %d: put %d in and got %d out", i, num, in)
360 }
361 if err != nil {
362 t.Errorf("test case %d: %s", i, err)
363 }
364 if len(left) != 0 {
365 t.Errorf("expected 0 bytes left; found %d", len(left))
366 }
367 }
368}
369
370func TestReadIntBytesOverflows(t *testing.T) {
371 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…