예제 #1
0
        public void TestCodePointAtBefore()
        {
            String s = "" + UChar.MinHighSurrogate +                  // isolated high
                       UChar.MinHighSurrogate +                       // pair
                       UChar.MinLowSurrogate + UChar.MinLowSurrogate; // isolated

            // low
            char[] c       = s.ToCharArray();
            int[]  avalues =
            {
                UChar.MinHighSurrogate,
                UChar.ToCodePoint(UChar.MinHighSurrogate,
                                  UChar.MinLowSurrogate),
                UChar.MinLowSurrogate, UChar.MinLowSurrogate
            };
            int[] bvalues =
            {
                UChar.MinHighSurrogate,
                UChar.MinHighSurrogate,
                UChar.ToCodePoint(UChar.MinHighSurrogate,
                                  UChar.MinLowSurrogate),
                UChar.MinLowSurrogate,
            };
            StringBuffer b = new StringBuffer(s);

            for (int i = 0; i < avalues.Length; ++i)
            {
                if (UChar.CodePointAt(s, i) != avalues[i])
                {
                    Errln("string at: " + i);
                }
                if (UChar.CodePointAt(c, i) != avalues[i])
                {
                    Errln("chars at: " + i);
                }
                if (UChar.CodePointAt(b, i) != avalues[i])
                {
                    Errln("stringbuffer at: " + i);
                }

                if (UChar.CodePointBefore(s, i + 1) != bvalues[i])
                {
                    Errln("string before: " + i);
                }
                if (UChar.CodePointBefore(c, i + 1) != bvalues[i])
                {
                    Errln("chars before: " + i);
                }
                if (UChar.CodePointBefore(b, i + 1) != bvalues[i])
                {
                    Errln("stringbuffer before: " + i);
                }
            }

            //cover codePointAtBefore with limit
            Logln("Testing codePointAtBefore with limit ...");
            for (int i = 0; i < avalues.Length; ++i)
            {
                if (UChar.CodePointAt(c, i, 4) != avalues[i])
                {
                    Errln("chars at: " + i);
                }
                if (UChar.CodePointBefore(c, i + 1, 0) != bvalues[i])
                {
                    Errln("chars before: " + i);
                }
            }
        }