diff options
Diffstat (limited to 'buffers_test.go')
| -rw-r--r-- | buffers_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/buffers_test.go b/buffers_test.go new file mode 100644 index 00000000..aae431e5 --- /dev/null +++ b/buffers_test.go @@ -0,0 +1,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") + } +} |
