From: Jes Cok Date: Wed, 15 Nov 2023 23:18:20 +0000 (+0000) Subject: slices: add cases for TestInsertPanics when there are values X-Git-Tag: go1.22rc1~266 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3cdc2a13b9cc84b74c6914df1a50907f9410e772;p=gostls13.git slices: add cases for TestInsertPanics when there are values For #64152 Change-Id: I32531aa8d147f4f10f6498f5ea1474555e93b6de GitHub-Last-Rev: 48bb3bb05c6acc3761680a8a0eac9df9dfd154d3 GitHub-Pull-Request: golang/go#64180 Reviewed-on: https://go-review.googlesource.com/c/go/+/542535 TryBot-Result: Gopher Robot Run-TryBot: Jes Cok Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: David Chase --- diff --git a/src/slices/slices_test.go b/src/slices/slices_test.go index b86638172a..8772fe1f19 100644 --- a/src/slices/slices_test.go +++ b/src/slices/slices_test.go @@ -538,6 +538,7 @@ func TestInsertOverlap(t *testing.T) { func TestInsertPanics(t *testing.T) { a := [3]int{} + b := [1]int{} for _, test := range []struct { name string s []int @@ -549,6 +550,12 @@ func TestInsertPanics(t *testing.T) { {"with out-of-bounds index and > cap", a[:1:1], 2, nil}, {"with out-of-bounds index and = cap", a[:1:2], 2, nil}, {"with out-of-bounds index and < cap", a[:1:3], 2, nil}, + + // There are values. + {"with negative index", a[:1:1], -1, b[:]}, + {"with out-of-bounds index and > cap", a[:1:1], 2, b[:]}, + {"with out-of-bounds index and = cap", a[:1:2], 2, b[:]}, + {"with out-of-bounds index and < cap", a[:1:3], 2, b[:]}, } { if !panics(func() { Insert(test.s, test.i, test.v...) }) { t.Errorf("Insert %s: got no panic, want panic", test.name)