Source file
test/codegen/switch.go
1
2
3
4
5
6
7
8
9 package codegen
10
11
12 func f(x string) int {
13
14 switch x {
15 case "":
16 return -1
17 case "1", "2", "3":
18 return -2
19 default:
20 return -3
21 }
22 }
23
24
25 func square(x int) int {
26
27
28 switch x {
29 case 1:
30 return 1
31 case 2:
32 return 4
33 case 3:
34 return 9
35 case 4:
36 return 16
37 case 5:
38 return 25
39 case 6:
40 return 36
41 case 7:
42 return 49
43 case 8:
44 return 64
45 default:
46 return x * x
47 }
48 }
49
50
51 func length(x string) int {
52
53
54 switch x {
55 case "a":
56 return 1
57 case "bb":
58 return 2
59 case "ccc":
60 return 3
61 case "dddd":
62 return 4
63 case "eeeee":
64 return 5
65 case "ffffff":
66 return 6
67 case "ggggggg":
68 return 7
69 case "hhhhhhhh":
70 return 8
71 default:
72 return len(x)
73 }
74 }
75
76
77
78 func mimetype(ext string) string {
79
80
81 switch ext {
82
83
84 case ".htm":
85 return "A"
86
87
88 case ".eot":
89 return "B"
90
91
92 case ".svg":
93 return "C"
94
95
96 case ".ttf":
97 return "D"
98 default:
99 return ""
100 }
101 }
102
View as plain text