2012-02-16 21:50:37 -07:00
|
|
|
// run
|
2009-05-21 15:46:13 -06:00
|
|
|
|
|
|
|
// Copyright 2009 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.
|
|
|
|
|
2012-02-23 00:47:26 -07:00
|
|
|
// Test initialization of package-level variables.
|
|
|
|
|
2009-05-21 15:46:13 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "reflect"
|
|
|
|
|
|
|
|
type S struct {
|
2010-09-03 18:36:13 -06:00
|
|
|
A, B, C, X, Y, Z int
|
2009-05-21 15:46:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type T struct {
|
2010-09-03 18:36:13 -06:00
|
|
|
S
|
2009-05-21 15:46:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var a1 = S { 0, 0, 0, 1, 2, 3 }
|
|
|
|
var b1 = S { X: 1, Z: 3, Y: 2 }
|
|
|
|
|
|
|
|
var a2 = S { 0, 0, 0, 0, 0, 0, }
|
2009-05-21 17:31:10 -06:00
|
|
|
var b2 = S { }
|
2009-05-21 15:46:13 -06:00
|
|
|
|
|
|
|
var a3 = T { S { 1, 2, 3, 0, 0, 0, } }
|
2009-05-21 17:31:10 -06:00
|
|
|
var b3 = T { S: S{ A: 1, B: 2, C: 3 } }
|
2009-05-21 15:46:13 -06:00
|
|
|
|
|
|
|
var a4 = &[16]byte { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
|
|
|
|
var b4 = &[16]byte { 4: 1, 1, 1, 1, 12: 1, 1, }
|
|
|
|
|
|
|
|
var a5 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
|
|
|
|
var b5 = &[16]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, }
|
|
|
|
|
|
|
|
var a6 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
|
2009-05-21 17:31:10 -06:00
|
|
|
var b6 = &[...]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, 0, 0,}
|
2009-05-21 15:46:13 -06:00
|
|
|
|
|
|
|
type Same struct {
|
|
|
|
a, b interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var same = []Same {
|
|
|
|
Same{ a1, b1 },
|
|
|
|
Same{ a2, b2 },
|
|
|
|
Same{ a3, b3 },
|
|
|
|
Same{ a4, b4 },
|
|
|
|
Same{ a5, b5 },
|
|
|
|
Same{ a6, b6 },
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-09-03 18:36:13 -06:00
|
|
|
ok := true
|
2009-09-15 13:42:24 -06:00
|
|
|
for _, s := range same {
|
2009-05-21 15:46:13 -06:00
|
|
|
if !reflect.DeepEqual(s.a, s.b) {
|
2010-09-03 18:36:13 -06:00
|
|
|
ok = false
|
|
|
|
fmt.Printf("not same: %v and %v\n", s.a, s.b)
|
2009-05-21 15:46:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !ok {
|
2010-09-03 18:36:13 -06:00
|
|
|
fmt.Println("BUG: test/initialize")
|
2009-05-21 15:46:13 -06:00
|
|
|
}
|
|
|
|
}
|