1 // TextInfoTest.cs - NUnit Test Cases for the
2 // System.Globalization.TextInfo class
4 // Miguel de Icaza <miguel@ximian.com>
6 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 using System.Globalization;
13 using System.Runtime.Serialization;
14 using System.Runtime.Serialization.Formatters.Binary;
16 namespace MonoTests.System.Globalization
20 public class TextInfoTest {
23 public void TitleCase ()
25 TextInfo ti = new CultureInfo ("en-US", false).TextInfo;
27 Assert.AreEqual (" The Dog", ti.ToTitleCase (" the dog"), "#1");
28 Assert.AreEqual (" The Dude", ti.ToTitleCase (" The Dude"), "#2");
29 Assert.AreEqual ("La Guerra Yla Paz", ti.ToTitleCase ("la Guerra yLa pAz"), "#3");
30 Assert.AreEqual ("\tTab\tAnd\tPeace", ti.ToTitleCase ("\ttab\taNd\tpeaCE"), "#4");
31 Assert.AreEqual ("This_Is\uFE58A\u0095String\u06D4With\uFE33Separators", ti.ToTitleCase ("this_is\uFE58a\u0095string\u06D4with\uFE33separators"), "#5");
35 public void ListSeparator ()
39 ti = new CultureInfo ("en-US", false).TextInfo;
40 Assert.AreEqual (",", ti.ListSeparator, "#1");
42 ti = CultureInfo.InvariantCulture.TextInfo;
43 Assert.AreEqual (",", ti.ListSeparator, "#2");
45 ti = new CultureInfo ("nl-BE", false).TextInfo;
46 Assert.AreEqual (";", ti.ListSeparator, "#3");
50 public void TitleCase2 ()
52 foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
53 Check (ci, "AB", "AB");
54 Check (ci, "ab", "Ab");
55 Check (ci, "aB", "Ab");
56 Check (ci, "1Ab", "1Ab");
57 Check (ci, "abc AB ab aB Ab ABc 1AB 1Ab 1ab 1aB",
58 "Abc AB Ab Ab Ab Abc 1AB 1Ab 1Ab 1Ab");
59 Check (ci, "LJ", "LJ");
60 Check (ci, "lj", "Lj");
61 Check (ci, "lJ", "Lj");
62 Check (ci, "lj abc ljabc", "Lj Abc Ljabc");
63 Check (ci, "ab", "Ab");
65 // Some greek titlecase characters
66 Check (ci, "\u01c4", "\u01c5");
67 Check (ci, "\u01c5", "\u01c5");
68 Check (ci, "\u01c6", "\u01c5");
69 Check (ci, "\u01ca", "\u01cb");
70 Check (ci, "\u01cb", "\u01cb");
71 Check (ci, "\u01cc", "\u01cb");
72 // Roman numbers are not converted unlike ToUpper().
73 Check (ci, "\u2170", "\u2170");
74 Check (ci, "\u24e9", "\u24e9");
78 private void Check (CultureInfo ci, string src, string expected)
80 Assert.AreEqual (expected, ci.TextInfo.ToTitleCase (src), src + " at culture " + ci.LCID);
83 private void CompareProperties (TextInfo t1, TextInfo t2, bool compareReadOnly)
85 Assert.AreEqual (t1.ANSICodePage, t2.ANSICodePage, "ANSICodePage");
86 Assert.AreEqual (t1.EBCDICCodePage, t2.EBCDICCodePage, "EBCDICCodePage");
87 Assert.AreEqual (t1.ListSeparator, t2.ListSeparator, "ListSeparator");
88 Assert.AreEqual (t1.MacCodePage, t2.MacCodePage, "MacCodePage");
89 Assert.AreEqual (t1.OEMCodePage, t2.OEMCodePage, "OEMCodePage");
90 Assert.AreEqual (t1.CultureName, t2.CultureName, "CultureName");
92 Assert.AreEqual (t1.IsReadOnly, t2.IsReadOnly, "IsReadOnly");
93 //FIXME Assert.AreEqual (t1.IsRightToLeft, t2.IsRightToLeft, "IsRightToLeft");
94 Assert.AreEqual (t1.LCID, t2.LCID, "LCID");
98 [Category ("NotWorking")] // OnDeserialization isn't completed
99 public void SerializationRoundtrip ()
101 TextInfo enus = new CultureInfo ("en-US").TextInfo;
102 BinaryFormatter bf = new BinaryFormatter ();
103 MemoryStream ms = new MemoryStream ();
104 bf.Serialize (ms, enus);
107 TextInfo clone = (TextInfo) bf.Deserialize (ms);
108 CompareProperties (enus, clone, true);
114 TextInfo enus = new CultureInfo ("en-US").TextInfo;
115 TextInfo clone = (TextInfo) enus.Clone ();
116 CompareProperties (enus, clone, true);
120 public void Clone_ReadOnly ()
122 TextInfo enus = TextInfo.ReadOnly (new CultureInfo ("en-US").TextInfo);
123 Assert.IsTrue (enus.IsReadOnly, "IsReadOnly-1");
124 TextInfo clone = (TextInfo) enus.Clone ();
125 Assert.IsFalse (clone.IsReadOnly, "IsReadOnly-2");
126 CompareProperties (enus, clone, false);
127 // cloned item is *NOT* read-only
131 public void ReadOnly ()
133 TextInfo enus = new CultureInfo ("en-US").TextInfo;
134 Assert.IsFalse (enus.IsReadOnly, "IsReadOnly-1");
135 TextInfo ro = TextInfo.ReadOnly (enus);
136 Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
137 CompareProperties (enus, ro, false);
141 public void IsRightToLeft ()
143 foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
174 Assert.IsTrue (ci.TextInfo.IsRightToLeft, ci.Name);
177 Assert.IsFalse (ci.TextInfo.IsRightToLeft, ci.Name);
184 public void Deserialization ()
186 TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
187 IDeserializationCallback dc = (ti as IDeserializationCallback);
188 dc.OnDeserialization (null);