blob: aae431e5007c2b4105d6d648fd1ac5e6b3f90ca5 (
about) (
plain) (
blame)
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
|
package furgit
import "testing"
func TestBorrowBodyResizeAndAppend(t *testing.T) {
b := borrowBody(1)
defer b.Release()
if cap(b.buf) < defaultBodyCap {
t.Fatalf("expected capacity >= %d, got %d", defaultBodyCap, cap(b.buf))
}
b.Append([]byte("alpha"))
b.Append([]byte("beta"))
if got := string(b.Bytes()); got != "alphabeta" {
t.Fatalf("unexpected contents: %q", got)
}
b.Resize(3)
if got := string(b.Bytes()); got != "alp" {
t.Fatalf("resize shrink mismatch: %q", got)
}
b.Resize(8)
if len(b.Bytes()) != 8 {
t.Fatalf("expected len 8 after grow, got %d", len(b.Bytes()))
}
if prefix := string(b.Bytes()[:3]); prefix != "alp" {
t.Fatalf("prefix lost after grow: %q", prefix)
}
}
func TestBorrowBodyRelease(t *testing.T) {
b := borrowBody(defaultBodyCap / 2)
b.Append([]byte("data"))
b.Release()
if b.buf != nil {
t.Fatal("expected buffer cleared after release")
}
}
|