mirror of
https://github.com/valyala/bytebufferpool.git
synced 2026-06-26 15:16:21 +03:00
Added io.WriterTo implementation to ByteBuffer
This commit is contained in:
@@ -1,11 +1,37 @@
|
||||
package bytebufferpool
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestByteBufferWriteTo(t *testing.T) {
|
||||
expectedS := "foobarbaz"
|
||||
var bb ByteBuffer
|
||||
bb.WriteString(expectedS[:3])
|
||||
bb.WriteString(expectedS[3:])
|
||||
|
||||
wt := (io.WriterTo)(&bb)
|
||||
var w bytes.Buffer
|
||||
for i := 0; i < 10; i++ {
|
||||
n, err := wt.WriteTo(&w)
|
||||
if n != int64(len(expectedS)) {
|
||||
t.Fatalf("unexpected n returned from WriteTo: %d. Expecting %d", n, len(expectedS))
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
s := string(w.Bytes())
|
||||
if s != expectedS {
|
||||
t.Fatalf("unexpected string written %q. Expecting %q", s, expectedS)
|
||||
}
|
||||
w.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteBufferGetPutSerial(t *testing.T) {
|
||||
testByteBufferGetPut(t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user