Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / if.go
blobdb1fe8b790766ae744befcfaa01ce0f437496edd
1 // $G $F.go && $L $F.$A && ./$A.out
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 package main
9 func assertequal(is, shouldbe int, msg string) {
10 if is != shouldbe {
11 print("assertion fail", msg, "\n")
12 panic(1)
16 func main() {
17 i5 := 5
18 i7 := 7
20 var count int
22 count = 0
23 if true {
24 count = count + 1
26 assertequal(count, 1, "if true")
28 count = 0
29 if false {
30 count = count + 1
32 assertequal(count, 0, "if false")
34 count = 0
35 if one := 1; true {
36 count = count + one
38 assertequal(count, 1, "if true one")
40 count = 0
41 if one := 1; false {
42 count = count + 1
43 _ = one
45 assertequal(count, 0, "if false one")
47 count = 0
48 if {
49 count = count + 1
51 assertequal(count, 1, "if empty")
53 count = 0
54 if one := 1; true {
55 count = count + one
57 assertequal(count, 1, "if empty one")
59 count = 0
60 if i5 < i7 {
61 count = count + 1
63 assertequal(count, 1, "if cond")
65 count = 0
66 if true {
67 count = count + 1
68 } else
69 count = count - 1
70 assertequal(count, 1, "if else true")
72 count = 0
73 if false {
74 count = count + 1
75 } else
76 count = count - 1
77 assertequal(count, -1, "if else false")
79 count = 0
80 if t:=1; false {
81 count = count + 1
82 _ = t
83 t := 7
84 _ = t
85 } else
86 count = count - t
87 assertequal(count, -1, "if else false var")
89 count = 0
90 t := 1
91 if false {
92 count = count + 1
93 t := 7
94 _ = t
95 } else
96 count = count - t
97 _ = t
98 assertequal(count, -1, "if else false var outside")