2 // This tests excercises a number of switch things:
4 // Code to test for multiple-labels is different that
5 // code for a single label.
7 // Code for switching on strings is different from the integer
10 // nulls (for strings) need to be handled specially since ceq will
11 // throw an exception if there.
13 // null as a case statement needs to be caught specially
21 public const string One
= "one";
36 case 10: return 255-10;
37 case 11: return 255-11;
38 case 12: return 255-12;
39 case 13: return 255-13;
40 case 14: return 255-14;
41 case 15: return 255-15;
42 case 16: return 255-16;
43 case 17: return 255-17;
44 case 18: return 255-18;
45 case 19: return 255-19;
46 case 20: return 255-20;
47 case 21: return 255-21;
48 case 22: return 255-22;
49 case 23: return 255-23;
50 case 24: return 255-24;
51 case 25: return 255-25;
52 case 26: return 255-26;
53 case 27: return 255-27;
54 case 28: return 255-28;
55 case 29: return 255-29;
56 case 30: return 255-30;
57 case 31: return 255-31;
58 case 32: return 255-32;
59 case 33: return 255-33;
60 case 34: return 255-34;
61 case 35: return 255-35;
62 case 36: return 255-36;
63 case 37: return 255-37;
64 case 38: return 255-38;
65 case 39: return 255-39;
66 case 40: return 255-40;
67 case 41: return 255-41;
68 case 42: return 255-42;
69 case 43: return 255-43;
70 case 44: return 255-44;
71 case 45: return 255-45;
72 case 46: return 255-46;
73 case 47: return 255-47;
74 case 48: return 255-48;
75 case 49: return 255-49;
76 case 50: return 255-50;
77 case 51: return 255-51;
78 case 52: return 255-52;
79 case 53: return 255-53;
80 case 54: return 255-54;
81 case 55: return 255-55;
82 case 56: return 255-56;
83 case 57: return 255-57;
84 case 58: return 255-58;
85 case 59: return 255-59;
86 case 60: return 255-60;
87 case 61: return 255-61;
88 case 62: return 255-62;
89 case 63: return 255-63;
90 case 64: return 255-64;
91 case 65: return 255-65;
92 case 66: return 255-66;
93 case 67: return 255-67;
94 case 68: return 255-68;
95 case 69: return 255-69;
96 case 70: return 255-70;
97 case 71: return 255-71;
98 case 72: return 255-72;
99 case 73: return 255-73;
100 case 74: return 255-74;
101 case 75: return 255-75;
102 case 76: return 255-76;
103 case 77: return 255-77;
104 case 78: return 255-78;
105 case 79: return 255-79;
106 case 80: return 255-80;
107 case 81: return 255-81;
108 case 82: return 255-82;
109 case 83: return 255-83;
110 case 84: return 255-84;
111 case 85: return 255-85;
112 case 86: return 255-86;
113 case 87: return 255-87;
114 case 88: return 255-88;
115 case 89: return 255-89;
116 case 90: return 255-90;
117 case 91: return 255-91;
118 case 92: return 255-92;
119 case 93: return 255-93;
120 case 94: return 255-94;
121 case 95: return 255-95;
122 case 96: return 255-96;
123 case 97: return 255-97;
124 case 98: return 255-98;
125 case 99: return 255-99;
126 case 100: return 255-100;
127 case 101: return 255-101;
128 case 102: return 255-102;
129 case 103: return 255-103;
130 case 104: return 255-104;
131 case 105: return 255-105;
132 case 106: return 255-106;
133 case 107: return 255-107;
134 case 108: return 255-108;
135 case 109: return 255-109;
136 case 110: return 255-110;
137 case 111: return 255-111;
138 case 112: return 255-112;
139 case 113: return 255-113;
140 case 114: return 255-114;
141 case 115: return 255-115;
142 case 116: return 255-116;
143 case 117: return 255-117;
144 case 118: return 255-118;
145 case 119: return 255-119;
146 case 120: return 255-120;
147 case 121: return 255-121;
148 case 122: return 255-122;
149 case 123: return 255-123;
150 case 124: return 255-124;
151 case 125: return 255-125;
152 case 126: return 255-126;
153 case 127: return 255-127;
154 case 128: return 255-128;
155 case 129: return 255-129;
156 case 130: return 255-130;
157 case 131: return 255-131;
158 case 132: return 255-132;
159 case 133: return 255-133;
160 case 134: return 255-134;
161 case 135: return 255-135;
162 case 136: return 255-136;
163 case 137: return 255-137;
164 case 138: return 255-138;
165 case 139: return 255-139;
166 case 140: return 255-140;
167 case 141: return 255-141;
168 case 142: return 255-142;
169 case 143: return 255-143;
170 case 144: return 255-144;
171 case 145: return 255-145;
172 case 146: return 255-146;
173 case 147: return 255-147;
174 case 148: return 255-148;
175 case 149: return 255-149;
176 case 150: return 255-150;
177 case 151: return 255-151;
178 case 152: return 255-152;
179 case 153: return 255-153;
180 case 154: return 255-154;
181 case 155: return 255-155;
182 case 156: return 255-156;
183 case 157: return 255-157;
184 case 158: return 255-158;
185 case 159: return 255-159;
186 case 160: return 255-160;
187 case 161: return 255-161;
188 case 162: return 255-162;
189 case 163: return 255-163;
190 case 164: return 255-164;
191 case 165: return 255-165;
192 case 166: return 255-166;
193 case 167: return 255-167;
194 case 168: return 255-168;
195 case 169: return 255-169;
196 case 170: return 255-170;
197 case 171: return 255-171;
198 case 172: return 255-172;
199 case 173: return 255-173;
200 case 174: return 255-174;
201 case 175: return 255-175;
202 case 176: return 255-176;
203 case 177: return 255-177;
204 case 178: return 255-178;
205 case 179: return 255-179;
206 case 180: return 255-180;
207 case 181: return 255-181;
208 case 182: return 255-182;
209 case 183: return 255-183;
210 case 184: return 255-184;
211 case 185: return 255-185;
212 case 186: return 255-186;
213 case 187: return 255-187;
214 case 188: return 255-188;
215 case 189: return 255-189;
216 case 190: return 255-190;
217 case 191: return 255-191;
218 case 192: return 255-192;
219 case 193: return 255-193;
220 case 194: return 255-194;
221 case 195: return 255-195;
222 case 196: return 255-196;
223 case 197: return 255-197;
224 case 198: return 255-198;
225 case 199: return 255-199;
226 case 200: return 255-200;
227 case 201: return 255-201;
228 case 202: return 255-202;
229 case 203: return 255-203;
230 case 204: return 255-204;
231 case 205: return 255-205;
232 case 206: return 255-206;
233 case 207: return 255-207;
234 case 208: return 255-208;
235 case 209: return 255-209;
236 case 210: return 255-210;
237 case 211: return 255-211;
238 case 212: return 255-212;
239 case 213: return 255-213;
240 case 214: return 255-214;
241 case 215: return 255-215;
242 case 216: return 255-216;
243 case 217: return 255-217;
244 case 218: return 255-218;
245 case 219: return 255-219;
246 case 220: return 255-220;
247 case 221: return 255-221;
248 case 222: return 255-222;
249 case 223: return 255-223;
250 case 224: return 255-224;
251 case 225: return 255-225;
252 case 226: return 255-226;
253 case 227: return 255-227;
254 case 228: return 255-228;
255 case 229: return 255-229;
256 case 230: return 255-230;
257 case 231: return 255-231;
258 case 232: return 255-232;
259 case 233: return 255-233;
260 case 234: return 255-234;
261 case 235: return 255-235;
262 case 236: return 255-236;
263 case 237: return 255-237;
264 case 238: return 255-238;
265 case 239: return 255-239;
266 case 240: return 255-240;
267 case 241: return 255-241;
268 case 242: return 255-242;
269 case 243: return 255-243;
270 case 244: return 255-244;
271 case 245: return 255-245;
272 case 246: return 255-246;
273 case 247: return 255-247;
274 case 248: return 255-248;
275 case 249: return 255-249;
276 case 250: return 255-250;
277 case 251: return 255-251;
278 case 252: return 255-252;
279 case 253: return 255-253;
280 case 254: return 255-254;
281 case 255: return 255-255;
287 static int test (int v
)
289 Console
.WriteLine ("value: " + v
);
302 Console
.WriteLine ("default");
309 static int tests (string s
)
330 static int testn (string s
)
342 static int testm (string s
)
351 static int testo (string s
)
362 static int testp (string s
)
375 static int test_def (string s
)
390 static int test_coverage (int x
)
400 static int test_goto (int a
)
414 static int test_memberaccess (string s
)
424 static int test_string_multiple_targets (string s
)
442 static int test_casts (int n
)
445 case (int) (char) (int) My
.A
:
453 public enum TestEnum
: long {
457 public static int testSwitchEnumLong (TestEnum c
)
468 goto case TestEnum
.b
;
476 static int test_long_enum_switch ()
478 if (testSwitchEnumLong (TestEnum
.a
) != 10)
480 if (testSwitchEnumLong (TestEnum
.b
) != 20)
482 if (testSwitchEnumLong (TestEnum
.c
) != 20)
484 if (testSwitchEnumLong ((TestEnum
)5) != 40)
489 static int tests_default (string s
)
491 // tests default in the middle of the switch
504 static int tests_default_2 (string foo
)
519 static void test_76590 (string s
)
534 static void test_77964()
547 static bool bug_78860()
549 string model
= "TSP100";
551 System
.Console
.WriteLine("switch on '{0}'", model
);
567 for (b
= 0; b
< 255; b
++){
568 if (s (b
) != 255 - b
){
569 Console
.WriteLine ("Failed with: " + b
+ " [" + s (b
) + "]");
574 Console
.WriteLine ("Batch 2");
586 if (tests ("one") != 1)
588 if (tests ("two") != 1)
590 if (tests ("three") != 3)
592 if (tests ("four") != 5)
594 if (tests (null) != 9)
596 if (tests ("blah") != 6)
598 if (tests ("new") != 9)
602 if (testn ("one") != 1)
604 if (testn ("hello") != 0)
606 if (testn (null) != 0)
609 if (testm ("one") != 1)
611 if (testm ("two") != 100)
613 if (testm (null) != 100)
616 if (testo ("one") != 1)
618 if (testo ("two") != 2)
620 if (testo (null) != 100)
623 if (testp ("one") != 1)
625 if (testp (null) != 1)
627 if (testp ("two") != 1)
629 if (testp ("three") != 3)
631 if (testp ("blah") != 4)
634 if (test_def ("one") != 3)
636 if (test_def ("two") != 1)
638 if (test_def ("three") != 2)
640 if (test_def (null) != 3)
643 if (test_coverage (100) != 10)
646 if (test_goto (0) != 20)
648 if (test_goto (1) != 10)
650 if (test_goto (2) != 20)
652 if (test_goto (200) != 100)
655 if (test_memberaccess ("one") != 3)
658 if (test_string_multiple_targets ("A") != 1)
660 if (test_string_multiple_targets ("B") != 2)
662 if (test_string_multiple_targets ("C") != 3)
664 if (test_string_multiple_targets ("D") != 3)
666 if (test_string_multiple_targets ("E") != 0)
669 if (test_casts (0) != 1)
672 if (test_long_enum_switch () != 0)
675 if (tests_default (null) != 1)
677 if (tests_default ("hello") != 1)
679 if (tests_default ("world") != 1)
681 if (tests_default ("how") != 2)
684 if (tests_default_2 ("Test") != 1)
686 if (tests_default_2 ("foo") != 2)
688 if (tests_default_2 ("Hello") != 3)
690 if (tests_default_2 ("Monkey") != 3)
696 Console
.WriteLine ("All tests pass");