summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.go-torture/execute/switch-1.go
blob: fdc93ce60ac5c2f328a7cfe310d0fcd665b7baed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main

func f1(i int) bool {
  switch j := i; j {
  case 3: fallthrough
  case 1: return true
  case 2: return false
  default: return false
  case 4: return true
  }
}

func f2(i int) int {
  switch {
    case i < 0: return -1
    case i > 0: return 1
    default: return 0
    case i != 0: return 1000
  }
  panic(0)
}

func f3(i int) int {
 lab:
  switch i {
    case 1: break
    case 2: return 2
    case 3, 4:
      switch i {
        case 3: break lab
        case 4: break
      }
      return 4
  }
  return 1
}

func main() {
  if !f1(1) {
    panic(1);
  }
  if f1(2) {
    panic(2);
  }
  if !f1(3) {
    panic(3);
  }
  if !f1(4) {
    panic(4);
  }
  if f1(5) {
    panic(5);
  }

  if f2(-100) != -1 {
    panic(6);
  }
  if f2(1000) != 1 {
    panic(7);
  }
  if f2(0) != 0 {
    panic(8);
  }

  if f3(1) != 1 || f3(2) != 2 || f3(3) != 1 || f3(4) != 4 {
    panic(9);
  }
}