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

Function TestReadString

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

Source from the content-addressed store, hash-verified

748}
749
750func TestReadString(t *testing.T) {
751 var buf bytes.Buffer
752 wr := NewWriter(&buf)
753 rd := NewReader(&buf)
754
755 sizes := []int{0, 1, 225, int(math.MaxUint16 + 5)}
756 for i, size := range sizes {
757 buf.Reset()
758 in := string(RandBytes(size))
759
760 err := wr.WriteString(in)
761 if err != nil {
762 t.Fatal(err)
763 }
764 err = wr.Flush()
765 if err != nil {
766 t.Fatal(err)
767 }
768
769 out, err := rd.ReadString()
770 if err != nil {
771 t.Errorf("test case %d: %s", i, err)
772 }
773 if out != in {
774 t.Errorf("test case %d: strings not equal.", i)
775 t.Errorf("string (len = %d) in; string (len = %d) out", size, len(out))
776 }
777
778 }
779}
780
781func benchString(size uint32, b *testing.B) {
782 str := string(RandBytes(int(size)))

Callers

nothing calls this directly

Calls 7

WriteStringMethod · 0.95
FlushMethod · 0.95
ReadStringMethod · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
RandBytesFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…