Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CharEnumeratorTest.cs « System « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: da7fecbc221942c5a01f01ec2c2922824ad71cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// CharEnumeratorTest.cs - NUnit Test Cases for the System.CharEnumerator class
//
// author:
//   Duco Fijma (duco@lorentz.xs4all.nl)
//
//   (C) 2002 Duco Fijma
//

using NUnit.Framework;
using System;

namespace MonoTests.System
{

public class CharEnumeratorTest : TestCase
{
	public CharEnumeratorTest () : base ("MonoTests.System.CharEnumeratorTest testcase") {}
        public CharEnumeratorTest (string name) : base (name) {}

	public static ITest Suite {
		get {
			return new TestSuite (typeof (CharEnumeratorTest));
		}
	}

	string _s;

	protected override void SetUp ()
	{
		_s = "Emma en Sophie";
	}

	private string GetFromEnumerator (CharEnumerator ce)
	{
		string res = "";
		bool cont = true;

		while (cont) {
			res += ce.Current;
			cont = ce.MoveNext ();
		}

		return res;
	}

	public void TestBasic ()
	{
		CharEnumerator ce = _s.GetEnumerator ();

		ce.MoveNext ();

		AssertEquals ("A1", _s, GetFromEnumerator (ce));
	}

	public void TestClone ()
	{
		CharEnumerator ce1, ce2=null;
		bool cont;

		ce1 = _s.GetEnumerator ();
		cont = ce1.MoveNext ();
		while (cont) {
			if (ce1.Current == 'S') {
				ce2 = (CharEnumerator) (ce1.Clone ());
			}
			cont = ce1.MoveNext ();
		}

		AssertEquals ("A1", "Sophie", GetFromEnumerator(ce2));
	}

	public void TestReadOutOfBounds ()
	{
		char c;
		bool exception;
		CharEnumerator ce = _s.GetEnumerator ();
	
		try {
			c = ce.Current;
			exception = false;
		}
		catch (InvalidOperationException) {
			exception = true;
		}
		Assert ("A1", exception);

		AssertEquals("A2", true, ce.MoveNext ());

		AssertEquals ("A3", _s, GetFromEnumerator (ce));

		try {
			c = ce.Current;
		}
		catch (InvalidOperationException) {
			exception = true;
		}
		Assert ("A4", exception);

		AssertEquals("A5", false, ce.MoveNext() );
		AssertEquals("A6", false, ce.MoveNext() );

		ce.Reset ();

		try {
			c = ce.Current;
		}
		catch (InvalidOperationException) {
			exception = true;
		}
		Assert ("A7", exception);

		AssertEquals ("A8", true, ce.MoveNext ());

		AssertEquals ("A9", _s, GetFromEnumerator (ce));

		AssertEquals ("A10", false, ce.MoveNext ());
		AssertEquals ("A11", false, ce.MoveNext ());
	}

}

}