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

Function TestReadBytes

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

Source from the content-addressed store, hash-verified

681}
682
683func TestReadBytes(t *testing.T) {
684 var buf bytes.Buffer
685 wr := NewWriter(&buf)
686 rd := NewReader(&buf)
687
688 sizes := []int{0, 1, 225, int(tuint32)}
689 var scratch []byte
690 for i, size := range sizes {
691 buf.Reset()
692 bts := RandBytes(size)
693
694 err := wr.WriteBytes(bts)
695 if err != nil {
696 t.Fatal(err)
697 }
698 err = wr.Flush()
699 if err != nil {
700 t.Fatal(err)
701 }
702
703 out, err := rd.ReadBytes(scratch)
704 if err != nil {
705 t.Errorf("test case %d: %s", i, err)
706 continue
707 }
708
709 if !bytes.Equal(bts, out) {
710 t.Errorf("test case %d: Bytes not equal.", i)
711 }
712
713 }
714}
715
716func benchBytes(size uint32, b *testing.B) {
717 data := make([]byte, 0, size+5)

Callers

nothing calls this directly

Calls 8

WriteBytesMethod · 0.95
FlushMethod · 0.95
ReadBytesMethod · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
RandBytesFunction · 0.85
ResetMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…