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.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/pkg/bytes/buffer_test.go b/src/pkg/bytes/buffer_test.go
index d24bbbe4b..bc696f4b5 100644
--- a/src/pkg/bytes/buffer_test.go
+++ b/src/pkg/bytes/buffer_test.go
@@ -264,6 +264,7 @@ func TestWriteTo(t *testing.T) {
}
}
+
func TestRuneIO(t *testing.T) {
const NRune = 1000
// Built a test array while we write the data
@@ -297,3 +298,37 @@ func TestRuneIO(t *testing.T) {
}
}
}
+
+
+func TestNext(t *testing.T) {
+ b := []byte{0, 1, 2, 3, 4}
+ tmp := make([]byte, 5)
+ for i := 0; i <= 5; i++ {
+ for j := i; j <= 5; j++ {
+ for k := 0; k <= 6; k++ {
+ // 0 <= i <= j <= 5; 0 <= k <= 6
+ // Check that if we start with a buffer
+ // of length j at offset i and ask for
+ // Next(k), we get the right bytes.
+ buf := NewBuffer(b[0:j])
+ n, _ := buf.Read(tmp[0:i])
+ if n != i {
+ t.Fatalf("Read %d returned %d", i, n)
+ }
+ bb := buf.Next(k)
+ want := k
+ if want > j-i {
+ want = j - i
+ }
+ if len(bb) != want {
+ t.Fatalf("in %d,%d: len(Next(%d)) == %d", i, j, k, len(bb))
+ }
+ for l, v := range bb {
+ if v != byte(l+i) {
+ t.Fatalf("in %d,%d: Next(%d)[%d] = %d, want %d", i, j, k, l, v, l+i)
+ }
+ }
+ }
+ }
+ }
+}