return 5;
case null:
return 9;
+ case "new":
+ goto case null;
default:
return 6;
}
return 1;
}
+
+ static int tests2 (string s)
+ {
+ switch (s){
+ case "one":
+ goto case null;
+ case "two":
+ goto default;
+ case null:
+ default:
+ return 3;
+ }
+ }
static int testn (string s)
{
return 20;
case TestEnum.c:
- return 30;
+ goto case TestEnum.b;
default:
return 40;
return 1;
if (testSwitchEnumLong (TestEnum.b) != 20)
return 2;
- if (testSwitchEnumLong (TestEnum.c) != 30)
+ if (testSwitchEnumLong (TestEnum.c) != 20)
return 3;
if (testSwitchEnumLong ((TestEnum)5) != 40)
return 4;
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 ()
+ static void test_1597 ()
+ {
+ var a = "";
+ switch (a) {
+ }
+ }
+
+ static int LongStringSwitch (string s)
+ {
+ switch (s)
+ {
+ case "System":
+ case "System.Core":
+ case "System.Data":
+ case "System.Data.DataSetExtensions":
+ case "System.Data.Linq":
+ case "System.Data.OracleClient":
+ case "System.Data.Services":
+ case "System.Data.Services.Client":
+ case "System.IdentityModel":
+ case "System.IdentityModel.Selectors":
+ case "System.Runtime.Remoting":
+ case "System.Runtime.Serialization":
+ case "System.ServiceModel":
+ case "System.Transactions":
+ case "System.Windows.Forms":
+ case "System.Xml":
+ case "System.Xml.Linq":
+ return 1;
+
+ case "System.Configuration":
+ case "System.Configuration.Install":
+ case "System.Design":
+ case "System.DirectoryServices":
+ case "System.Drawing":
+ case "System.Drawing.Design":
+ case "System.EnterpriseServices":
+ case "System.Management":
+ case "System.Messaging":
+ case "System.Runtime.Serialization.Formatters.Soap":
+ case "System.Security":
+ case "System.ServiceProcess":
+ case "System.Web":
+ case "System.Web.Mobile":
+ case "System.Web.Services":
+ return 2;
+
+ case "System.ComponentModel.DataAnnotations":
+ case "System.ServiceModel.Web":
+ case "System.Web.Abstractions":
+ case "System.Web.Extensions":
+ case "System.Web.Extensions.Design":
+ case "System.Web.DynamicData":
+ case "System.Web.Routing":
+ return 3;
+ }
+
+ return 10;
+ }
+
+ static bool SwitchSingleSection (string scheme)
+ {
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "file":
+ case "ftp":
+ case "nntp":
+ case "gopher":
+ case "mailto":
+ case "news":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static int Main ()
{
byte b;
return 10;
if (tests ("blah") != 6)
return 11;
+ if (tests ("new") != 9)
+ return 110;
+
if (testn ("one") != 1)
return 12;
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;
+
+ if (tests2 ("a") != 3)
+ return 71;
+ if (tests2 ("one") != 3)
+ return 72;
+ if (tests2 ("two") != 3)
+ return 73;
+
+ if (LongStringSwitch ("System.Management") != 2)
+ return 80;
+ if (LongStringSwitch (null) != 10)
+ return 81;
+ if (LongStringSwitch (".") != 10)
+ return 82;
+
+ if (!SwitchSingleSection ("file"))
+ return 90;
+ if (SwitchSingleSection (null))
+ return 91;
+ if (SwitchSingleSection ("-=-"))
+ return 92;
+
+ test_1597 ();
Console.WriteLine ("All tests pass");
return 0;