// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package io
+package bytes
import (
- "io";
+ "bytes";
"rand";
"testing";
)
// Verify that contents of buf match the string s.
-func check(t *testing.T, testname string, buf *ByteBuffer, s string) {
+func check(t *testing.T, testname string, buf *Buffer, s string) {
if buf.Len() != len(buf.Data()) {
t.Errorf("%s: buf.Len() == %d, len(buf.Data()) == %d\n", testname, buf.Len(), len(buf.Data()))
}
// Fill buf through n writes of fub.
// The initial contents of buf corresponds to the string s;
// the result is the final contents of buf returned as a string.
-func fill(t *testing.T, testname string, buf *ByteBuffer, s string, n int, fub []byte) string {
+func fill(t *testing.T, testname string, buf *Buffer, s string, n int, fub []byte) string {
check(t, testname + " (fill 1)", buf, s);
for ; n > 0; n-- {
m, err := buf.Write(fub);
// Empty buf through repeated reads into fub.
// The initial contents of buf corresponds to the string s.
-func empty(t *testing.T, testname string, buf *ByteBuffer, s string, fub []byte) {
+func empty(t *testing.T, testname string, buf *Buffer, s string, fub []byte) {
check(t, testname + " (empty 1)", buf, s);
for {
func TestBasicOperations(t *testing.T) {
- var buf ByteBuffer;
+ var buf Buffer;
for i := 0; i < 5; i++ {
check(t, "TestBasicOperations (1)", &buf, "");
func TestLargeWrites(t *testing.T) {
- var buf ByteBuffer;
+ var buf Buffer;
for i := 3; i < 30; i += 3 {
s := fill(t, "TestLargeWrites (1)", &buf, "", 5, data);
empty(t, "TestLargeWrites (2)", &buf, s, make([]byte, len(data)/i));
func TestLargeReads(t *testing.T) {
- var buf ByteBuffer;
+ var buf Buffer;
for i := 3; i < 30; i += 3 {
s := fill(t, "TestLargeReads (1)", &buf, "", 5, data[0 : len(data)/i]);
empty(t, "TestLargeReads (2)", &buf, s, make([]byte, len(data)));
func TestMixedReadsAndWrites(t *testing.T) {
- var buf ByteBuffer;
+ var buf Buffer;
s := "";
for i := 0; i < 50; i++ {
wlen := rand.Intn(len(data));