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"));
28 Assert.AreEqual (" The Dude", ti.ToTitleCase (" The Dude"));
29 Assert.AreEqual ("La Guerra Yla Paz", ti.ToTitleCase ("la Guerra yLa pAz"));
30 Assert.AreEqual ("\tTab\tAnd\tPeace", ti.ToTitleCase ("\ttab\taNd\tpeaCE"));
34 public void ListSeparator ()
38 ti = new CultureInfo ("en-US", false).TextInfo;
39 Assert.AreEqual (",", ti.ListSeparator, "#1");
41 ti = CultureInfo.InvariantCulture.TextInfo;
42 Assert.AreEqual (",", ti.ListSeparator, "#2");
44 ti = new CultureInfo ("nl-BE", false).TextInfo;
45 Assert.AreEqual (";", ti.ListSeparator, "#3");
49 public void TitleCase2 ()
51 foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
52 Check (ci, "AB", "AB");
53 Check (ci, "ab", "Ab");
54 Check (ci, "aB", "Ab");
55 Check (ci, "1Ab", "1Ab");
56 Check (ci, "abc AB ab aB Ab ABc 1AB 1Ab 1ab 1aB",
57 "Abc AB Ab Ab Ab Abc 1AB 1Ab 1Ab 1Ab");
58 Check (ci, "LJ", "LJ");
59 Check (ci, "lj", "Lj");
60 Check (ci, "lJ", "Lj");
61 Check (ci, "lj abc ljabc", "Lj Abc Ljabc");
62 Check (ci, "ab", "Ab");
64 // Some greek titlecase characters
65 Check (ci, "\u01c4", "\u01c5");
66 Check (ci, "\u01c5", "\u01c5");
67 Check (ci, "\u01c6", "\u01c5");
68 Check (ci, "\u01ca", "\u01cb");
69 Check (ci, "\u01cb", "\u01cb");
70 Check (ci, "\u01cc", "\u01cb");
71 // Roman numbers are not converted unlike ToUpper().
72 Check (ci, "\u2170", "\u2170");
73 Check (ci, "\u24e9", "\u24e9");
77 private void Check (CultureInfo ci, string src, string expected)
79 Assert.AreEqual (expected, ci.TextInfo.ToTitleCase (src), src + " at culture " + ci.LCID);
82 private void CompareProperties (TextInfo t1, TextInfo t2, bool compareReadOnly)
84 Assert.AreEqual (t1.ANSICodePage, t2.ANSICodePage, "ANSICodePage");
85 Assert.AreEqual (t1.EBCDICCodePage, t2.EBCDICCodePage, "EBCDICCodePage");
86 Assert.AreEqual (t1.ListSeparator, t2.ListSeparator, "ListSeparator");
87 Assert.AreEqual (t1.MacCodePage, t2.MacCodePage, "MacCodePage");
88 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");
99 [Category ("NotWorking")] // OnDeserialization isn't completed
100 public void SerializationRoundtrip ()
102 TextInfo enus = new CultureInfo ("en-US").TextInfo;
103 BinaryFormatter bf = new BinaryFormatter ();
104 MemoryStream ms = new MemoryStream ();
105 bf.Serialize (ms, enus);
108 TextInfo clone = (TextInfo) bf.Deserialize (ms);
109 CompareProperties (enus, clone, true);
116 TextInfo enus = new CultureInfo ("en-US").TextInfo;
117 TextInfo clone = (TextInfo) enus.Clone ();
118 CompareProperties (enus, clone, true);
122 public void Clone_ReadOnly ()
124 TextInfo enus = TextInfo.ReadOnly (new CultureInfo ("en-US").TextInfo);
125 Assert.IsTrue (enus.IsReadOnly, "IsReadOnly-1");
126 TextInfo clone = (TextInfo) enus.Clone ();
127 Assert.IsFalse (clone.IsReadOnly, "IsReadOnly-2");
128 CompareProperties (enus, clone, false);
129 // cloned item is *NOT* read-only
133 public void ReadOnly ()
135 TextInfo enus = new CultureInfo ("en-US").TextInfo;
136 Assert.IsFalse (enus.IsReadOnly, "IsReadOnly-1");
137 TextInfo ro = TextInfo.ReadOnly (enus);
138 Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
139 CompareProperties (enus, ro, false);
143 public void IsRightToLeft ()
145 foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
174 Assert.IsTrue (ci.TextInfo.IsRightToLeft, ci.Name);
177 Assert.IsFalse (ci.TextInfo.IsRightToLeft, ci.Name);
185 public void Deserialization ()
187 TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
188 IDeserializationCallback dc = (ti as IDeserializationCallback);
189 dc.OnDeserialization (null);