MCPcopy Create free account
hub / github.com/valyala/bytebufferpool / TestByteBufferReadFrom

Function TestByteBufferReadFrom

bytebuffer_test.go:11–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestByteBufferReadFrom(t *testing.T) {
12 prefix := "foobar"
13 expectedS := "asadfsdafsadfasdfisdsdfa"
14 prefixLen := int64(len(prefix))
15 expectedN := int64(len(expectedS))
16
17 var bb ByteBuffer
18 bb.WriteString(prefix)
19
20 rf := (io.ReaderFrom)(&bb)
21 for i := 0; i < 20; i++ {
22 r := bytes.NewBufferString(expectedS)
23 n, err := rf.ReadFrom(r)
24 if n != expectedN {
25 t.Fatalf("unexpected n=%d. Expecting %d. iteration %d", n, expectedN, i)
26 }
27 if err != nil {
28 t.Fatalf("unexpected error: %s", err)
29 }
30 bbLen := int64(bb.Len())
31 expectedLen := prefixLen + int64(i+1)*expectedN
32 if bbLen != expectedLen {
33 t.Fatalf("unexpected byteBuffer length: %d. Expecting %d", bbLen, expectedLen)
34 }
35 for j := 0; j < i; j++ {
36 start := prefixLen + int64(j)*expectedN
37 b := bb.B[start : start+expectedN]
38 if string(b) != expectedS {
39 t.Fatalf("unexpected byteBuffer contents: %q. Expecting %q", b, expectedS)
40 }
41 }
42 }
43}
44
45func TestByteBufferWriteTo(t *testing.T) {
46 expectedS := "foobarbaz"

Callers

nothing calls this directly

Calls 3

WriteStringMethod · 0.95
LenMethod · 0.95
ReadFromMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…