示例#1
0
        public void ShouldThrowInvalidOperationExceptionOnAddUtfWhenBufferIsShaped()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8(SimpleText);

                Font.Shape(buffer);

                Assert.Throws <InvalidOperationException>(() => { buffer.AddUtf8("A"); });
            }
        }
示例#2
0
        public void ShouldAddUtfBySpan()
        {
            using (var buffer = new Buffer())
            {
                var bytes = Encoding.UTF8.GetBytes("A").AsSpan();

                buffer.AddUtf8(bytes);

                Assert.Equal(1, buffer.Length);

                var utf16 = "B".AsSpan();

                buffer.AddUtf16(utf16);

                Assert.Equal(2, buffer.Length);

                bytes = Encoding.UTF32.GetBytes("C");

                var utf32 = new int[] { bytes[0] };

                buffer.AddUtf32(utf32);

                Assert.Equal(3, buffer.Length);
            }
        }
示例#3
0
        public void ShouldAddUtfByString()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8("A");

                Assert.Equal(1, buffer.Length);

                buffer.AddUtf8("B");

                Assert.Equal(2, buffer.Length);

                buffer.AddUtf8("C");

                Assert.Equal(3, buffer.Length);
            }
        }
示例#4
0
        public void ShouldThrowInvalidOperationExceptionOnDeserializeGlyphsWhenBufferIsNonEmpty()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8("A");

                Assert.Throws <InvalidOperationException>(() => { buffer.DeserializeGlyphs(SerializedSimpleText); });
            }
        }
示例#5
0
        public void ShouldThrowInvalidOperationExceptionOnSerializeGlyphsWhenBufferIsUnShaped()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8("A");

                Assert.Throws <InvalidOperationException>(() => { buffer.SerializeGlyphs(); });
            }
        }
示例#6
0
        public void ShouldAppendBuffer()
        {
            using (var buffer = new Buffer())
                using (var source = new Buffer())
                {
                    source.AddUtf8("123");

                    buffer.Append(source, 0, source.Length);
                }
        }
示例#7
0
        public void ShouldAppendBuffer()
        {
            using (var buffer = new Buffer())
                using (var source = new Buffer())
                {
                    buffer.ContentType = ContentType.Unicode;

                    source.AddUtf8("123");

                    buffer.Append(source, 0, source.Length);
                }
        }
示例#8
0
        public void ShouldClearContents()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8(SimpleText);

                Assert.Equal(SimpleText.Length, buffer.GlyphInfos.Length);

                buffer.ClearContents();

                Assert.Empty(buffer.GlyphInfos);
            }
        }
示例#9
0
        public void ShouldHaveDefaultStateAfterReset()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8(SimpleText);

                buffer.Reset();

                Assert.Equal(ContentType.Invalid, buffer.ContentType);

                Assert.Equal(0, buffer.Length);
            }
        }
示例#10
0
        public void ShouldReverseClusters()
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf8("12");

                buffer.ReverseClusters();

                Assert.Equal(50u, buffer.GlyphInfos[0].Codepoint);
                Assert.Equal(1u, buffer.GlyphInfos[0].Cluster);

                Assert.Equal(49u, buffer.GlyphInfos[1].Codepoint);
                Assert.Equal(0u, buffer.GlyphInfos[1].Cluster);
            }
        }
示例#11
0
        public void ShouldHaveCorrectContentType()
        {
            using (var buffer = new Buffer())
            {
                Assert.Equal(ContentType.Invalid, buffer.ContentType);

                buffer.AddUtf8(SimpleText);

                Assert.Equal(ContentType.Unicode, buffer.ContentType);

                Font.Shape(buffer);

                Assert.Equal(ContentType.Glyphs, buffer.ContentType);
            }
        }
示例#12
0
        public void ShouldAddUtfBySpan()
        {
            using (var buffer = new Buffer())
            {
                var utf8 = Encoding.UTF8.GetBytes("A").AsSpan();

                buffer.AddUtf8(utf8);

                Assert.Equal(1, buffer.Length);

                var utf16 = "B".AsSpan();

                buffer.AddUtf16(utf16);

                Assert.Equal(2, buffer.Length);

                var utf32 = new[] { char.ConvertToUtf32("C", 0) };

                buffer.AddUtf32(utf32);

                Assert.Equal(3, buffer.Length);
            }
        }