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");
89 Assert.AreEqual (t1.CultureName, t2.CultureName, "CultureName");
91 Assert.AreEqual (t1.IsReadOnly, t2.IsReadOnly, "IsReadOnly");
92 //FIXME Assert.AreEqual (t1.IsRightToLeft, t2.IsRightToLeft, "IsRightToLeft");
93 Assert.AreEqual (t1.LCID, t2.LCID, "LCID");
97 [Category ("NotWorking")] // OnDeserialization isn't completed
98 public void SerializationRoundtrip ()
100 TextInfo enus = new CultureInfo ("en-US").TextInfo;
101 BinaryFormatter bf = new BinaryFormatter ();
102 MemoryStream ms = new MemoryStream ();
103 bf.Serialize (ms, enus);
106 TextInfo clone = (TextInfo) bf.Deserialize (ms);
107 CompareProperties (enus, clone, true);
113 TextInfo enus = new CultureInfo ("en-US").TextInfo;
114 TextInfo clone = (TextInfo) enus.Clone ();
115 CompareProperties (enus, clone, true);
119 public void Clone_ReadOnly ()
121 TextInfo enus = TextInfo.ReadOnly (new CultureInfo ("en-US").TextInfo);
122 Assert.IsTrue (enus.IsReadOnly, "IsReadOnly-1");
123 TextInfo clone = (TextInfo) enus.Clone ();
124 Assert.IsFalse (clone.IsReadOnly, "IsReadOnly-2");
125 CompareProperties (enus, clone, false);
126 // cloned item is *NOT* read-only
130 public void ReadOnly ()
132 TextInfo enus = new CultureInfo ("en-US").TextInfo;
133 Assert.IsFalse (enus.IsReadOnly, "IsReadOnly-1");
134 TextInfo ro = TextInfo.ReadOnly (enus);
135 Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
136 CompareProperties (enus, ro, false);
140 public void IsRightToLeft ()
142 foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
173 Assert.IsTrue (ci.TextInfo.IsRightToLeft, ci.Name);
176 Assert.IsFalse (ci.TextInfo.IsRightToLeft, ci.Name);
183 public void Deserialization ()
185 TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
186 IDeserializationCallback dc = (ti as IDeserializationCallback);
187 dc.OnDeserialization (null);