2004-08-03 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / tests / 2test-8.cs
1 using System;
2 using System.Collections;
3
4 public class Test
5 {
6         public IEnumerable Foo (int a)
7         {
8                 try {
9                         try {
10                                 yield return a;
11                         } finally {
12                                 Console.WriteLine ("Hello World");
13                         }
14
15                         Console.WriteLine ("Next block");
16
17                         try {
18                                 yield return a * a;
19                         } finally {
20                                 Console.WriteLine ("Boston");
21                         }
22                 } finally {
23                         Console.WriteLine ("Outer finally");
24                 }
25
26                 Console.WriteLine ("Outer block");
27                 yield break;
28         }
29 }
30
31 class X
32 {
33         static int Main ()
34         {
35                 Test test = new Test ();
36
37                 ArrayList list = new ArrayList ();
38                 foreach (object o in test.Foo (5))
39                         list.Add (o);
40
41                 if (list.Count != 2)
42                         return 1;
43                 if ((int) list [0] != 5)
44                         return 2;
45                 if ((int) list [1] != 25)
46                         return 3;
47
48                 IEnumerable a = test.Foo (5);
49
50                 IEnumerator b = a as IEnumerator;
51                 if (b != null) {
52                         if (b.MoveNext ())
53                                 return 4;
54                 }
55
56                 IEnumerator c = a.GetEnumerator ();
57                 if (!c.MoveNext ())
58                         return 5;
59                 if ((int) c.Current != 5)
60                         return 6;
61                 if (!c.MoveNext ())
62                         return 7;
63                 if ((int) c.Current != 25)
64                         return 8;
65
66                 IEnumerator d = a.GetEnumerator ();
67
68                 if ((int) c.Current != 25)
69                         return 9;
70                 if (!d.MoveNext ())
71                         return 10;
72                 if ((int) c.Current != 25)
73                         return 11;
74                 if ((int) d.Current != 5)
75                         return 12;
76
77                 if (c.MoveNext ())
78                         return 13;
79
80                 ((IDisposable) a).Dispose ();
81                 return 0;
82         }
83 }