1
2
3
4
5 package test
6
7 import "testing"
8
9 const arrFooSize = 96
10
11 type arrFoo [arrFooSize]int
12
13
14 func badCopy(dst, src []int) {
15 p := (*[arrFooSize]int)(dst[:arrFooSize])
16 q := (*[arrFooSize]int)(src[:arrFooSize])
17 *p = arrFoo(*q)
18 }
19
20
21 func goodCopy(dst, src []int) {
22 p := (*[arrFooSize]int)(dst[:arrFooSize])
23 q := (*[arrFooSize]int)(src[:arrFooSize])
24 *p = *q
25 }
26
27 func TestOverlapedMoveWithNoopIConv(t *testing.T) {
28 h1 := make([]int, arrFooSize+1)
29 h2 := make([]int, arrFooSize+1)
30 for i := range arrFooSize + 1 {
31 h1[i] = i
32 h2[i] = i
33 }
34 badCopy(h1[1:], h1[:arrFooSize])
35 goodCopy(h2[1:], h2[:arrFooSize])
36 for i := range arrFooSize + 1 {
37 if h1[i] != h2[i] {
38 t.Errorf("h1 and h2 differ at index %d, expect them to be the same", i)
39 }
40 }
41 }
42
View as plain text