gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/internal/poll/writev_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package poll_test
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  
    11  	"gitee.com/ks-custle/core-gm/internal/poll"
    12  )
    13  
    14  func TestConsume(t *testing.T) {
    15  	tests := []struct {
    16  		in      [][]byte
    17  		consume int64
    18  		want    [][]byte
    19  	}{
    20  		{
    21  			in:      [][]byte{[]byte("foo"), []byte("bar")},
    22  			consume: 0,
    23  			want:    [][]byte{[]byte("foo"), []byte("bar")},
    24  		},
    25  		{
    26  			in:      [][]byte{[]byte("foo"), []byte("bar")},
    27  			consume: 2,
    28  			want:    [][]byte{[]byte("o"), []byte("bar")},
    29  		},
    30  		{
    31  			in:      [][]byte{[]byte("foo"), []byte("bar")},
    32  			consume: 3,
    33  			want:    [][]byte{[]byte("bar")},
    34  		},
    35  		{
    36  			in:      [][]byte{[]byte("foo"), []byte("bar")},
    37  			consume: 4,
    38  			want:    [][]byte{[]byte("ar")},
    39  		},
    40  		{
    41  			in:      [][]byte{nil, nil, nil, []byte("bar")},
    42  			consume: 1,
    43  			want:    [][]byte{[]byte("ar")},
    44  		},
    45  		{
    46  			in:      [][]byte{nil, nil, nil, []byte("foo")},
    47  			consume: 0,
    48  			want:    [][]byte{[]byte("foo")},
    49  		},
    50  		{
    51  			in:      [][]byte{nil, nil, nil},
    52  			consume: 0,
    53  			want:    [][]byte{},
    54  		},
    55  	}
    56  	for i, tt := range tests {
    57  		in := tt.in
    58  		poll.Consume(&in, tt.consume)
    59  		if !reflect.DeepEqual(in, tt.want) {
    60  			t.Errorf("%d. after consume(%d) = %+v, want %+v", i, tt.consume, in, tt.want)
    61  		}
    62  	}
    63  }