Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-154.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56b5be7509f24a2c1fcb3b249e374277623d78f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
using System;
using System.Collections;

public class X
{
	public static int Main ()
	{
		// This is a compilation-only test.
		return 0;
	}

	// All code paths throw an exception, no need to set out parameters.
	public static void test1 (out float f)
	{
		throw new NotSupportedException ();
	}

	// The while loop breaks but does not return, so this is ok.
	public static void test2 (int a, out float f)
	{
		while (a > 0) {
			if (a == 5)
				continue;

			Console.WriteLine (a);
		}

		f = 8.53F;
	}

	// a has been assigned in all code paths which do not return.
	public static void test3 (long[] b, int c)
	{
		ICollection a;
		if (b == null)
			throw new ArgumentException ();
		else
			a = (ICollection) b;

		Console.WriteLine (a);
	}

	// Forward goto, it's ok to set f after the target label.
	public static int test4 (int b, out float f)
	{
		long a;

		Console.WriteLine ("Hello World");

		a = 5;

		goto World;

	World:
		Console.WriteLine (a);

		f = 8.53F;

		return 0;
	}

	// try { ... } catch { ... } finally { ... } block
	static public int test5 (out float f, long d)
	{
                int a;
		long b = 8;

		try {
			f = 8.53F;

			if (d == 500)
				return 9;

			a = 5;
		} catch (NotSupportedException e) {
			a = 9;
		} catch (Exception e) {
			return 9;
		} finally {
			f = 9.234F;
		}

		return a;
        }

	// Passing out parameter to method invocation
	static public int test6 (out float f)
	{
		return test5 (out f, 50);
	}

	// Loop-variable of foreach() and for() loop.
	static public long test7 (int[] a, int stop)
	{
		long b = 0;
		foreach (int i in a)
			b += i;

		for (int i = 1; i < stop; i++)
			b *= i;

		return b;
	}

	// Initializing locals in initialize or test of for block
	static public long test8 (int stop)
	{
		int i;
		long b;
		for (i = 1; (b = stop) > 3; i++) {
			stop--;
			b += i;
		}
		return b;
	}

	// Initializing locals in test of while block
	static public long test9 (int stop)
	{
		long b;
		while ((b = stop) > 3) {
			stop--;
			b += stop;
		}
		return b;
	}

	// Return in subblock
	public static void test10 (int a, out float f)
	{
		if (a == 5) {
			f = 8.53F;
			return;
		}

		f = 9.0F;
	}

	// Switch block
	public static long test11 (int a)
	{
		long b;

		switch (a) {
		case 5:
			b = 1;
			break;

		case 9:
			b = 3;
			break;

		default:
			return 9;
		}

		return b;
	}

	// Try block which rethrows exception.
	public static void test12 (out float f)
	{
		try {
			f = 9.0F;
		} catch {
			throw new NotSupportedException ();
		}
	}

	// Return in subblock.
	public static void test13 (int a, out float f)
	{
		do {
			if (a == 8) {
				f = 8.5F;
				return;
			}
		} while (false);

		f = 1.3F;
		return;
	}

	// Switch block with goto case / goto default.
	public static long test14 (int a, out float f)
	{
		long b;

		switch (a) {
		case 1:
			goto case 2;

		case 2:
			f = 9.53F;
			return 9;

		case 3:
			goto default;

		default:
			b = 10;
			break;
		}

		f = 10.0F;

		return b;
	}

	// Forward goto, it's ok to set f before the jump.
	public static int test15 (int b, out float f)
	{
		long a;

		Console.WriteLine ("Hello World");

		a = 5;
		f = 8.53F;

		goto World;

	World:
		Console.WriteLine (a);

		return 0;
	}

	// `continue' breaks unless we're a loop block.
	public static void test16 ()
	{
                int value;

                for (int i = 0; i < 5; ++i) {
                        if (i == 0) {
                                continue;
                        } else if (i == 1) {
                                value = 2;
                        } else {
                                value = 0;
                        }
                        if (value > 0)
                                return;
                }
	}

	// `continue' in a nested if.
	public static void test17 ()
	{
		 int value;
		 long charCount = 9;
		 long testit = 5;

		 while (charCount > 0) {
			 --charCount;

			 if (testit == 8) {
				 if (testit == 9)
					 throw new Exception ();

				 continue;
			 } else {
				 value = 0;
			 }

			 Console.WriteLine (value);
		 }
	}

	// `out' parameter assigned after conditional exception.
	static void test18 (int a, out int f)
	{
		try {
			if (a == 5)
				throw new Exception ();

			f = 9;
		} catch (IndexOutOfRangeException) {
			throw new FormatException ();
		}
	}

	// code after try/catch block is unreachable. always returns.
        static int test19 () {
                int res;
                int a = Environment.NewLine.Length;
                int fin = 0;

                try {
                        res = 10/a;
                        throw new NotImplementedException ();
                } catch (NotImplementedException e) {
                        fin = 2;
                        throw new NotImplementedException ();
                } finally {
                        fin = 1;
                }
                return res;
        }

}