enum A {
a = 23333,
}
+ public const string One = "one";
static int s (byte b)
{
return 5;
case null:
return 9;
+ case "new":
+ goto case null;
default:
return 6;
}
}
return 4;
}
+
+ static int test_def (string s)
+ {
+ switch (s){
+ case "one":
+ goto default;
+ case "two":
+ return 1;
+ case "three":
+ return 2;
+ default:
+ return 3;
+ }
+ return 4;
+ }
+
+ static int test_coverage (int x)
+ {
+ switch (x){
+ case 0:
+ return 1;
+ default:
+ return 10;
+ }
+ }
+
+ static int test_goto (int a)
+ {
+ switch (a){
+ case 0:
+ goto case 2;
+ case 1:
+ return 10;
+ case 2:
+ return 20;
+ default:
+ return 100;
+ }
+ }
+
+ static int test_memberaccess (string s)
+ {
+ switch (s){
+ case X.One:
+ return 3;
+ default:
+ return 4;
+ }
+ }
+
+ static int test_string_multiple_targets (string s)
+ {
+ switch (s){
+ case "A":
+ return 1;
+ case "B":
+ return 2;
+ case "C":
+ case "D":
+ return 3;
+ }
+ return 0;
+ }
+
+ enum My : byte {
+ A
+ }
+
+ static int test_casts (int n)
+ {
+ switch (n) {
+ case (int) (char) (int) My.A:
+ return 1;
+
+ default:
+ return 2;
+ }
+ }
+
+ public enum TestEnum : long {
+ a, b, c
+ }
+
+ public static int testSwitchEnumLong (TestEnum c)
+ {
+
+ switch (c) {
+ case TestEnum.a:
+ return 10;
+
+ case TestEnum.b:
+ return 20;
+
+ case TestEnum.c:
+ goto case TestEnum.b;
+
+ default:
+ return 40;
+ }
+
+ }
+
+ static int test_long_enum_switch ()
+ {
+ if (testSwitchEnumLong (TestEnum.a) != 10)
+ return 1;
+ if (testSwitchEnumLong (TestEnum.b) != 20)
+ return 2;
+ if (testSwitchEnumLong (TestEnum.c) != 20)
+ return 3;
+ if (testSwitchEnumLong ((TestEnum)5) != 40)
+ return 4;
+ return 0;
+ }
+
+ static int tests_default (string s)
+ {
+ // tests default in the middle of the switch
+
+ switch (s){
+ default:
+ case "hello":
+ case "world":
+ return 1;
+ case "how":
+ return 2;
+ }
+ }
+
+ // Bug #74655
+ static int tests_default_2 (string foo)
+ {
+ switch (foo) {
+ case "Hello":
+ break;
+ default:
+ return 1;
+ case "foo":
+ return 2;
+ case "Monkey":
+ break;
+ }
+ return 3;
+ }
+
+ static void test_76590 (string s)
+ {
+ switch (s) {
+ case "null":
+ case (string)null:
+ break;
+
+ case "#":
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ static void test_77964()
+ {
+ char c = 'c';
+ switch (c)
+ {
+ case 'A':
+ break;
+
+ case 'a':
+ goto case 65;
+ }
+ }
+
+ static bool bug_78860()
+ {
+ string model = "TSP100";
+
+ System.Console.WriteLine("switch on '{0}'", model);
+
+ switch(model) {
+ case "wibble":
+ case null:
+ return false;
+ case "TSP100":
+ return true;
+ }
+ return false;
+ }
static int Main ()
{
return 10;
if (tests ("blah") != 6)
return 11;
+ if (tests ("new") != 9)
+ return 110;
+
if (testn ("one") != 1)
return 12;
if (testp ("blah") != 4)
return 25;
+ if (test_def ("one") != 3)
+ return 26;
+ if (test_def ("two") != 1)
+ return 27;
+ if (test_def ("three") != 2)
+ return 28;
+ if (test_def (null) != 3)
+ return 29;
+
+ if (test_coverage (100) != 10)
+ return 30;
+
+ if (test_goto (0) != 20)
+ return 31;
+ if (test_goto (1) != 10)
+ return 32;
+ if (test_goto (2) != 20)
+ return 33;
+ if (test_goto (200) != 100)
+ return 34;
+
+ if (test_memberaccess ("one") != 3)
+ return 35;
+
+ if (test_string_multiple_targets ("A") != 1)
+ return 36;
+ if (test_string_multiple_targets ("B") != 2)
+ return 37;
+ if (test_string_multiple_targets ("C") != 3)
+ return 38;
+ if (test_string_multiple_targets ("D") != 3)
+ return 39;
+ if (test_string_multiple_targets ("E") != 0)
+ return 40;
+
+ if (test_casts (0) != 1)
+ return 41;
+
+ if (test_long_enum_switch () != 0)
+ return 42;
+
+ if (tests_default (null) != 1)
+ return 43;
+ if (tests_default ("hello") != 1)
+ return 44;
+ if (tests_default ("world") != 1)
+ return 45;
+ if (tests_default ("how") != 2)
+ return 46;
+
+ if (tests_default_2 ("Test") != 1)
+ return 47;
+ if (tests_default_2 ("foo") != 2)
+ return 48;
+ if (tests_default_2 ("Hello") != 3)
+ return 49;
+ if (tests_default_2 ("Monkey") != 3)
+ return 50;
+
+ if (!bug_78860 ())
+ return 60;
+
Console.WriteLine ("All tests pass");
return 0;
}