X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fslices%2Fslices_test.go;h=2fc583ff909d048738d70590c55e94a4207770cd;hb=7a1fce8751b04f66f758c7aac0efd5937bc670dc;hp=7d4fc34b2e6bdbae2d6c52e14d11ad1acf7023b6;hpb=1cc19e5ba0a008df7baeb78e076e43f9d8e0abf2;p=gostls13.git diff --git a/src/slices/slices_test.go b/src/slices/slices_test.go index 7d4fc34b2e..2fc583ff90 100644 --- a/src/slices/slices_test.go +++ b/src/slices/slices_test.go @@ -659,6 +659,10 @@ func panics(f func()) (b bool) { } 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 @@ -669,6 +673,7 @@ func TestDeletePanics(t *testing.T) { {"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) @@ -928,6 +933,10 @@ func TestReplace(t *testing.T) { } 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 @@ -936,6 +945,7 @@ func TestReplacePanics(t *testing.T) { {"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...) }) {