]> Cypherpunks repositories - gostls13.git/commitdiff
slices: add cases for TestInsertPanics when there are values
authorJes Cok <xigua67damn@gmail.com>
Wed, 15 Nov 2023 23:18:20 +0000 (23:18 +0000)
committerKeith Randall <khr@golang.org>
Fri, 17 Nov 2023 23:00:36 +0000 (23:00 +0000)
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 <gobot@golang.org>
Run-TryBot: Jes Cok <xigua67damn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/slices/slices_test.go

index b86638172a6858d4a3cb8aae2cab707824006bd8..8772fe1f1982eb0abd22a84666e0c27ec3391209 100644 (file)
@@ -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)