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 Assert.AreEqual (String.Empty, StringInfo.GetNextTextElement ("A\u0330BC", 4), "#4");
36 [ExpectedException (typeof (ArgumentOutOfRangeException))]
37 public void GetNextTextElementOutOfRange1 ()
39 StringInfo.GetNextTextElement ("ABC", -1);
43 public void LengthInTextElements ()
45 Assert.AreEqual (3, new StringInfo ("ABC").LengthInTextElements, "#1");
46 Assert.AreEqual (5, new StringInfo (" ABC ").LengthInTextElements, "#2");
47 Assert.AreEqual (3, new StringInfo ("A\u0330BC\u0330").LengthInTextElements, "#3");
48 Assert.AreEqual (3, new StringInfo ("A\u0330\u0331BC\u0330").LengthInTextElements, "#4");
52 public void SubstringByTextElements ()
54 StringInfo si = new StringInfo ("A\u0330BC\u0330");
55 Assert.AreEqual ("A\u0330BC\u0330", si.SubstringByTextElements (0), "#1");
56 Assert.AreEqual ("BC\u0330", si.SubstringByTextElements (1), "#2");
57 Assert.AreEqual ("C\u0330", si.SubstringByTextElements (2), "#3");
61 public void DefaultConstructor ()
63 var info = new StringInfo ();
64 Assert.AreEqual (string.Empty, info.String);
68 [ExpectedException (typeof (ArgumentOutOfRangeException))]
69 public void SubstringByTextElementsOutOfRange1 ()
71 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (-1);
75 [ExpectedException (typeof (ArgumentOutOfRangeException))]
76 public void SubstringByTextElementsOutOfRange2 ()
78 new StringInfo ("A\u0330BC\u0330").SubstringByTextElements (4);
82 [ExpectedException (typeof (ArgumentOutOfRangeException))]
83 public void SubstringByTextElementsOutOfRange3 ()
85 new StringInfo (String.Empty).SubstringByTextElements (0);