From 09f3ff174c6487bebc4a9a6adea6d74baf6a92cc Mon Sep 17 00:00:00 2001 From: cui fliter Date: Mon, 12 Sep 2022 15:50:04 +0000 Subject: [PATCH] strings: add a test case of growLen is negative Before committing, the test coverage of strings/builder.go is 97.4% After committing, the test coverage of strings/builder.go is 100% Change-Id: I22643b1c4632b5ca7ef98362f32bb85faae80bad GitHub-Last-Rev: 2a55ca3e33d3aabd2ccc047de580abcfe05d6bb4 GitHub-Pull-Request: golang/go#55004 Reviewed-on: https://go-review.googlesource.com/c/go/+/430156 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Tobias Klauser Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Jenny Rakoczy --- src/strings/builder_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/strings/builder_test.go b/src/strings/builder_test.go index e3d239266f..dbc2c1943b 100644 --- a/src/strings/builder_test.go +++ b/src/strings/builder_test.go @@ -109,6 +109,15 @@ func TestBuilderGrow(t *testing.T) { t.Errorf("growLen=%d: got %d allocs during Write; want %v", growLen, g, w) } } + // when growLen < 0, should panic + var a Builder + n := -1 + defer func() { + if r := recover(); r == nil { + t.Errorf("a.Grow(%d) should panic()", n) + } + }() + a.Grow(n) } func TestBuilderWrite2(t *testing.T) { -- 2.50.0