コード例 #1
0
        private void EnsureComparesConsistent(string left, string right)
        {
            String8 left8  = left.TestConvert();
            String8 right8 = right.TestConvert();

            CompareResult caseSensitiveExpected   = ToResult(String.Compare(left, right, StringComparison.Ordinal));
            CompareResult caseInsensitiveExpected = ToResult(String.Compare(left, right, StringComparison.OrdinalIgnoreCase));

            Assert.AreEqual(caseSensitiveExpected, ToResult(left8.CompareTo(right8)), "Case sensitive comparison result incorrect.");
            Assert.AreEqual(caseInsensitiveExpected, ToResult(left8.CompareTo(right8, true)), "Case insensitive comparison result incorrect.");

            Assert.AreEqual(caseSensitiveExpected, ToResult(left8.CompareTo(right)), "Case sensitive String8 to string comparison result incorrect.");
            Assert.AreEqual(caseInsensitiveExpected, ToResult(left8.CompareTo(right, true)), "Case insensitive String8 to string comparison result incorrect.");

            // StartsWith and CompareAsPrefixTo
            Assert.AreEqual(left.StartsWith(right), left8.StartsWith(right8));
            Assert.AreEqual(left.StartsWith(right, StringComparison.OrdinalIgnoreCase), left8.StartsWith(right8, true));
            Assert.AreEqual(right.StartsWith(left), right8.StartsWith(left8));
            Assert.AreEqual(right.StartsWith(left, StringComparison.OrdinalIgnoreCase), right8.StartsWith(left8, true));

            // Case Insensitive Stable is the insensitive order, then the sensitive order for ties
            CompareResult caseInsensitiveStableExpected = (caseInsensitiveExpected == CompareResult.Equal ? caseSensitiveExpected : caseInsensitiveExpected);

            Assert.AreEqual(caseInsensitiveStableExpected, ToResult(left8.CompareCaseInsensitiveStableTo(right8)), "Case insensitive stable String8 to string comparison result incorrect.");
        }