Merge pull request #1142 from edbprx/master
[mono.git] / mcs / tests / gtest-409.cs
1 using System;
2
3 //
4 // parser conditional and cast expression tests
5 //
6
7 class A<T>
8 {
9         public static int Value;
10 }
11
12 public class ConditionalParsing
13 {
14         class T
15         {
16                 public T (string path, bool mode)
17                         : this (path, mode, (mode == true ? 1 : 2), 1, int.MaxValue)
18                 {
19                 }
20                 
21                 public T (string s, bool m, int i, int i2, int i3)
22                 {
23                 }
24         }
25         
26         class Const
27         {
28                 const int c = true ? 1 : 2;
29         }
30         
31         struct S
32         {
33         }
34
35         struct MyTestStruct : IDisposable
36         {
37                 public void Dispose ()
38                 {
39                 }
40
41                 public static implicit operator MyTestStruct (int i)
42                 {
43                         return new MyTestStruct ();
44                 }
45         }
46         
47         void Test_1 (bool a)
48         {
49                 int? b = a ? 3 : 4;
50         }
51         
52         void Test_2 ()
53         {
54                 string mp = "";
55                 int a = 1;
56                 int _provider = mp.Length == a ? _provider = 4 : 5;
57         }
58         
59         T? Test_3<T> (Func<T, T, T> result, T t) where T : struct
60         {
61                 return new T? (result (t, t));
62         }
63         
64         void Test_4 (bool x, bool y)
65         {
66                 int s = x ? (y ? 2 : 4) : (y ? 5 : 7);
67         }
68         
69         void Test_5 (bool a, IDisposable fs)
70         {
71                 using (a ? fs : null) {
72                         Console.WriteLine ("");
73                 }
74         }
75         
76         void Test_6 (bool a)
77         {
78                 char[] escaped_text_chars =
79                         a != false ?
80                         new char [] {'&', '<', '>', '\r', '\n'} :
81                         new char [] {'&', '<', '>'};
82         }
83         
84         void Test_7 (object o)
85         {
86                 object a = (S?[]) o;
87         }
88
89         void Test_8 (DateTime value)
90         {
91                 var     _endDate = value > DateTime.MinValue ? new DateTime ? (value) : null;
92         }
93         
94         void Test_9 ()
95         {
96                 bool b = (1 == 2);
97                 bool c = (1 == 1);
98                 string a = (b ? (c ? "#" : "#") : "");
99         }
100
101         void Test_10 ()
102         {
103                 int i = new int [] { 1, 2, 3 } [1];
104         }
105         
106         void Test_11 ()
107         {
108                 int a = (int)(A<int>.Value);
109         }
110         
111         static int Test_12 (bool arg)
112         {
113                 return arg ? Foo (() => { return 1; }) : 1;
114         }
115         
116         static int Foo (Func<int> arg)
117         {
118                 return 1;
119         }
120
121         void Test_13 (object param)
122         {
123                 if (param as bool? ?? false) {} else {}
124         }
125
126         int? Test_14 ()
127         {
128                 bool a = false, b = false;
129                 object c = null;
130
131                 return a ? (b ? c as int? : null) : null;
132         }
133
134         Action<int> Test_15 (Action<int> arg)
135         {
136                 return arg ?? (Helper<int>);
137         }
138
139         void Test_16 ()
140         {
141                 bool? b = Test (1, arg:2);
142         }
143
144         void Test_17 ()
145         {
146                 {
147                         using (MyTestStruct? mts = (int?) 1)
148                         {
149                         }
150                 }
151         }
152
153         static void Helper<T> (T arg)
154         {
155         }
156
157         static bool Test (object b, int arg)
158         {
159                 return false;
160         }
161
162         public static void Main ()
163         {
164         }
165 }
166