Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / test-229.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Specialized;
4
5 public class List : IEnumerable {
6
7         int pos = 0;
8         int [] items;
9         
10         public List (int i) 
11         {
12                 items = new int [i];
13         }
14         
15         public void Add (int value) 
16         {
17                 items [pos ++] = value;
18         }
19         
20         public MyEnumerator GetEnumerator ()
21         {
22                 return new MyEnumerator(this);
23         }
24         
25         IEnumerator IEnumerable.GetEnumerator ()
26         {
27                 return GetEnumerator ();
28         }
29         
30         public struct MyEnumerator : IEnumerator {
31                 
32                 List l;
33                 int p;
34                 
35                 public MyEnumerator (List l) 
36                 {
37                         this.l = l;
38                         p = -1;
39                 }
40                 
41                 public object Current {
42                         get {
43                                 return l.items [p];
44                         }
45                 }
46                 
47                 public bool MoveNext() 
48                 {
49                         return ++p < l.pos;
50                 }
51
52                 public void Reset() 
53                 {
54                         p = 0;
55                 }
56         }
57 }
58
59 public class UberList : List {
60         public UberList (int i) : base (i)
61         {
62         }
63         
64         public static int Main(string[] args)
65         {
66                 return One () && Two () && Three () ? 0 : 1;
67
68         }
69         
70         static bool One ()
71         {
72                 List l = new List (1);
73                 l.Add (1);
74                 
75                 foreach (int i in l)
76                         if (i == 1)
77                                 return true;
78                 return false;
79         }
80         
81         static bool Two ()
82         {
83                 List l = new UberList (1);
84                 l.Add (1);
85                 
86                 foreach (int i in l)
87                         if (i == 1)
88                                 return true;
89                 return false;
90         }
91         
92         static bool Three ()
93         {
94                 UberList l = new UberList (1);
95                 l.Add (1);
96                 
97                 foreach (int i in l)
98                         if (i == 1)
99                                 return true;
100                 return false;
101         }
102 }