5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
10 using NUnit.Framework;
12 using System.Globalization;
14 using System.Runtime.Serialization;
15 using System.Runtime.Serialization.Formatters.Binary;
17 namespace MonoTests.System.Globalization
21 public class StringInfoTest
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");
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");
38 [ExpectedException (typeof (ArgumentOutOfRangeException))]
39 public void GetNextTextElementOutOfRange1 ()
41 StringInfo.GetNextTextElement ("ABC", -1);
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");
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");
64 public void DefaultConstructor ()
66 var info = new StringInfo ();
67 Assert.AreEqual (string.Empty, info.String);
71 [ExpectedException (typeof (ArgumentOutOfRangeException))]
72 public void SubstringByTextElementsOutOfRange1 ()
74 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (-1);
78 [ExpectedException (typeof (ArgumentOutOfRangeException))]
79 public void SubstringByTextElementsOutOfRange2 ()
81 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (4);
85 [ExpectedException (typeof (ArgumentOutOfRangeException))]
86 public void SubstringByTextElementsOutOfRange3 ()
88 new StringInfo (String.Empty).SubstringByTextElements (0);