1// run
2
3// Copyright 2009 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Test initialization of package-level variables.
8
9package main
10
11import "fmt"
12import "reflect"
13
14type S struct {
15	A, B, C, X, Y, Z int
16}
17
18type T struct {
19	S
20}
21
22var a1 = S { 0, 0, 0, 1, 2, 3 }
23var b1 = S { X: 1, Z: 3, Y: 2 }
24
25var a2 = S { 0, 0, 0, 0, 0, 0, }
26var b2 = S { }
27
28var a3 = T { S { 1, 2, 3, 0, 0, 0, } }
29var b3 = T { S: S{ A: 1, B: 2, C: 3 } }
30
31var a4 = &[16]byte { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
32var b4 = &[16]byte { 4: 1, 1, 1, 1, 12: 1, 1, }
33
34var a5 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
35var b5 = &[16]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, }
36
37var a6 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
38var b6 = &[...]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, 0, 0,}
39
40type Same struct {
41	a, b interface{}
42}
43
44var same = []Same {
45	Same{ a1, b1 },
46	Same{ a2, b2 },
47	Same{ a3, b3 },
48	Same{ a4, b4 },
49	Same{ a5, b5 },
50	Same{ a6, b6 },
51}
52
53func main() {
54	ok := true
55	for _, s := range same {
56		if !reflect.DeepEqual(s.a, s.b) {
57			ok = false
58			fmt.Printf("not same: %v and %v\n", s.a, s.b)
59		}
60	}
61	if !ok {
62		fmt.Println("BUG: test/initialize")
63	}
64}
65