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

Function TestReadInt64

msgp/read_test.go:428–474  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

426}
427
428func TestReadInt64(t *testing.T) {
429 var buf bytes.Buffer
430 wr := NewWriter(&buf)
431 rd := NewReader(&buf)
432
433 ints := []int64{-100000, -5000, -5, 0, 8, 240, int64(tuint16), int64(tuint32), int64(tuint64)}
434 uints := []uint64{0, 8, 240, uint64(tuint16), uint64(tuint32), tuint64}
435
436 all := make([]any, 0, len(ints)+len(uints))
437 for _, v := range ints {
438 all = append(all, v)
439 }
440 for _, v := range uints {
441 all = append(all, v)
442 }
443
444 for i, num := range all {
445 buf.Reset()
446 var err error
447
448 var in int64
449 switch num := num.(type) {
450 case int64:
451 err = wr.WriteInt64(num)
452 in = num
453 case uint64:
454 err = wr.WriteUint64(num)
455 in = int64(num)
456 default:
457 panic(num)
458 }
459 if err != nil {
460 t.Fatal(err)
461 }
462 err = wr.Flush()
463 if err != nil {
464 t.Fatal(err)
465 }
466 out, err := rd.ReadInt64()
467 if err != nil {
468 t.Fatal(err)
469 }
470 if out != in {
471 t.Errorf("Test case %d: put %d in and got %d out", i, num, in)
472 }
473 }
474}
475
476func TestReadIntOverflows(t *testing.T) {
477 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 7

WriteInt64Method · 0.95
WriteUint64Method · 0.95
FlushMethod · 0.95
ReadInt64Method · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…