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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [if.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
func assertequal(is, shouldbe int, msg string) {
10
        if is != shouldbe {
11
                print("assertion fail", msg, "\n")
12
                panic(1)
13
        }
14
}
15
 
16
func main() {
17
        i5 := 5
18
        i7 := 7
19
 
20
        var count int
21
 
22
        count = 0
23
        if true {
24
                count = count + 1
25
        }
26
        assertequal(count, 1, "if true")
27
 
28
        count = 0
29
        if false {
30
                count = count + 1
31
        }
32
        assertequal(count, 0, "if false")
33
 
34
        count = 0
35
        if one := 1; true {
36
                count = count + one
37
        }
38
        assertequal(count, 1, "if true one")
39
 
40
        count = 0
41
        if one := 1; false {
42
                count = count + 1
43
                _ = one
44
        }
45
        assertequal(count, 0, "if false one")
46
 
47
        count = 0
48
        if i5 < i7 {
49
                count = count + 1
50
        }
51
        assertequal(count, 1, "if cond")
52
 
53
        count = 0
54
        if true {
55
                count = count + 1
56
        } else {
57
                count = count - 1
58
        }
59
        assertequal(count, 1, "if else true")
60
 
61
        count = 0
62
        if false {
63
                count = count + 1
64
        } else {
65
                count = count - 1
66
        }
67
        assertequal(count, -1, "if else false")
68
 
69
        count = 0
70
        if t := 1; false {
71
                count = count + 1
72
                _ = t
73
                t := 7
74
                _ = t
75
        } else {
76
                count = count - t
77
        }
78
        assertequal(count, -1, "if else false var")
79
 
80
        count = 0
81
        t := 1
82
        if false {
83
                count = count + 1
84
                t := 7
85
                _ = t
86
        } else {
87
                count = count - t
88
        }
89
        _ = t
90
        assertequal(count, -1, "if else false var outside")
91
}

powered by: WebSVN 2.1.0

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