1
2
3
4
5
6
7
8
9 package test
10
11 import "testing"
12
13 type T1 struct {
14 x float32
15 a, b, c, d int16
16 }
17 type T2 struct {
18 x float32
19 a, b, c, d int32
20 }
21
22 type A2 [2]byte
23 type A4 [4]byte
24 type A8 [8]byte
25
26
27 func cmpT1(p, q *T1) {
28 if *p != *q {
29 panic("comparison test wrong")
30 }
31 }
32
33
34 func cmpT2(p, q *T2) {
35 if *p != *q {
36 panic("comparison test wrong")
37 }
38 }
39
40
41 func cmpA2(p, q *A2) {
42 if *p != *q {
43 panic("comparison test wrong")
44 }
45 }
46
47
48 func cmpA4(p, q *A4) {
49 if *p != *q {
50 panic("comparison test wrong")
51 }
52 }
53
54
55 func cmpA8(p, q *A8) {
56 if *p != *q {
57 panic("comparison test wrong")
58 }
59 }
60
61 func TestAlignEqual(t *testing.T) {
62 cmpT1(&T1{}, &T1{})
63 cmpT2(&T2{}, &T2{})
64
65 m1 := map[T1]bool{}
66 m1[T1{}] = true
67 m1[T1{}] = false
68 if len(m1) != 1 {
69 t.Fatalf("len(m1)=%d, want 1", len(m1))
70 }
71 m2 := map[T2]bool{}
72 m2[T2{}] = true
73 m2[T2{}] = false
74 if len(m2) != 1 {
75 t.Fatalf("len(m2)=%d, want 1", len(m2))
76 }
77
78 type X2 struct {
79 y byte
80 z A2
81 }
82 var x2 X2
83 cmpA2(&x2.z, &A2{})
84 type X4 struct {
85 y byte
86 z A4
87 }
88 var x4 X4
89 cmpA4(&x4.z, &A4{})
90 type X8 struct {
91 y byte
92 z A8
93 }
94 var x8 X8
95 cmpA8(&x8.z, &A8{})
96 }
97
View as plain text