github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/test/initialize.go (about)

     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  
     9  package main
    10  
    11  import "fmt"
    12  import "reflect"
    13  
    14  type S struct {
    15  	A, B, C, X, Y, Z int
    16  }
    17  
    18  type T struct {
    19  	S
    20  }
    21  
    22  var a1 = S { 0, 0, 0, 1, 2, 3 }
    23  var b1 = S { X: 1, Z: 3, Y: 2 }
    24  
    25  var a2 = S { 0, 0, 0, 0, 0, 0, }
    26  var b2 = S { }
    27  
    28  var a3 = T { S { 1, 2, 3, 0, 0, 0, } }
    29  var b3 = T { S: S{ A: 1, B: 2, C: 3 } }
    30  
    31  var a4 = &[16]byte { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
    32  var b4 = &[16]byte { 4: 1, 1, 1, 1, 12: 1, 1, }
    33  
    34  var a5 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
    35  var b5 = &[16]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, }
    36  
    37  var a6 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }
    38  var b6 = &[...]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, 0, 0,}
    39  
    40  type Same struct {
    41  	a, b interface{}
    42  }
    43  
    44  var 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  
    53  func 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  }