aboutsummaryrefslogtreecommitdiff
path: root/src/strings/builder_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/strings/builder_test.go')
-rw-r--r--src/strings/builder_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/strings/builder_test.go b/src/strings/builder_test.go
index 949f214619..9e597015d8 100644
--- a/src/strings/builder_test.go
+++ b/src/strings/builder_test.go
@@ -20,6 +20,9 @@ func check(t *testing.T, b *Builder, want string) {
if n := b.Len(); n != len(got) {
t.Errorf("Len: got %d; but len(String()) is %d", n, len(got))
}
+ if n := b.Cap(); n < len(got) {
+ t.Errorf("Cap: got %d; but len(String()) is %d", n, len(got))
+ }
}
func TestBuilder(t *testing.T) {
@@ -89,6 +92,9 @@ func TestBuilderGrow(t *testing.T) {
allocs := testing.AllocsPerRun(100, func() {
var b Builder
b.Grow(growLen) // should be only alloc, when growLen > 0
+ if b.Cap() < growLen {
+ t.Fatalf("growLen=%d: Cap() is lower than growLen", growLen)
+ }
b.Write(p)
if b.String() != string(p) {
t.Fatalf("growLen=%d: bad data written after Grow", growLen)
@@ -227,6 +233,16 @@ func TestBuilderCopyPanic(t *testing.T) {
},
},
{
+ name: "Cap",
+ wantPanic: false,
+ fn: func() {
+ var a Builder
+ a.WriteByte('x')
+ b := a
+ b.Cap()
+ },
+ },
+ {
name: "Reset",
wantPanic: false,
fn: func() {