-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_test.go
97 lines (91 loc) · 1.43 KB
/
reader_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package reversereader
import (
"bytes"
"io"
"reflect"
"testing"
)
func Test_reader_Read(t *testing.T) {
type in struct {
rs io.ReadSeeker
p []byte
}
type out struct {
p []byte
n int
err error
}
cases := []struct {
in in
exp out
}{
{
in: in{
rs: bytes.NewReader([]byte{0x01, 0x02, 0x03, 0x04}),
p: make([]byte, 0),
},
exp: out{
p: []byte{},
n: 0,
err: nil,
},
},
{
in: in{
rs: bytes.NewReader([]byte{0x01, 0x02, 0x03, 0x04}),
p: make([]byte, 5),
},
exp: out{
p: []byte{0x04, 0x03, 0x02, 0x01, 0x00},
n: 4,
err: io.EOF,
},
},
{
in: in{
rs: bytes.NewReader([]byte{0x01, 0x02, 0x03, 0x04}),
p: make([]byte, 4),
},
exp: out{
p: []byte{0x04, 0x03, 0x02, 0x01},
n: 4,
err: io.EOF,
},
},
{
in: in{
rs: bytes.NewReader([]byte{0x01, 0x02, 0x03, 0x04}),
p: make([]byte, 3),
},
exp: out{
p: []byte{0x04, 0x03, 0x02},
n: 3,
err: nil,
},
},
{
in: in{
rs: bytes.NewReader([]byte{}),
p: make([]byte, 1),
},
exp: out{
p: []byte{0x00},
n: 0,
err: io.EOF,
},
},
}
for i, c := range cases {
r := NewReader(c.in.rs)
n, err := r.Read(c.in.p)
act := out{
p: c.in.p,
n: n,
err: err,
}
exp := c.exp
if !reflect.DeepEqual(act, exp) {
t.Errorf("\n index: %d\n actual: %#v\nexpected: %#v\n", i, act, exp)
}
}
}