github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/bytearena_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/assert"
     7  )
     8  
     9  func TestByteArena(t *testing.T) {
    10  	a := NewByteArena(512, 16384)
    11  	n := 10
    12  	bytes := a.AllocBytes(n)
    13  	assert.Assert(t, len(bytes) == n && cap(bytes) == n)
    14  
    15  	cp := 10
    16  	bytes = make([]byte, cp)
    17  	assert.Assert(t, cap(bytes) == cp && cap(bytes[5:]) == cp-5)
    18  }