Merge pull request #463 from strawd/concurrent-requests
[mono.git] / mcs / tests / gtest-269.cs
1 using System;
2
3 [Flags]
4 enum IrishBeer {
5         Stout           = 0x1000,
6         Ale             = 0x2000,
7         Lager           = 0x3000,
8
9         Guinness        = 1 | Stout,
10         Smithwicks      = 2 | Ale
11 }
12
13 struct IrishPub
14 {
15         public readonly IrishBeer Beer;
16
17         public IrishPub (IrishBeer beer)
18         {
19                 this.Beer = beer;
20         }
21
22         public static implicit operator long (IrishPub? pub)
23         {
24                 return pub.HasValue ? (long) pub.Value.Beer : 0;
25         }
26
27         public static implicit operator IrishPub? (long value)
28         {
29                 return new IrishPub ((IrishBeer) value);
30         }
31 }
32
33 class X
34 {
35         static int Beer (IrishPub? pub)
36         {
37                 switch (pub) {
38                 case 0x1001:
39                         return 1;
40
41                 case 0x2002:
42                         return 2;
43
44                 default:
45                         return 3;
46                 }
47         }
48
49         static long PubToLong (IrishPub pub)
50         {
51                 return pub;
52         }
53
54         static int Test (int? a)
55         {
56                 switch (a) {
57                 case 0:
58                         return 0;
59
60                 case 3:
61                         return 1;
62
63                 default:
64                         return 2;
65                 }
66         }
67
68         static int TestWithNull (int? a)
69         {
70                 switch (a) {
71                 case 0:
72                         return 0;
73
74                 case 3:
75                         return 1;
76
77                 case null:
78                         return 2;
79
80                 default:
81                         return 3;
82                 }
83         }
84
85         static long? Foo (bool flag)
86         {
87                 if (flag)
88                         return 4;
89                 else
90                         return null;
91         }
92
93         static int Test (bool flag)
94         {
95                 switch (Foo (flag)) {
96                 case 0:
97                         return 0;
98
99                 case 4:
100                         return 1;
101
102                 default:
103                         return 2;
104                 }
105         }
106
107         public static int Main ()
108         {
109                 IrishPub pub = new IrishPub (IrishBeer.Guinness);
110                 if (PubToLong (pub) != 0x1001)
111                         return 1;
112
113                 if (Beer (null) != 3)
114                         return 2;
115                 if (Beer (new IrishPub (IrishBeer.Guinness)) != 1)
116                         return 3;
117
118                 if (Test (null) != 2)
119                         return 4;
120                 if (Test (3) != 1)
121                         return 5;
122                 if (Test (true) != 1)
123                         return 6;
124                 if (Test (false) != 2)
125                         return 7;
126
127                 if (TestWithNull (null) != 2)
128                         return 8;
129                 if (TestWithNull (3) != 1)
130                         return 9;
131
132                 return 0;
133         }
134 }