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

test-iter-07.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13b338423ca1caf0c4cd65e72839e08af61895bd (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
// Compiler options: -langversion:default

using System;
using System.Collections;

public class Test
{
	public IEnumerable Foo (int a)
	{
		try {
			try {
				yield return a;
			} finally {
				Console.WriteLine ("Hello World");
			}

			Console.WriteLine ("Next block");

			try {
				yield return a * a;
			} finally {
				Console.WriteLine ("Boston");
			}
		} finally {
			Console.WriteLine ("Outer finally");
		}

		Console.WriteLine ("Outer block");
		yield break;
	}
}

class X
{
	public static int Main ()
	{
		Test test = new Test ();

		ArrayList list = new ArrayList ();
		foreach (object o in test.Foo (5))
			list.Add (o);

		if (list.Count != 2)
			return 1;
		if ((int) list [0] != 5)
			return 2;
		if ((int) list [1] != 25)
			return 3;

		IEnumerable a = test.Foo (5);

		IEnumerator b = a as IEnumerator;
		if (b != null) {
			if (b.MoveNext ())
				return 4;
		}

		IEnumerator c = a.GetEnumerator ();
		if (!c.MoveNext ())
			return 5;
		if ((int) c.Current != 5)
			return 6;
		if (!c.MoveNext ())
			return 7;
		if ((int) c.Current != 25)
			return 8;

		IEnumerator d = a.GetEnumerator ();

		if ((int) c.Current != 25)
			return 9;
		if (!d.MoveNext ())
			return 10;
		if ((int) c.Current != 25)
			return 11;
		if ((int) d.Current != 5)
			return 12;

		if (c.MoveNext ())
			return 13;

		((IDisposable) a).Dispose ();
		return 0;
	}
}