testsuite: fix c23-constexpr-2a.c test to use dg-do run
[official-gcc.git] / gcc / testsuite / go.test / test / if.go
blob25cc141648b9a65b7555075ad947b1035ad3111d
1 // run
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 // Test if statements in various forms.
9 package main
11 func assertequal(is, shouldbe int, msg string) {
12 if is != shouldbe {
13 print("assertion fail", msg, "\n")
14 panic(1)
18 func main() {
19 i5 := 5
20 i7 := 7
22 var count int
24 count = 0
25 if true {
26 count = count + 1
28 assertequal(count, 1, "if true")
30 count = 0
31 if false {
32 count = count + 1
34 assertequal(count, 0, "if false")
36 count = 0
37 if one := 1; true {
38 count = count + one
40 assertequal(count, 1, "if true one")
42 count = 0
43 if one := 1; false {
44 count = count + 1
45 _ = one
47 assertequal(count, 0, "if false one")
49 count = 0
50 if i5 < i7 {
51 count = count + 1
53 assertequal(count, 1, "if cond")
55 count = 0
56 if true {
57 count = count + 1
58 } else {
59 count = count - 1
61 assertequal(count, 1, "if else true")
63 count = 0
64 if false {
65 count = count + 1
66 } else {
67 count = count - 1
69 assertequal(count, -1, "if else false")
71 count = 0
72 if t := 1; false {
73 count = count + 1
74 _ = t
75 t := 7
76 _ = t
77 } else {
78 count = count - t
80 assertequal(count, -1, "if else false var")
82 count = 0
83 t := 1
84 if false {
85 count = count + 1
86 t := 7
87 _ = t
88 } else {
89 count = count - t
91 _ = t
92 assertequal(count, -1, "if else false var outside")