OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [complit.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $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 {
10
        i    int
11
        f    float64
12
        s    string
13
        next *T
14
}
15
 
16
type R struct {
17
        num int
18
}
19
 
20
func itor(a int) *R {
21
        r := new(R)
22
        r.num = a
23
        return r
24
}
25
 
26
func eq(a []*R) {
27
        for i := 0; i < len(a); i++ {
28
                if a[i].num != i {
29
                        panic("bad")
30
                }
31
        }
32
}
33
 
34
func teq(t *T, n int) {
35
        for i := 0; i < n; i++ {
36
                if t == nil || t.i != i {
37
                        panic("bad")
38
                }
39
                t = t.next
40
        }
41
        if t != nil {
42
                panic("bad")
43
        }
44
}
45
 
46
type P struct {
47
        a, b int
48
}
49
 
50
func NewP(a, b int) *P {
51
        return &P{a, b}
52
}
53
 
54
func main() {
55
        var t T
56
        t = T{0, 7.2, "hi", &t}
57
 
58
        var tp *T
59
        tp = &T{0, 7.2, "hi", &t}
60
 
61
        tl := &T{i: 0, next: &T{i: 1, next: &T{i: 2, next: &T{i: 3, next: &T{i: 4}}}}}
62
        teq(tl, 5)
63
 
64
        a1 := []int{1, 2, 3}
65
        if len(a1) != 3 {
66
                panic("a1")
67
        }
68
        a2 := [10]int{1, 2, 3}
69
        if len(a2) != 10 || cap(a2) != 10 {
70
                panic("a2")
71
        }
72
 
73
        a3 := [10]int{1, 2, 3}
74
        if len(a3) != 10 || a2[3] != 0 {
75
                panic("a3")
76
        }
77
 
78
        var oai []int
79
        oai = []int{1, 2, 3}
80
        if len(oai) != 3 {
81
                panic("oai")
82
        }
83
 
84
        at := [...]*T{&t, tp, &t}
85
        if len(at) != 3 {
86
                panic("at")
87
        }
88
 
89
        c := make(chan int)
90
        ac := []chan int{c, c, c}
91
        if len(ac) != 3 {
92
                panic("ac")
93
        }
94
 
95
        aat := [][len(at)]*T{at, at}
96
        if len(aat) != 2 || len(aat[1]) != 3 {
97
                panic("aat")
98
        }
99
 
100
        s := string([]byte{'h', 'e', 'l', 'l', 'o'})
101
        if s != "hello" {
102
                panic("s")
103
        }
104
 
105
        m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.}
106
        if len(m) != 3 {
107
                panic("m")
108
        }
109
 
110
        eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
111
        eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}})
112
 
113
        p1 := NewP(1, 2)
114
        p2 := NewP(1, 2)
115
        if p1 == p2 {
116
                panic("NewP")
117
        }
118
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.