Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / corlib / Test / System / CharEnumeratorTest.cs
1 //
2 // CharEnumeratorTest.cs - NUnit Test Cases for the System.CharEnumerator class
3 //
4 // author:
5 //   Duco Fijma (duco@lorentz.xs4all.nl)
6 //
7 //   (C) 2002 Duco Fijma
8 //
9
10 using NUnit.Framework;
11 using System;
12
13 namespace MonoTests.System
14 {
15
16 [TestFixture]
17 public class CharEnumeratorTest
18 {
19         public CharEnumeratorTest () {}
20
21         string _s;
22
23         [SetUp]
24         protected void SetUp ()
25         {
26                 _s = "Emma en Sophie";
27         }
28
29         private string GetFromEnumerator (CharEnumerator ce)
30         {
31                 string res = "";
32                 bool cont = true;
33
34                 while (cont) {
35                         res += ce.Current;
36                         cont = ce.MoveNext ();
37                 }
38
39                 return res;
40         }
41
42         [Test]
43         public void TestBasic ()
44         {
45                 CharEnumerator ce = _s.GetEnumerator ();
46
47                 ce.MoveNext ();
48
49                 Assert.AreEqual (_s, GetFromEnumerator (ce), "A1");
50         }
51
52         [Test]
53         public void TestClone ()
54         {
55                 CharEnumerator ce1, ce2=null;
56                 bool cont;
57
58                 ce1 = _s.GetEnumerator ();
59                 cont = ce1.MoveNext ();
60                 while (cont) {
61                         if (ce1.Current == 'S') {
62                                 ce2 = (CharEnumerator) (ce1.Clone ());
63                         }
64                         cont = ce1.MoveNext ();
65                 }
66
67                 Assert.AreEqual ("Sophie", GetFromEnumerator(ce2), "A1");
68         }
69
70         [Test]
71         public void TestReadOutOfBounds ()
72         {
73                 char c;
74                 bool exception;
75                 CharEnumerator ce = _s.GetEnumerator ();
76         
77                 try {
78                         c = ce.Current;
79                         exception = false;
80                 }
81                 catch (InvalidOperationException) {
82                         exception = true;
83                 }
84                 Assert.IsTrue (exception, "A1");
85
86                 Assert.AreEqual(true, ce.MoveNext (), "A2");
87
88                 Assert.AreEqual (_s, GetFromEnumerator (ce), "A3");
89
90                 try {
91                         c = ce.Current;
92                 }
93                 catch (InvalidOperationException) {
94                         exception = true;
95                 }
96                 Assert.IsTrue (exception, "A4");
97
98                 Assert.AreEqual(false, ce.MoveNext() , "A5");
99                 Assert.AreEqual(false, ce.MoveNext() , "A6");
100
101                 ce.Reset ();
102
103                 try {
104                         c = ce.Current;
105                 }
106                 catch (InvalidOperationException) {
107                         exception = true;
108                 }
109                 Assert.IsTrue (exception, "A7");
110
111                 Assert.AreEqual (true, ce.MoveNext (), "A8");
112
113                 Assert.AreEqual (_s, GetFromEnumerator (ce), "A9");
114
115                 Assert.AreEqual (false, ce.MoveNext (), "A10");
116                 Assert.AreEqual (false, ce.MoveNext (), "A11");
117         }
118
119 }
120
121 }