2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / corlib / Test / System.Globalization / StringInfoTest.cs
blob70fb0abd9fa10e6b2c315d6649f79a68dd159fc3
1 //
2 // StringInfoTest.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8 //
10 using NUnit.Framework;
11 using System;
12 using System.Globalization;
13 using System.IO;
14 using System.Runtime.Serialization;
15 using System.Runtime.Serialization.Formatters.Binary;
17 namespace MonoTests.System.Globalization
20 [TestFixture]
21 public class StringInfoTest
23 [Test]
24 public void GetNextTextElement ()
26 Assert.AreEqual ("A", StringInfo.GetNextTextElement ("ABC", 0), "#1");
27 Assert.AreEqual ("C", StringInfo.GetNextTextElement ("ABC", 2), "#2");
28 Assert.AreEqual ("A\u0330", StringInfo.GetNextTextElement ("A\u0330BC", 0), "#3");
29 Assert.AreEqual ("B", StringInfo.GetNextTextElement ("A\u0330BC", 2), "#4");
31 // hmm ...
32 #if NET_2_0 // it causes ArgumentOutOfRangeException in 1.x, not worthy to test it anymore
33 Assert.AreEqual (String.Empty, StringInfo.GetNextTextElement ("A\u0330BC", 4), "#4");
34 #endif
37 [Test]
38 [ExpectedException (typeof (ArgumentOutOfRangeException))]
39 public void GetNextTextElementOutOfRange1 ()
41 StringInfo.GetNextTextElement ("ABC", -1);
44 #if NET_2_0
45 [Test]
46 public void LengthInTextElements ()
48 Assert.AreEqual (3, new StringInfo ("ABC").LengthInTextElements, "#1");
49 Assert.AreEqual (5, new StringInfo (" ABC ").LengthInTextElements, "#2");
50 Assert.AreEqual (3, new StringInfo ("A\u0330BC\u0330").LengthInTextElements, "#3");
51 Assert.AreEqual (3, new StringInfo ("A\u0330\u0331BC\u0330").LengthInTextElements, "#4");
54 [Test]
55 public void SubstringByTextElements ()
57 StringInfo si = new StringInfo ("A\u0330BC\u0330");
58 Assert.AreEqual ("A\u0330BC\u0330", si.SubstringByTextElements (0), "#1");
59 Assert.AreEqual ("BC\u0330", si.SubstringByTextElements (1), "#2");
60 Assert.AreEqual ("C\u0330", si.SubstringByTextElements (2), "#3");
63 [Test]
64 public void DefaultConstructor ()
66 var info = new StringInfo ();
67 Assert.AreEqual (string.Empty, info.String);
70 [Test]
71 [ExpectedException (typeof (ArgumentOutOfRangeException))]
72 public void SubstringByTextElementsOutOfRange1 ()
74 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (-1);
77 [Test]
78 [ExpectedException (typeof (ArgumentOutOfRangeException))]
79 public void SubstringByTextElementsOutOfRange2 ()
81 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (4);
84 [Test]
85 [ExpectedException (typeof (ArgumentOutOfRangeException))]
86 public void SubstringByTextElementsOutOfRange3 ()
88 new StringInfo (String.Empty).SubstringByTextElements (0);
90 #endif