Example #1
0
        public void CodePointValidation(string s)
        {
            var utf8string = new Utf8String(Encoding.UTF8.GetBytes(s));
            IEnumerator<UnicodeCodePoint> codePoints = utf8string.GetEnumerator();
            for (int i = 0; i < s.Length; i++)
            {
                Assert.True(codePoints.MoveNext());
                Assert.Equal((uint)s[i], (uint)codePoints.Current);
            }

            Assert.False(codePoints.MoveNext());
        }
Example #2
0
        public void CodePointValidation(string s)
        {
            var utf8string = new Utf8String(Encoding.UTF8.GetBytes(s));
            IEnumerator <UnicodeCodePoint> codePoints = utf8string.GetEnumerator();

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

            Assert.False(codePoints.MoveNext());
        }
Example #3
0
        public void EnsureCodeUnitsOfStringByEnumeratingBytes(byte[] expectedBytes, Utf8String utf8String)
        {
            Assert.Equal(expectedBytes.Length, utf8String.Length);
            Utf8String.Enumerator e = utf8String.GetEnumerator();

            int i = 0;

            while (e.MoveNext())
            {
                Assert.True(i < expectedBytes.Length);
                Assert.Equal(expectedBytes[i], (byte)e.Current);
                i++;
            }
            Assert.Equal(expectedBytes.Length, i);
        }
Example #4
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);
            }
        }
Example #5
0
        public void IterateMultibyteUtf8ButSingleByteUtf16()
        {
            var str = new Utf8String("“hat”");
            var it  = str.GetEnumerator();

            Assert.IsTrue(it.MoveNext());
            Assert.That(it.Current.Value, Is.EqualTo(0x201c));
            Assert.IsTrue(it.MoveNext());
            Assert.That(it.Current.Value, Is.EqualTo(0x68));
            Assert.IsTrue(it.MoveNext());
            Assert.That(it.Current.Value, Is.EqualTo(0x61));
            Assert.IsTrue(it.MoveNext());
            Assert.That(it.Current.Value, Is.EqualTo(0x74));
            Assert.IsTrue(it.MoveNext());
            Assert.That(it.Current.Value, Is.EqualTo(0x201d));
            Assert.IsFalse(it.MoveNext());
        }
Example #6
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);
            }
        }
        public void Utf8StringCodeUnitsEnumeratorIsAStruct()
        {
            var utf8CodeUnitsEnumerator = _anyUtf8String.GetEnumerator();

            Assert.True(_anyUtf8String.GetType().GetTypeInfo().IsValueType);
        }
Example #8
0
        public void EnsureCodeUnitsOfStringByEnumeratingBytes(byte[] expectedBytes, Utf8String utf8String)
        {
            Assert.Equal(expectedBytes.Length, utf8String.Length);
            Utf8String.Enumerator e = utf8String.GetEnumerator();

            int i = 0;
            while (e.MoveNext())
            {
                Assert.True(i < expectedBytes.Length);
                Assert.Equal(expectedBytes[i], (byte)e.Current);
                i++;
            }
            Assert.Equal(expectedBytes.Length, i);
        }