1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
11
func TestForwardCopy(t *testing.T) {
12
testCases := []struct {
17
{0, 9, 0, 9, "012345678"},
18
{0, 5, 4, 9, "45678"},
19
{4, 9, 0, 5, "01230"},
20
{1, 6, 3, 8, "34567"},
21
{3, 8, 1, 6, "12121"},
24
{1, 6, 0, 9, "00000"},
31
for _, tc := range testCases {
32
b := []byte("0123456789")
33
dst := b[tc.dst0:tc.dst1]
34
src := b[tc.src0:tc.src1]
35
n := forwardCopy(dst, src)
36
got := string(dst[:n])
38
t.Errorf("dst=b[%d:%d], src=b[%d:%d]: got %q, want %q",
39
tc.dst0, tc.dst1, tc.src0, tc.src1, got, tc.want)
41
// Check that the bytes outside of dst[:n] were not modified.
43
if i >= tc.dst0 && i < tc.dst0+n {
47
t.Errorf("dst=b[%d:%d], src=b[%d:%d]: copy overrun at b[%d]: got '%c', want '%c'",
48
tc.dst0, tc.dst1, tc.src0, tc.src1, i, x, '0'+i)