summaryrefslogtreecommitdiff
path: root/src/pkg/bytes/buffer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/bytes/buffer_test.go')
-rw-r--r--src/pkg/bytes/buffer_test.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/pkg/bytes/buffer_test.go b/src/pkg/bytes/buffer_test.go
index 509793d24..2af9ffdef 100644
--- a/src/pkg/bytes/buffer_test.go
+++ b/src/pkg/bytes/buffer_test.go
@@ -6,6 +6,7 @@ package bytes_test
import (
. "bytes"
+ "os"
"rand"
"testing"
"utf8"
@@ -238,7 +239,7 @@ func TestMixedReadsAndWrites(t *testing.T) {
func TestNil(t *testing.T) {
var b *Buffer
if b.String() != "<nil>" {
- t.Errorf("expcted <nil>; got %q", b.String())
+ t.Errorf("expected <nil>; got %q", b.String())
}
}
@@ -347,3 +348,27 @@ func TestNext(t *testing.T) {
}
}
}
+
+var readBytesTests = []struct {
+ buffer []byte
+ delim byte
+ expected []byte
+ err os.Error
+}{
+ {err: os.EOF},
+ {[]byte{}, 0, []byte{}, os.EOF},
+ {[]byte("a\x00"), 0, []byte("a\x00"), nil},
+ {[]byte("hello\x01world"), 1, []byte("hello\x01"), nil},
+ {[]byte("foo\nbar"), 0, []byte("foo\nbar"), os.EOF},
+ {[]byte("alpha beta gamma"), ' ', []byte("alpha "), nil},
+}
+
+func TestReadBytes(t *testing.T) {
+ for _, test := range readBytesTests {
+ buf := NewBuffer(test.buffer)
+ bytes, err := buf.ReadBytes(test.delim)
+ if !Equal(bytes, test.expected) || err != test.err {
+ t.Errorf("expected %q, %v got %q, %v", test.expected, test.err, bytes, err)
+ }
+ }
+}