**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System / CharEnumeratorTest.cs
blob6ea33511d71a8d75a1da701c2200e726a6e8126b
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 //
10 using NUnit.Framework;
11 using System;
13 namespace MonoTests.System
16 public class CharEnumeratorTest : TestCase
18 public CharEnumeratorTest () {}
20 string _s;
22 protected override void SetUp ()
24 _s = "Emma en Sophie";
27 private string GetFromEnumerator (CharEnumerator ce)
29 string res = "";
30 bool cont = true;
32 while (cont) {
33 res += ce.Current;
34 cont = ce.MoveNext ();
37 return res;
40 public void TestBasic ()
42 CharEnumerator ce = _s.GetEnumerator ();
44 ce.MoveNext ();
46 AssertEquals ("A1", _s, GetFromEnumerator (ce));
49 public void TestClone ()
51 CharEnumerator ce1, ce2=null;
52 bool cont;
54 ce1 = _s.GetEnumerator ();
55 cont = ce1.MoveNext ();
56 while (cont) {
57 if (ce1.Current == 'S') {
58 ce2 = (CharEnumerator) (ce1.Clone ());
60 cont = ce1.MoveNext ();
63 AssertEquals ("A1", "Sophie", GetFromEnumerator(ce2));
66 public void TestReadOutOfBounds ()
68 char c;
69 bool exception;
70 CharEnumerator ce = _s.GetEnumerator ();
72 try {
73 c = ce.Current;
74 exception = false;
76 catch (InvalidOperationException) {
77 exception = true;
79 Assert ("A1", exception);
81 AssertEquals("A2", true, ce.MoveNext ());
83 AssertEquals ("A3", _s, GetFromEnumerator (ce));
85 try {
86 c = ce.Current;
88 catch (InvalidOperationException) {
89 exception = true;
91 Assert ("A4", exception);
93 AssertEquals("A5", false, ce.MoveNext() );
94 AssertEquals("A6", false, ce.MoveNext() );
96 ce.Reset ();
98 try {
99 c = ce.Current;
101 catch (InvalidOperationException) {
102 exception = true;
104 Assert ("A7", exception);
106 AssertEquals ("A8", true, ce.MoveNext ());
108 AssertEquals ("A9", _s, GetFromEnumerator (ce));
110 AssertEquals ("A10", false, ce.MoveNext ());
111 AssertEquals ("A11", false, ce.MoveNext ());