]> Cypherpunks.ru repositories - gostls13.git/blob - test/complit.go
convert composite literals from { } to ( ).
[gostls13.git] / test / complit.go
1 // $G $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 type T struct { i int; f float; s string; next *T }
10
11 type R struct { num int }
12
13 func itor(a int) *R {
14         r := new(R);
15         r.num = a;
16         return r;
17 }
18
19 func eq(a []*R) {
20         for i := 0; i < len(a); i++ {
21                 if a[i].num != i { panic("bad") }
22         }
23 }
24
25 type P struct { a, b int };
26 func NewP(a, b int) *P {
27         return &P(a, b)
28 }
29
30 func main() {
31         var t T;
32         t = T(0, 7.2, "hi", &t);
33
34         var tp *T;
35         tp = &T(0, 7.2, "hi", &t);
36
37         a1 := []int(1,2,3);
38         if len(a1) != 3 { panic("a1") }
39         a2 := [10]int(1,2,3);
40         if len(a2) != 10 || cap(a2) != 10 { panic("a2") }
41
42         a3 := [10]int(1,2,3,);
43         if len(a3) != 10 || a2[3] != 0 { panic("a3") }
44
45         var oai []int;
46         oai = []int(1,2,3);
47         if len(oai) != 3 { panic("oai") }
48
49         at := [...]*T(&t, &t, &t);
50         if len(at) != 3 { panic("at") }
51
52         c := make(chan int);
53         ac := []chan int(c, c, c);
54         if len(ac) != 3 { panic("ac") }
55
56         aat := [][len(at)]*T(at, at);
57         if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") }
58
59         s := string([]byte('h', 'e', 'l', 'l', 'o'));
60         if s != "hello" { panic("s") }
61
62         m := map[string]float("one":1.0, "two":2.0, "pi":22./7.);
63         if len(m) != 3 { panic("m") }
64
65         eq([]*R(itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)));
66
67         p1 := NewP(1, 2);
68         p2 := NewP(1, 2);
69         if p1 == p2 { panic("NewP") }
70 }