// Implementations are intentionally split to avoid boxing
        private void TestCodePointForwardEnumerator(string s, Utf8String u8s)
        {
            List<UnicodeCodePoint> codePoints = new List<UnicodeCodePoint>();
            Utf8String.CodePointEnumerator it = u8s.CodePoints.GetEnumerator();
            while (it.MoveNext())
            {
                codePoints.Add(it.Current);
            }

            Utf16LittleEndianCodePointEnumerable utf16CodePoints = new Utf16LittleEndianCodePointEnumerable(s);
            Assert.Equal(utf16CodePoints, codePoints);

            Utf8String u8s2 = new Utf8String(codePoints);
            Assert.Equal(u8s, u8s2);
            Assert.Equal(s, u8s2.ToString());
        }
Beispiel #2
0
        public void AsciiStringEnumerators(string s)
        {
            Utf8String u8s = new Utf8String(Encoding.UTF8.GetBytes(s));

            Utf8String.Enumerator          e   = u8s.GetEnumerator();
            Utf8String.CodePointEnumerator cpe = u8s.CodePoints.GetEnumerator();

            Assert.Equal(s.Length, u8s.Length);
            for (int i = 0; i < s.Length; i++)
            {
                Assert.True(e.MoveNext());
                Assert.True(cpe.MoveNext());
                Assert.Equal((byte)s[i], (byte)u8s[i]);
                Assert.Equal(u8s[i], e.Current);
                Assert.Equal((byte)s[i], (byte)(uint)cpe.Current);
            }
        }