1
2
3
4
5 package poll_test
6
7 import (
8 "internal/poll"
9 "reflect"
10 "testing"
11 )
12
13 func TestConsume(t *testing.T) {
14 tests := []struct {
15 in [][]byte
16 consume int64
17 want [][]byte
18 }{
19 {
20 in: [][]byte{[]byte("foo"), []byte("bar")},
21 consume: 0,
22 want: [][]byte{[]byte("foo"), []byte("bar")},
23 },
24 {
25 in: [][]byte{[]byte("foo"), []byte("bar")},
26 consume: 2,
27 want: [][]byte{[]byte("o"), []byte("bar")},
28 },
29 {
30 in: [][]byte{[]byte("foo"), []byte("bar")},
31 consume: 3,
32 want: [][]byte{[]byte("bar")},
33 },
34 {
35 in: [][]byte{[]byte("foo"), []byte("bar")},
36 consume: 4,
37 want: [][]byte{[]byte("ar")},
38 },
39 {
40 in: [][]byte{nil, nil, nil, []byte("bar")},
41 consume: 1,
42 want: [][]byte{[]byte("ar")},
43 },
44 {
45 in: [][]byte{nil, nil, nil, []byte("foo")},
46 consume: 0,
47 want: [][]byte{[]byte("foo")},
48 },
49 {
50 in: [][]byte{nil, nil, nil},
51 consume: 0,
52 want: [][]byte{},
53 },
54 }
55 for i, tt := range tests {
56 in := tt.in
57 poll.Consume(&in, tt.consume)
58 if !reflect.DeepEqual(in, tt.want) {
59 t.Errorf("%d. after consume(%d) = %+v, want %+v", i, tt.consume, in, tt.want)
60 }
61 }
62 }
63
View as plain text