File: copy_test.go

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,388 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (54 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (28)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package flate

import (
	"testing"
)

func TestForwardCopy(t *testing.T) {
	testCases := []struct {
		dst0, dst1 int
		src0, src1 int
		want       string
	}{
		{0, 9, 0, 9, "012345678"},
		{0, 5, 4, 9, "45678"},
		{4, 9, 0, 5, "01230"},
		{1, 6, 3, 8, "34567"},
		{3, 8, 1, 6, "12121"},
		{0, 9, 3, 6, "345"},
		{3, 6, 0, 9, "012"},
		{1, 6, 0, 9, "00000"},
		{0, 4, 7, 8, "7"},
		{0, 1, 6, 8, "6"},
		{4, 4, 6, 9, ""},
		{2, 8, 6, 6, ""},
		{0, 0, 0, 0, ""},
	}
	for _, tc := range testCases {
		b := []byte("0123456789")
		n := tc.dst1 - tc.dst0
		if tc.src1-tc.src0 < n {
			n = tc.src1 - tc.src0
		}
		forwardCopy(b, tc.dst0, tc.src0, n)
		got := string(b[tc.dst0 : tc.dst0+n])
		if got != tc.want {
			t.Errorf("dst=b[%d:%d], src=b[%d:%d]: got %q, want %q",
				tc.dst0, tc.dst1, tc.src0, tc.src1, got, tc.want)
		}
		// Check that the bytes outside of dst[:n] were not modified.
		for i, x := range b {
			if i >= tc.dst0 && i < tc.dst0+n {
				continue
			}
			if int(x) != '0'+i {
				t.Errorf("dst=b[%d:%d], src=b[%d:%d]: copy overrun at b[%d]: got '%c', want '%c'",
					tc.dst0, tc.dst1, tc.src0, tc.src1, i, x, '0'+i)
			}
		}
	}
}