PR testsuite/86649
[official-gcc.git] / gcc / testsuite / go.test / test / complit.go
blob649be6d4d39ce02c2c4a8954680825a7f2ac00ed
1 // run
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.
7 // Test composite literals.
9 package main
11 type T struct {
12 i int
13 f float64
14 s string
15 next *T
18 type R struct {
19 num int
22 func itor(a int) *R {
23 r := new(R)
24 r.num = a
25 return r
28 func eq(a []*R) {
29 for i := 0; i < len(a); i++ {
30 if a[i].num != i {
31 panic("bad")
36 func teq(t *T, n int) {
37 for i := 0; i < n; i++ {
38 if t == nil || t.i != i {
39 panic("bad")
41 t = t.next
43 if t != nil {
44 panic("bad")
48 type P struct {
49 a, b int
52 func NewP(a, b int) *P {
53 return &P{a, b}
56 func main() {
57 var t T
58 t = T{0, 7.2, "hi", &t}
60 var tp *T
61 tp = &T{0, 7.2, "hi", &t}
63 tl := &T{i: 0, next: &T{i: 1, next: &T{i: 2, next: &T{i: 3, next: &T{i: 4}}}}}
64 teq(tl, 5)
66 a1 := []int{1, 2, 3}
67 if len(a1) != 3 {
68 panic("a1")
70 a2 := [10]int{1, 2, 3}
71 if len(a2) != 10 || cap(a2) != 10 {
72 panic("a2")
75 a3 := [10]int{1, 2, 3}
76 if len(a3) != 10 || a2[3] != 0 {
77 panic("a3")
80 var oai []int
81 oai = []int{1, 2, 3}
82 if len(oai) != 3 {
83 panic("oai")
86 at := [...]*T{&t, tp, &t}
87 if len(at) != 3 {
88 panic("at")
91 c := make(chan int)
92 ac := []chan int{c, c, c}
93 if len(ac) != 3 {
94 panic("ac")
97 aat := [][len(at)]*T{at, at}
98 if len(aat) != 2 || len(aat[1]) != 3 {
99 panic("aat")
102 s := string([]byte{'h', 'e', 'l', 'l', 'o'})
103 if s != "hello" {
104 panic("s")
107 m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.}
108 if len(m) != 3 {
109 panic("m")
112 eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
113 eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}})
115 p1 := NewP(1, 2)
116 p2 := NewP(1, 2)
117 if p1 == p2 {
118 panic("NewP")