-
Notifications
You must be signed in to change notification settings - Fork 2
/
buffer_test.go
48 lines (44 loc) · 900 Bytes
/
buffer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package redisgo
import (
"bytes"
"math/rand"
"testing"
)
func TestReader(t *testing.T) {
var b []byte
buf := make([]byte, 0, 1<<20)
for i := 0; i < 10000; i++ {
b = make([]byte, 1+rand.Intn(100))
rand.Read(b)
buf = append(buf, b...)
if i%100 == 0 {
buf = append(buf, CR, LF)
}
}
buf = append(buf, CR, LF)
r0 := newReader(bytes.NewReader(buf), 10)
buf0 := make([]byte, 0, 1<<20)
for {
b, err := r0.Readline()
if err != nil {
break
}
buf0 = append(buf0, b...)
}
if !bytes.Equal(buf, buf0) {
t.Fatal("not equal", len(buf), len(buf0))
}
r1 := newReader(bytes.NewReader(buf), 10)
buf1 := make([]byte, 0, 1<<20)
for {
b, err := r1.Read(1 + rand.Intn(50))
if err != nil {
buf1 = append(buf1, r1.bytes()...)
break
}
buf1 = append(buf1, b...)
}
if !bytes.Equal(buf, buf1) {
t.Fatal("not equal", len(buf), len(buf1), "\n", buf, "\n", buf1)
}
}