X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Globalization%2FCompareInfoTest.cs;h=ccf702f8a923dc53bcb638e0ec0aab1e3ca6a711;hb=0be292818eb53868d1cfe4956ab3a033480d22c7;hp=30d5aa7434249a45822136803774d6b285094dfd;hpb=881f83658281916d8f0784df7c726ecb7cc289db;p=mono.git diff --git a/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs b/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs index 30d5aa74342..ccf702f8a92 100644 --- a/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs +++ b/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs @@ -15,7 +15,7 @@ namespace MonoTests.System.Globalization { [TestFixture] -public class CompareInfoTest : Assertion +public class CompareInfoTest { static bool doTest = Environment.GetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION") != "yes"; @@ -26,26 +26,29 @@ public class CompareInfoTest : Assertion { string s1 = "foo"; - AssertEquals ("Compare two empty strings", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", "")); - AssertEquals ("Compare string with empty string", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, "")); - AssertEquals ("Compare empty string with string", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", s1)); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", ""), "Compare two empty strings"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, ""), "Compare string with empty string"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", s1), "Compare empty string with string"); - AssertEquals ("Compare two empty strings, with 0 offsets", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "", 0)); - AssertEquals ("Compare string with empty string, with 0 offsets", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, "", 0)); - AssertEquals ("Compare empty string with string, with 0 offsets", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, s1, 0)); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "", 0), "Compare two empty strings, with 0 offsets"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, "", 0), "Compare string with empty string, with 0 offsets"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, s1, 0), "Compare empty string with string, with 0 offsets"); - AssertEquals ("Compare two empty strings, with 0 offsets and specified lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, "", 0, "".Length)); - AssertEquals ("Compare string with empty string, with 0 offsets and specified lengths", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, "", 0, "".Length)); - AssertEquals ("Compare empty string with string, with 0 offsets and specified lengths", -1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, s1, 0, s1.Length)); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, "", 0, "".Length), "Compare two empty strings, with 0 offsets and specified lengths"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, "", 0, "".Length), "Compare string with empty string, with 0 offsets and specified lengths"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", 0, "".Length, s1, 0, s1.Length), "Compare empty string with string, with 0 offsets and specified lengths"); - AssertEquals ("Compare two strings, with offsets == string lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, s1.Length)); - AssertEquals ("Compare two strings, with first offset == string length", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, 0)); - AssertEquals ("Compare two strings, with second offset == string length", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1, s1.Length)); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, s1.Length), "Compare two strings, with offsets == string lengths"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s1.Length, s1, 0), "Compare two strings, with first offset == string length"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1, s1.Length), "Compare two strings, with second offset == string length"); - AssertEquals ("Compare two strings, with zero lengths", 0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, 0)); - AssertEquals ("Compare two strings, with first length zero", -1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, s1.Length)); - AssertEquals ("Compare strings, with second length zero", 1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, s1, 0, 0)); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, 0), "Compare two strings, with zero lengths"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, 0, s1, 0, s1.Length), "Compare two strings, with first length zero"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare (s1, 0, s1.Length, s1, 0, 0), "Compare strings, with second length zero"); + Assert.AreEqual (0, CultureInfo.InvariantCulture.CompareInfo.Compare (null, null), "Compare two null references"); + Assert.AreEqual (1, CultureInfo.InvariantCulture.CompareInfo.Compare ("", null), "Compare a string to a null reference"); + Assert.AreEqual (-1, CultureInfo.InvariantCulture.CompareInfo.Compare (null, ""), "Compare a null reference to a string"); } // Culture-sensitive collation tests @@ -74,7 +77,7 @@ public class CompareInfoTest : Assertion void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci) { byte [] actual = ci.GetSortKey (test, opt).KeyData; - AssertEquals (message, expected, actual); + Assert.AreEqual (expected, actual, message); } void AssertSortKeyLevel5 (string message, byte [] expected, string test) @@ -86,7 +89,7 @@ public class CompareInfoTest : Assertion ; byte [] actual = new byte [tmp.Length - idx]; Array.Copy (tmp, idx, actual, 0, actual.Length); - AssertEquals (message, expected, actual); + Assert.AreEqual (expected, actual, message); } void AssertCompare (string message, int result, string s1, string s2) @@ -105,11 +108,11 @@ public class CompareInfoTest : Assertion { int ret = ci.Compare (s1, s2, opt); if (result == 0) - AssertEquals (message, 0, ret); + Assert.AreEqual (0, ret, message); else if (result < 0) - Assert (message + String.Format ("(neg: {0})", ret), ret < 0); + Assert.IsTrue (ret < 0, message + String.Format ("(neg: {0})", ret)); else - Assert (message + String.Format ("(pos: {0})", ret), ret > 0); + Assert.IsTrue (ret > 0, message + String.Format ("(pos: {0})", ret)); } void AssertCompare (string message, int result, @@ -117,11 +120,11 @@ public class CompareInfoTest : Assertion { int ret = invariant.Compare (s1, idx1, len1, s2, idx2, len2); if (result == 0) - AssertEquals (message, 0, ret); + Assert.AreEqual (0, ret, message); else if (result < 0) - Assert (message, ret < 0); + Assert.IsTrue (ret < 0, message); else - Assert (message, ret > 0); + Assert.IsTrue (ret > 0, message); } void AssertCompare (string message, int result, @@ -130,144 +133,126 @@ public class CompareInfoTest : Assertion { int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt); if (result == 0) - AssertEquals (message, 0, ret); + Assert.AreEqual (0, ret, message); else if (result < 0) - Assert (message, ret < 0); + Assert.IsTrue (ret < 0, message); else - Assert (message, ret > 0); + Assert.IsTrue (ret > 0, message); } void AssertIndexOf (string message, int expected, string source, char target) { - AssertEquals (message, expected, - invariant.IndexOf (source, target)); + Assert.AreEqual (expected, invariant.IndexOf (source, target), message); } void AssertIndexOf (string message, int expected, string source, char target, CompareOptions opt) { - AssertEquals (message, expected, - invariant.IndexOf (source, target, opt)); + Assert.AreEqual (expected, invariant.IndexOf (source, target, opt), message); } void AssertIndexOf (string message, int expected, string source, char target, int idx, int len, CompareOptions opt, CompareInfo ci) { - AssertEquals (message, expected, - ci.IndexOf (source, target, idx, len, opt)); + Assert.AreEqual (expected, ci.IndexOf (source, target, idx, len, opt), message); } void AssertIndexOf (string message, int expected, string source, string target) { - AssertEquals (message, expected, - invariant.IndexOf (source, target)); + Assert.AreEqual (expected, invariant.IndexOf (source, target), message); } void AssertIndexOf (string message, int expected, string source, string target, CompareOptions opt) { - AssertEquals (message, expected, - invariant.IndexOf (source, target, opt)); + Assert.AreEqual (expected, invariant.IndexOf (source, target, opt), message); } void AssertIndexOf (string message, int expected, string source, string target, int idx, int len, CompareOptions opt, CompareInfo ci) { - AssertEquals (message, expected, - ci.IndexOf (source, target, idx, len, opt)); + Assert.AreEqual (expected, ci.IndexOf (source, target, idx, len, opt), message); } void AssertLastIndexOf (string message, int expected, string source, char target) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target), message); } void AssertLastIndexOf (string message, int expected, string source, char target, CompareOptions opt) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target, opt)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target, opt), message); } void AssertLastIndexOf (string message, int expected, string source, char target, int idx, int len) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target, idx, len)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target, idx, len), message); } void AssertLastIndexOf (string message, int expected, string source, char target, int idx, int len, CompareOptions opt, CompareInfo ci) { - AssertEquals (message, expected, - ci.LastIndexOf (source, target, idx, len, opt)); + Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message); } void AssertLastIndexOf (string message, int expected, string source, string target) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target), message); } void AssertLastIndexOf (string message, int expected, string source, string target, CompareOptions opt) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target, opt)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target, opt), message); } void AssertLastIndexOf (string message, int expected, string source, string target, int idx, int len) { - AssertEquals (message, expected, - invariant.LastIndexOf (source, target, idx, len)); + Assert.AreEqual (expected, invariant.LastIndexOf (source, target, idx, len), message); } void AssertLastIndexOf (string message, int expected, string source, string target, int idx, int len, CompareOptions opt, CompareInfo ci) { - AssertEquals (message, expected, - ci.LastIndexOf (source, target, idx, len, opt)); + Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message); } void AssertIsPrefix (string message, bool expected, string source, string target) { - Assert (message, expected == invariant.IsPrefix ( - source, target)); + Assert.IsTrue (expected == invariant.IsPrefix (source, target), message); } void AssertIsPrefix (string message, bool expected, string source, string target, CompareOptions opt) { - Assert (message, expected == invariant.IsPrefix ( - source, target, opt)); + Assert.IsTrue (expected == invariant.IsPrefix (source, target, opt), message); } void AssertIsSuffix (string message, bool expected, string source, string target) { - Assert (message, expected == invariant.IsSuffix ( - source, target)); + Assert.IsTrue (expected == invariant.IsSuffix (source, target), message); } void AssertIsSuffix (string message, bool expected, string source, string target, CompareOptions opt) { - Assert (message, expected == invariant.IsSuffix ( - source, target, opt)); + Assert.IsTrue (expected == invariant.IsSuffix (source, target, opt), message); } [Test] public void GetSortKey () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // AE == \u00C6 AssertSortKey ("#1", new byte [] {0xE, 2, 0xE, 0x21, 1, 1, @@ -303,7 +288,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyIgnoreWidth () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0xE, 2, 1, 1, 0x13, 1, 1, 0}, "\uFF21"); @@ -319,7 +304,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyDiacritical () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0xE, 0x21, 1, 0xE, 1, 1, 1, 0}, "e\u0301"); @@ -372,7 +357,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyIgnoreNonSpaceKana () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0x22, 0x1A, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, @@ -392,7 +377,7 @@ public class CompareInfoTest : Assertion public void GetSortKeySpecialWeight () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0x22, 0xA, 0x22, 2, 1, 1, 1, 0xFF, 2, 0xFF, 0xFF, 1, 0}, @@ -483,7 +468,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyLevel5 () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // shift weight AssertSortKeyLevel5 ("#8", new byte [] { @@ -511,6 +496,33 @@ public class CompareInfoTest : Assertion } + [Test] + public void GetSortKey_Options () + { + Array values = Enum.GetValues (typeof (CompareOptions)); + foreach (int i in values) { + CompareOptions option = (CompareOptions) i; +#if NET_2_0 + if (option == CompareOptions.OrdinalIgnoreCase || option == CompareOptions.Ordinal) { + try { + french.GetSortKey ("foo", option); + Assert.Fail ("#1: " + option.ToString ()); + } catch (ArgumentException ex) { + Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2: " + option.ToString ()); + Assert.IsNotNull (ex.Message, "#2: " + option.ToString ()); + Assert.IsNotNull (ex.ParamName, "#3: " + option.ToString ()); + Assert.AreEqual ("options", ex.ParamName, "#4: " + option.ToString ()); + Assert.IsNull (ex.InnerException, "#5: " + option.ToString ()); + } + } else { + french.GetSortKey ("foo", option); + } +#else + french.GetSortKey ("foo", option); +#endif + } + } + [Test] #if NET_2_0 [Category ("NotDotNet")] @@ -518,7 +530,7 @@ public class CompareInfoTest : Assertion public void FrenchSort () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // invariant AssertSortKey ("#inv-1", new byte [] {0xE, 0xA, 0xE, 0x7C, 0xE, 0x99, 0xE, 0x21, 1, 2, 0x12, 1, 1, 1, 0}, "c\u00F4te"); @@ -546,7 +558,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyThai () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0x1E, 7, 0x1F, 0x28, 1, 3, 3, 1, 1, 1, 0}, @@ -611,7 +623,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyCzechTailoring () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#i1", new byte [] { 0xE, 0xA, 0xE, 0x2C, 1, 1, 1, 1, 0}, @@ -631,7 +643,7 @@ public class CompareInfoTest : Assertion public void GetSortKeyHungarianTailoring () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#1", new byte [] { 0xE, 0xE, 1, 1, 0x1A, 1, 1, 0}, @@ -683,7 +695,7 @@ public class CompareInfoTest : Assertion public void CustomCJKTable () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertSortKey ("#1", new byte [] { 0x9E, 9, 0x9E, 0x11, 1, 1, 1, 1, 0}, @@ -700,7 +712,7 @@ public class CompareInfoTest : Assertion public void CultureSensitiveCompare () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertCompare ("#1", -1, "1", "2"); AssertCompare ("#2", 1, "A", "a"); @@ -734,6 +746,17 @@ public class CompareInfoTest : Assertion // expansion // BUG in .NET 2.0: the same 00C6/00E6 issue. AssertCompare ("#21", -1, "\u00E6", "aes"); + +// bug #78748 + AssertCompare ("#22", -1, "++)", "+-+)"); + AssertCompare ("#23", -1, "+-+)", "+-+-)"); + AssertCompare ("#24", 1, "+-+-)", "++)"); + // BUG in .NET: it returns 1 + AssertCompare ("#25", -1, "+-+-)", "-+-+)"); + AssertCompare ("#26", -1, "+-+)", "-+-+)"); + AssertCompare ("#27", -1, "++)", "-+-+)"); + // bug #79714 + AssertCompare ("#28", 1, "aa ", "A"); } [Test] @@ -743,7 +766,7 @@ public class CompareInfoTest : Assertion public void CompareSpecialWeight () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // Japanese (in invariant) // BUG in .NET 2.0 : half-width kana should be bigger. @@ -770,7 +793,7 @@ public class CompareInfoTest : Assertion public void IndexOfChar () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIndexOf ("#1", -1, "ABC", '1'); AssertIndexOf ("#2", 2, "ABCABC", 'c', CompareOptions.IgnoreCase); @@ -790,7 +813,7 @@ public class CompareInfoTest : Assertion public void IndexOfCharMSBug () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIndexOf ("#1", 0, "\u00E6", 'a'); } @@ -799,7 +822,7 @@ public class CompareInfoTest : Assertion public void LastIndexOfChar () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertLastIndexOf ("#1", -1, "ABC", '1'); AssertLastIndexOf ("#2", 5, "ABCABC", 'c', CompareOptions.IgnoreCase); @@ -813,8 +836,10 @@ public class CompareInfoTest : Assertion AssertLastIndexOf ("#9", -1, "UA", '\u00C6'); AssertLastIndexOf ("#10", -1, "UE", '\u00C6'); AssertLastIndexOf ("#11", 0, "\\", '\\'); - AssertEquals ("#11en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\')); - AssertEquals ("#11ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\')); + Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\", '\\'), "#11en"); + Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\", '\\'), "#11ja"); + AssertLastIndexOf ("#12", 8, "/system/web", 'w'); + Assert.AreEqual (8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", 'w'), "#12sv"); } [Test] @@ -822,7 +847,7 @@ public class CompareInfoTest : Assertion public void LastIndexOfCharMSBug () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIndexOf ("#1", 0, "\u00E6", 'a'); } @@ -834,7 +859,7 @@ public class CompareInfoTest : Assertion public void IsPrefix () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIsPrefix ("#1", false, "ABC", "c", CompareOptions.IgnoreCase); AssertIsPrefix ("#2", false, "BC", "c", CompareOptions.IgnoreCase); @@ -858,15 +883,15 @@ public class CompareInfoTest : Assertion AssertIsPrefix ("#15", true, "\uff21\uff21", "\u3007\uff21", CompareOptions.None); AssertIsPrefix ("#16", true, "\uff21\uff21", "\uff21\u3007", CompareOptions.None); AssertIsPrefix ("#17", true, "\\b\\a a", "\\b\\a a"); - Assert ("#17en", new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a")); - Assert ("#17ja", new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a")); + Assert.IsTrue (new CultureInfo ("en").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17en"); + Assert.IsTrue (new CultureInfo ("ja").CompareInfo.IsPrefix ("\\b\\a a", "\\b\\a a"), "#17ja"); } [Test] public void IsPrefixSpecialWeight () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // Japanese (in invariant) AssertIsPrefix ("#1", false, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D"); @@ -903,7 +928,7 @@ public class CompareInfoTest : Assertion public void IsSuffix () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIsSuffix ("#1", true, "ABC", "c", CompareOptions.IgnoreCase); AssertIsSuffix ("#2", true, "BC", "c", CompareOptions.IgnoreCase); @@ -935,8 +960,8 @@ public class CompareInfoTest : Assertion AssertIsSuffix ("#18", true, "/test.css", ""); AssertIsSuffix ("#19", true, "/test.css", "/test.css"); AssertIsSuffix ("#20", true, "\\b\\a a", "\\b\\a a"); - Assert ("#20en", new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a")); - Assert ("#20ja", new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a")); + Assert.IsTrue (new CultureInfo ("en").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20en"); + Assert.IsTrue (new CultureInfo ("ja").CompareInfo.IsSuffix ("\\b\\a a", "\\b\\a a"), "#20ja"); } [Test] @@ -945,20 +970,18 @@ public class CompareInfoTest : Assertion public void IsSuffixMSBug () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertIsSuffix ("#1", true, "\u00E6", "e", CompareOptions.None); } [Test] -#if NET_2_0 - [Category ("NotDotNet")] -#endif public void IndexOfString () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); + AssertIndexOf ("#0", 0, "", "", CompareOptions.None); AssertIndexOf ("#1", -1, "ABC", "1", CompareOptions.None); AssertIndexOf ("#2", 2, "ABCABC", "c", CompareOptions.IgnoreCase); AssertIndexOf ("#3", 1, "ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth); @@ -969,31 +992,44 @@ public class CompareInfoTest : Assertion AssertIndexOf ("#8", 0, "-ABC", "-", CompareOptions.None); AssertIndexOf ("#9", 0, "--ABC", "--", CompareOptions.None); AssertIndexOf ("#10", -1, "--ABC", "--", 1, 2, CompareOptions.None, invariant); -// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). - AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None); + // U+3007 is completely ignored character. AssertIndexOf ("#12", 0, "\uff21\uff21", "\uff21", CompareOptions.None); -// BUG in .NET 2.0 : see \u3007 issue (mentioned above). - AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None); + AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", CompareOptions.None); AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", CompareOptions.None); AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", CompareOptions.None); // target is "empty" (in culture-sensitive context). AssertIndexOf ("#16", -1, String.Empty, "\u3007"); -// BUG in .NET 2.0 : see \u3007 issue (mentioned above). - AssertIndexOf ("#17", 0, "A", "\u3007"); + AssertIndexOf ("#18", 0, "ABC", "\u3007"); AssertIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a"); - AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a")); - AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a")); + Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"), "#19en"); + Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.IndexOf ("\\b\\a a", "\\b\\a a"), "#19ja"); } + [Test] +#if NET_2_0 + [Category ("NotDotNet")] +#endif + public void IndexOfStringWeird () + { +// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). + AssertIndexOf ("#11", 0, "AE", "\u00C6", CompareOptions.None); + +// BUG in .NET 2.0 : see \u3007 issue (mentioned above). + AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", CompareOptions.None); + +// BUG in .NET 2.0 : see \u3007 issue (mentioned above). + AssertIndexOf ("#17", 0, "A", "\u3007"); + } + [Test] public void IndexOfSpecialWeight () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // Japanese (in invariant) AssertIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D"); @@ -1015,13 +1051,10 @@ public class CompareInfoTest : Assertion } [Test] -#if NET_2_0 - [Category ("NotDotNet")] -#endif public void LastIndexOfString () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.None); AssertLastIndexOf ("#2", 5, "ABCABC", "c", CompareOptions.IgnoreCase); @@ -1030,31 +1063,50 @@ public class CompareInfoTest : Assertion AssertLastIndexOf ("#5", 4, "ABCABC", "BC", CompareOptions.IgnoreCase); AssertLastIndexOf ("#6", 4, "BBCBBC", "BC", CompareOptions.IgnoreCase); AssertLastIndexOf ("#7", 1, "original", "rig", CompareOptions.None); -// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). - AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None); + AssertLastIndexOf ("#9", 0, "-ABC", "-", CompareOptions.None); AssertLastIndexOf ("#10", 0, "--ABC", "--", CompareOptions.None); AssertLastIndexOf ("#11", -1, "--ABC", "--", 2, 2, CompareOptions.None, invariant); AssertLastIndexOf ("#12", -1, "--ABC", "--", 4, 2, CompareOptions.None, invariant); -// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). - AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None); + // U+3007 is completely ignored character. AssertLastIndexOf ("#14", 1, "\uff21\uff21", "\uff21", CompareOptions.None); -// BUG in .NET 2.0 : see \u3007 issue (mentioned above). - AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None); + AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", CompareOptions.None); AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", CompareOptions.None); AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", CompareOptions.None); AssertLastIndexOf ("#19", 0, "\\b\\a a", "\\b\\a a"); - AssertEquals ("#19en", 0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a")); - AssertEquals ("#19ja", 0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a")); + Assert.AreEqual (0, new CultureInfo ("en").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19en"); + Assert.AreEqual (0, new CultureInfo ("ja").CompareInfo.LastIndexOf ("\\b\\a a", "\\b\\a a"), "#19ja"); + // bug #80612 + AssertLastIndexOf ("#20", 8, "/system/web", "w"); + Assert.AreEqual (8, new CultureInfo ("sv").CompareInfo.LastIndexOf ("/system/web", "w"), "#20sv"); + + AssertLastIndexOf ("#21", 2, "foo", String.Empty); + } + + [Test] + [Category ("NotDotNet")] + public void LastIndexOfStringDotnetWeird () + { + if (!doTest) + Assert.Ignore ("Test is disabled."); + +// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). + AssertLastIndexOf ("#8", 0, "\u00E6", "ae", CompareOptions.None); + +// BUG in .NET 2.0 : see GetSortKey() test (mentioned above). + AssertLastIndexOf ("#13", 0, "AE", "\u00C6", CompareOptions.None); + +// BUG in .NET 2.0 : see \u3007 issue (mentioned above). + AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", CompareOptions.None); } [Test] public void LastIndexOfSpecialWeight () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // Japanese (in invariant) AssertLastIndexOf ("#1", -1, "\u30D1\u30FC\u30B9", "\uFF8A\uFF9F\uFF70\uFF7D"); @@ -1080,20 +1132,42 @@ public class CompareInfoTest : Assertion } [Test] - // for bug #76702 + public void LastIndexOfOrdinalString () + { + if (!doTest) + Assert.Ignore ("Test is disabled."); + + AssertLastIndexOf ("#1", -1, "ABC", "1", CompareOptions.Ordinal); + AssertLastIndexOf ("#2", 5, "ABCABC", "C", CompareOptions.Ordinal); + AssertLastIndexOf ("#3", -1, "ABCABC", "\uFF22", CompareOptions.Ordinal); + AssertLastIndexOf ("#4", 4, "ABCABC", "BC", CompareOptions.Ordinal); + AssertLastIndexOf ("#5", 4, "BBCBBC", "BC", CompareOptions.Ordinal); + AssertLastIndexOf ("#6", 1, "original", "rig", CompareOptions.Ordinal); + AssertLastIndexOf ("#7", 0, "\\b\\a a", "\\b\\a a", CompareOptions.Ordinal); + } + + [Test] public void NullCharacter () { - AssertEquals ("#1", -1, "MONO".IndexOf ("\0\0\0")); - AssertEquals ("#2", -1, "MONO".LastIndexOf ("\0\0\0")); - AssertEquals ("#3", 1, "MONO".CompareTo ("\0\0\0")); + // for bug #76702 + Assert.AreEqual (-1, "MONO".IndexOf ("\0\0\0"), "#1"); + Assert.AreEqual (-1, "MONO".LastIndexOf ("\0\0\0"), "#2"); + Assert.AreEqual (1, "MONO".CompareTo ("\0\0\0"), "#3"); + + // I don't really understand why they are so... + AssertIndexOf ("#4", 0, "\0\0", "\0"); + AssertIndexOf ("#5", -1, "\0", "\0\0"); + AssertIndexOf ("#6", -1, "foo", "\0"); + AssertLastIndexOf ("#7", 1, "\0\0", "\0"); + AssertLastIndexOf ("#8", -1, "\0", "\0\0"); + AssertLastIndexOf ("#9", -1, "foo", "\0"); } [Test] - [Category ("NotDotNet")] - // MS.NET treats it as equivalent, while in IndexOf() it does not match. + // LAMESPEC: MS.NET treats it as equivalent, while in IndexOf() it does not match. public void NullCharacterWeird () { - AssertEquals ("#4", -1, "MONO".CompareTo ("MONO\0\0\0")); + Assert.AreEqual (0, "MONO".CompareTo ("MONO\0\0\0"), "#4"); } #if NET_2_0 @@ -1102,7 +1176,7 @@ public class CompareInfoTest : Assertion public void OrdinalIgnoreCaseCompare () { if (!doTest) - return; + Assert.Ignore ("Test is disabled."); // matches // BUG in .NET 2.0 : see GetSortKey() test (mentioned above). @@ -1127,7 +1201,201 @@ public class CompareInfoTest : Assertion AssertCompare ("#13", 0, "ae", "AE", CompareOptions.OrdinalIgnoreCase); AssertCompare ("#14", 0, "ola", "OLA", CompareOptions.OrdinalIgnoreCase); } + + [Test] + public void OrdinalIgnoreCaseIndexOf () + { + AssertIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase); + AssertIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase); + AssertIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase); + } + + [Test] + public void OrdinalIgnoreCaseIndexOfChar () + { + AssertIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase); + AssertIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase); + AssertIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase); + } + + [Test] + public void OrdinalIgnoreCaseLastIndexOf () + { + AssertLastIndexOf ("#1-1", 0, "ABC", "abc", CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#1-2", -1, "AEBECE", "\u00E6", CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#1-3", -1, "@_@", "`_`", CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#1-4", 1, "ABCDE", "bc", CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#1-5", -1, "BBBBB", "ab", CompareOptions.OrdinalIgnoreCase); + } + + [Test] + public void OrdinalIgnoreCaseLastIndexOfChar () + { + AssertLastIndexOf ("#2-1", 0, "ABC", 'a', CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#2-2", -1, "AEBECE", '\u00C0', CompareOptions.OrdinalIgnoreCase); + AssertLastIndexOf ("#2-3", -1, "@_@", '`', CompareOptions.OrdinalIgnoreCase); + } + + [Test] // bug #80865 + public void IsPrefixOrdinalIgnoreCase () + { + Assert.IsTrue ("aaaa".StartsWith ("A", StringComparison.OrdinalIgnoreCase)); + } #endif + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void IsPrefix_SourceNull () + { + invariant.IsPrefix (null, "b"); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void IsPrefix_PrefixNull () + { + invariant.IsPrefix ("a", null, CompareOptions.None); + } + + [Test] + public void IsPrefix_PrefixEmpty () + { + Assert.IsTrue (invariant.IsPrefix ("a", String.Empty)); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IsPrefix_CompareOptions_Invalid () + { + invariant.IsPrefix ("a", "b", (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IsPrefix_CompareOptions_StringSort () + { + invariant.IsPrefix ("a", "b", CompareOptions.StringSort); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void IsSuffix_SourceNull () + { + invariant.IsSuffix (null, "b"); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void IsSuffix_SuffixNull () + { + invariant.IsSuffix ("a", null, CompareOptions.None); + } + + [Test] + public void IsSuffix_PrefixEmpty () + { + Assert.IsTrue (invariant.IsSuffix ("a", String.Empty)); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IsSuffix_CompareOptions_Invalid () + { + invariant.IsSuffix ("a", "b", (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IsSuffix_CompareOptions_StringSort () + { + invariant.IsSuffix ("a", "b", CompareOptions.StringSort); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void Compare_String_String_CompareOptions_Invalid () + { + // validation of CompareOptions is made before null checks + invariant.Compare (null, null, (CompareOptions) Int32.MinValue); + } + + [Test] + public void Compare_String_String_CompareOptions_StringSort () + { + // StringSort is valid for Compare only + Assert.AreEqual (-1, invariant.Compare ("a", "b", CompareOptions.StringSort)); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void Compare_String_Int_String_Int_CompareOptions_Invalid () + { + invariant.Compare (null, 0, null, 0, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void Compare_String_Int_Int_String_Int_Int_CompareOptions_Invalid () + { + invariant.Compare (null, 0, 0, null, 0, 0, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IndexOf_String_Char_Int_Int_CompareOptions_Invalid () + { + invariant.IndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IndexOf_String_Char_Int_Int_CompareOptions_StringSort () + { + invariant.IndexOf ("a", 'a', 0, 1, CompareOptions.StringSort); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IndexOf_String_String_Int_Int_CompareOptions_Invalid () + { + invariant.IndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void IndexOf_String_String_Int_Int_CompareOptions_StringSort () + { + invariant.IndexOf ("a", "a", 0, 1, CompareOptions.StringSort); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void LastIndexOf_String_Char_Int_Int_CompareOptions_Invalid () + { + invariant.LastIndexOf ("a", 'a', 0, 1, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void LastIndexOf_String_Char_Int_Int_CompareOptions_StringSort () + { + invariant.LastIndexOf ("a", 'a', 0, 1, CompareOptions.StringSort); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void LastIndexOf_String_String_Int_Int_CompareOptions_Invalid () + { + invariant.LastIndexOf ("a", "a", 0, 1, (CompareOptions) Int32.MinValue); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void LastIndexOf_String_String_Int_Int_CompareOptions_StringSort () + { + invariant.LastIndexOf ("a", "a", 0, 1, CompareOptions.StringSort); + } } } +