2009-06-12 Bill Holmes <billholmes54@gmail.com>
[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 public class CharEnumeratorTest : TestCase
17 {
18         public CharEnumeratorTest () {}
19
20         string _s;
21
22         protected override void SetUp ()
23         {
24                 _s = "Emma en Sophie";
25         }
26
27         private string GetFromEnumerator (CharEnumerator ce)
28         {
29                 string res = "";
30                 bool cont = true;
31
32                 while (cont) {
33                         res += ce.Current;
34                         cont = ce.MoveNext ();
35                 }
36
37                 return res;
38         }
39
40         public void TestBasic ()
41         {
42                 CharEnumerator ce = _s.GetEnumerator ();
43
44                 ce.MoveNext ();
45
46                 AssertEquals ("A1", _s, GetFromEnumerator (ce));
47         }
48
49         public void TestClone ()
50         {
51                 CharEnumerator ce1, ce2=null;
52                 bool cont;
53
54                 ce1 = _s.GetEnumerator ();
55                 cont = ce1.MoveNext ();
56                 while (cont) {
57                         if (ce1.Current == 'S') {
58                                 ce2 = (CharEnumerator) (ce1.Clone ());
59                         }
60                         cont = ce1.MoveNext ();
61                 }
62
63                 AssertEquals ("A1", "Sophie", GetFromEnumerator(ce2));
64         }
65
66         public void TestReadOutOfBounds ()
67         {
68                 char c;
69                 bool exception;
70                 CharEnumerator ce = _s.GetEnumerator ();
71         
72                 try {
73                         c = ce.Current;
74                         exception = false;
75                 }
76                 catch (InvalidOperationException) {
77                         exception = true;
78                 }
79                 Assert ("A1", exception);
80
81                 AssertEquals("A2", true, ce.MoveNext ());
82
83                 AssertEquals ("A3", _s, GetFromEnumerator (ce));
84
85                 try {
86                         c = ce.Current;
87                 }
88                 catch (InvalidOperationException) {
89                         exception = true;
90                 }
91                 Assert ("A4", exception);
92
93                 AssertEquals("A5", false, ce.MoveNext() );
94                 AssertEquals("A6", false, ce.MoveNext() );
95
96                 ce.Reset ();
97
98                 try {
99                         c = ce.Current;
100                 }
101                 catch (InvalidOperationException) {
102                         exception = true;
103                 }
104                 Assert ("A7", exception);
105
106                 AssertEquals ("A8", true, ce.MoveNext ());
107
108                 AssertEquals ("A9", _s, GetFromEnumerator (ce));
109
110                 AssertEquals ("A10", false, ce.MoveNext ());
111                 AssertEquals ("A11", false, ce.MoveNext ());
112         }
113
114 }
115
116 }