github.com/dubbogo/gost@v1.14.0/bytes/buffer_test.go (about)

     1  // Copyright 2009 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  /*
     6   * Licensed to the Apache Software Foundation (ASF) under one or more
     7   * contributor license agreements.  See the NOTICE file distributed with
     8   * this work for additional information regarding copyright ownership.
     9   * The ASF licenses this file to You under the Apache License, Version 2.0
    10   * (the "License"); you may not use this file except in compliance with
    11   * the License.  You may obtain a copy of the License at
    12   *
    13   *     http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   */
    21  
    22  package gxbytes
    23  
    24  import (
    25  	"testing"
    26  )
    27  
    28  import (
    29  	"github.com/stretchr/testify/assert"
    30  )
    31  
    32  func TestBufferWithPeek(t *testing.T) {
    33  	var b Buffer
    34  	b.WriteString("hello")
    35  
    36  	b1 := b
    37  	b1.WriteNextBegin(100)
    38  	assert.True(t, b.off == b1.off)
    39  	assert.True(t, b.lastRead == b1.lastRead)
    40  	assert.True(t, len(b.buf) == len(b1.buf))
    41  	assert.True(t, cap(b.buf) < cap(b1.buf))
    42  
    43  	// out of range
    44  	//l, err := b1.WriteNextEnd(101)
    45  	//assert.Zero(t, l)
    46  	//assert.NotNil(t, err)
    47  
    48  	l, err := b1.WriteNextEnd(99)
    49  	assert.Nil(t, err)
    50  	assert.True(t, l == 99)
    51  	assert.NotNil(t, b1.buf)
    52  }