}
func TestDeletePanics(t *testing.T) {
+ s := []int{0, 1, 2, 3, 4}
+ s = s[0:2]
+ _ = s[0:4] // this is a valid slice of s
+
for _, test := range []struct {
name string
s []int
{"with out-of-bounds first index", []int{42}, 2, 3},
{"with out-of-bounds second index", []int{42}, 0, 2},
{"with invalid i>j", []int{42}, 1, 0},
+ {"s[i:j] is valid and j > len(s)", s, 0, 4},
} {
if !panics(func() { Delete(test.s, test.i, test.j) }) {
t.Errorf("Delete %s: got no panic, want panic", test.name)
}
func TestReplacePanics(t *testing.T) {
+ s := []int{0, 1, 2, 3, 4}
+ s = s[0:2]
+ _ = s[0:4] // this is a valid slice of s
+
for _, test := range []struct {
name string
s, v []int
{"indexes out of order", []int{1, 2}, []int{3}, 2, 1},
{"large index", []int{1, 2}, []int{3}, 1, 10},
{"negative index", []int{1, 2}, []int{3}, -1, 2},
+ {"s[i:j] is valid and j > len(s)", s, nil, 0, 4},
} {
ss, vv := Clone(test.s), Clone(test.v)
if !panics(func() { Replace(ss, test.i, test.j, vv...) }) {