Пример #1
0
        public void CharacterLength()
        {
            string        s1  = "1!a $\uE000";
            StringBuilder sb1 = new StringBuilder(s1);

            for (int nIndex = 0; nIndex < s1.Length; ++nIndex)
            {
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(s1, nIndex));
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(s1, nIndex));
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(sb1, nIndex));
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(sb1, nIndex));
            }

            string        s2  = "\uDF80\uD800";
            StringBuilder sb2 = new StringBuilder(s2);

            for (int nIndex = 0; nIndex < s2.Length; ++nIndex)
            {
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(s2, nIndex));
                Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(sb2, nIndex));
            }

            string        s3  = "\uD800\uDF80";
            StringBuilder sb3 = new StringBuilder(s3);

            Assert.AreEqual(2, UnicodeUtility.GetCharacterLength(s3, 0));
            Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(s3, 1));
            Assert.AreEqual(2, UnicodeUtility.GetCharacterLength(sb3, 0));
            Assert.AreEqual(1, UnicodeUtility.GetCharacterLength(sb3, 1));
        }
Пример #2
0
 public void CharacterLengthLargeIndex()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => UnicodeUtility.GetCharacterLength("a", 1));
     Assert.Throws <ArgumentOutOfRangeException>(() => UnicodeUtility.GetCharacterLength(new StringBuilder("a"), 1));
 }
Пример #3
0
 public void CharacterLengthNullString()
 {
     Assert.Throws <ArgumentNullException>(() => UnicodeUtility.GetCharacterLength((string)null, 1));
     Assert.Throws <ArgumentNullException>(() => UnicodeUtility.GetCharacterLength((StringBuilder)null, 1));
 }