Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out |
| 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 | package main |
| 8 | |
| 9 | import "fmt" |
| 10 | import "reflect" |
| 11 | |
| 12 | type S struct { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 13 | A, B, C, X, Y, Z int |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | type T struct { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 17 | S |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | var a1 = S { 0, 0, 0, 1, 2, 3 } |
| 21 | var b1 = S { X: 1, Z: 3, Y: 2 } |
| 22 | |
| 23 | var a2 = S { 0, 0, 0, 0, 0, 0, } |
Russ Cox | c2fa45b | 2009-05-21 16:31:10 -0700 | [diff] [blame] | 24 | var b2 = S { } |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 25 | |
| 26 | var a3 = T { S { 1, 2, 3, 0, 0, 0, } } |
Russ Cox | c2fa45b | 2009-05-21 16:31:10 -0700 | [diff] [blame] | 27 | var b3 = T { S: S{ A: 1, B: 2, C: 3 } } |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 28 | |
| 29 | var a4 = &[16]byte { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, } |
| 30 | var b4 = &[16]byte { 4: 1, 1, 1, 1, 12: 1, 1, } |
| 31 | |
| 32 | var a5 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, } |
| 33 | var b5 = &[16]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, } |
| 34 | |
| 35 | var a6 = &[16]byte { 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, } |
Russ Cox | c2fa45b | 2009-05-21 16:31:10 -0700 | [diff] [blame] | 36 | var b6 = &[...]byte { 1, 4: 1, 1, 1, 1, 12: 1, 1, 0, 0,} |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 37 | |
| 38 | type Same struct { |
| 39 | a, b interface{} |
| 40 | } |
| 41 | |
| 42 | var same = []Same { |
| 43 | Same{ a1, b1 }, |
| 44 | Same{ a2, b2 }, |
| 45 | Same{ a3, b3 }, |
| 46 | Same{ a4, b4 }, |
| 47 | Same{ a5, b5 }, |
| 48 | Same{ a6, b6 }, |
| 49 | } |
| 50 | |
| 51 | func main() { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 52 | ok := true |
Russ Cox | ae54cf7 | 2009-09-15 12:42:24 -0700 | [diff] [blame] | 53 | for _, s := range same { |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 54 | if !reflect.DeepEqual(s.a, s.b) { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 55 | ok = false |
| 56 | fmt.Printf("not same: %v and %v\n", s.a, s.b) |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | if !ok { |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 60 | fmt.Println("BUG: test/initialize") |
Russ Cox | d5269d0 | 2009-05-21 14:46:13 -0700 | [diff] [blame] | 61 | } |
| 62 | } |