File: copy_test.go

package info (click to toggle)
gcc-avr 1%3A5.4.0%2BAtmel3.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 589,832 kB
  • sloc: ansic: 2,775,567; ada: 756,757; cpp: 723,977; f90: 117,673; asm: 66,896; makefile: 62,755; xml: 44,466; sh: 29,549; exp: 23,315; objc: 15,216; fortran: 10,901; pascal: 4,185; python: 4,093; perl: 2,969; awk: 2,811; ml: 2,385; cs: 879; yacc: 316; lex: 198; haskell: 112; lisp: 8
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)
			}
		}
	}
}