-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes_test.go
38 lines (30 loc) · 881 Bytes
/
bytes_test.go
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
// Copyright (c) 2023, Roel Schut. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package writing
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBytesBufferPool(t *testing.T) {
t.Run("init", func(t *testing.T) {
var p BytesBufferPool
assert.Equal(t, 0, p.Get().Cap())
})
t.Run("NewBytesBufferPool", func(t *testing.T) {
const n = 12
p := NewBytesBufferPool(n)
assert.True(t, p.Get().Cap() >= n)
})
}
func TestBytesBufferPool_Get(t *testing.T) {
var p BytesBufferPool
b := p.Get()
assert.Equal(t, 0, b.Cap())
const str = "dit is een hele lang test string met heel veel willekeurige woorden die nergens op slaan zolang de buffer maar groeit"
_, _ = b.WriteString(str)
assert.Equal(t, str, b.String())
p.Put(b)
b = p.Get()
assert.Equal(t, 0, b.Len())
}