]> Cypherpunks.ru repositories - gostls13.git/blob - test/complit.go
change *map to map; *chan to chan; new(T) to new(*T)
[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         //a3 := [10]int{1,2,3,};  // BUG: trailing commas not allowed
42         //if len(a3) != 10 || a2[3] != 0 { panic("a3") }
43
44         var oai []int;
45         oai = &[]int{1,2,3};
46         if len(oai) != 3 { panic("oai") }
47
48         at := []*T{&t, &t, &t};
49         if len(at) != 3 { panic("at") }
50
51         c := new(chan int);
52         ac := []chan int{c, c, c};
53         if len(ac) != 3 { panic("ac") }
54
55         aat := [][len(at)]*T{at, at};
56         if len(aat) != 2 || len(aat[1]) != 3 { panic("at") }
57
58         s := string([]byte{'h', 'e', 'l', 'l', 'o'});
59         if s != "hello" { panic("s") }
60
61         m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.};
62         if len(m) != 3 { panic("m") }
63
64         eq(&[]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)});
65
66         p1 := NewP(1, 2);
67         p2 := NewP(1, 2);
68         if p1 == p2 { panic("NewP") }
69 }