summaryrefslogtreecommitdiffstats
path: root/src/internal/poll/writev_test.go
blob: b46657ce960239c67dff21e0926be3bdebd3a96c (plain)
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
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package poll_test

import (
	"internal/poll"
	"reflect"
	"testing"
)

func TestConsume(t *testing.T) {
	tests := []struct {
		in      [][]byte
		consume int64
		want    [][]byte
	}{
		{
			in:      [][]byte{[]byte("foo"), []byte("bar")},
			consume: 0,
			want:    [][]byte{[]byte("foo"), []byte("bar")},
		},
		{
			in:      [][]byte{[]byte("foo"), []byte("bar")},
			consume: 2,
			want:    [][]byte{[]byte("o"), []byte("bar")},
		},
		{
			in:      [][]byte{[]byte("foo"), []byte("bar")},
			consume: 3,
			want:    [][]byte{[]byte("bar")},
		},
		{
			in:      [][]byte{[]byte("foo"), []byte("bar")},
			consume: 4,
			want:    [][]byte{[]byte("ar")},
		},
		{
			in:      [][]byte{nil, nil, nil, []byte("bar")},
			consume: 1,
			want:    [][]byte{[]byte("ar")},
		},
		{
			in:      [][]byte{nil, nil, nil, []byte("foo")},
			consume: 0,
			want:    [][]byte{[]byte("foo")},
		},
		{
			in:      [][]byte{nil, nil, nil},
			consume: 0,
			want:    [][]byte{},
		},
	}
	for i, tt := range tests {
		in := tt.in
		poll.Consume(&in, tt.consume)
		if !reflect.DeepEqual(in, tt.want) {
			t.Errorf("%d. after consume(%d) = %+v, want %+v", i, tt.consume, in, tt.want)
		}
	}
}