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

Function TestReadIntOverflows

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

Source from the content-addressed store, hash-verified

474}
475
476func TestReadIntOverflows(t *testing.T) {
477 var buf bytes.Buffer
478 wr := NewWriter(&buf)
479 rd := NewReader(&buf)
480
481 i8, i16, i32, i64, u8, u16, u32, u64 := 1, 2, 3, 4, 5, 6, 7, 8
482
483 overflowErr := func(err error, failBits int) bool {
484 bits := 0
485 switch err := err.(type) {
486 case IntOverflow:
487 bits = err.FailedBitsize
488 case UintOverflow:
489 bits = err.FailedBitsize
490 }
491 return bits == failBits
492 }
493
494 belowZeroErr := func(err error, failBits int) bool {
495 switch err.(type) {
496 case UintBelowZero:
497 return true
498 }
499 return false
500 }
501
502 vs := []struct {
503 v any
504 rdBits int
505 failBits int
506 errCheck func(err error, failBits int) bool
507 }{
508 {uint64(math.MaxInt64), i32, 32, overflowErr},
509 {uint64(math.MaxInt64), i16, 16, overflowErr},
510 {uint64(math.MaxInt64), i8, 8, overflowErr},
511
512 {uint64(math.MaxUint64), i64, 64, overflowErr},
513 {uint64(math.MaxUint64), i32, 64, overflowErr},
514 {uint64(math.MaxUint64), i16, 64, overflowErr},
515 {uint64(math.MaxUint64), i8, 64, overflowErr},
516
517 {uint64(math.MaxUint32), i32, 32, overflowErr},
518 {uint64(math.MaxUint32), i16, 16, overflowErr},
519 {uint64(math.MaxUint32), i8, 8, overflowErr},
520
521 {int64(math.MinInt64), u64, 64, belowZeroErr},
522 {int64(math.MinInt64), u32, 64, belowZeroErr},
523 {int64(math.MinInt64), u16, 64, belowZeroErr},
524 {int64(math.MinInt64), u8, 64, belowZeroErr},
525 {int64(math.MinInt32), u64, 64, belowZeroErr},
526 {int64(math.MinInt32), u32, 32, belowZeroErr},
527 {int64(math.MinInt32), u16, 16, belowZeroErr},
528 {int64(math.MinInt32), u8, 8, belowZeroErr},
529 {int64(math.MinInt16), u64, 64, belowZeroErr},
530 {int64(math.MinInt16), u32, 32, belowZeroErr},
531 {int64(math.MinInt16), u16, 16, belowZeroErr},
532 {int64(math.MinInt16), u8, 8, belowZeroErr},
533 {int64(math.MinInt8), u64, 64, belowZeroErr},

Callers

nothing calls this directly

Calls 13

WriteInt64Method · 0.95
WriteUint64Method · 0.95
FlushMethod · 0.95
ReadInt64Method · 0.95
ReadInt32Method · 0.95
ReadInt16Method · 0.95
ReadInt8Method · 0.95
ReadUint64Method · 0.95
ReadUint32Method · 0.95
ReadUint16Method · 0.95
ReadUint8Method · 0.95
NewWriterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…