public void CustomTypeToStreamUtf8()
 {
     byte[] buffer = new byte[1024];
     MemoryStream stream = new MemoryStream(buffer);
     using(var writer = new StreamFormatter(stream, EncodingData.InvariantUtf8, pool)) {
         writer.Append(new Age(56));
         writer.Append(new Age(14, inMonths: true));
         var writtenText = Encoding.UTF8.GetString(buffer, 0, (int)stream.Position);
         Assert.Equal(writtenText, "56y14m");
     }
 }
        public void FormatString()
        {
            var buffer = new byte[1024];
            MemoryStream stream = new MemoryStream(buffer);

            using(var utf8Writer = new StreamFormatter(stream, FormattingData.InvariantUtf8, pool)) {
                utf8Writer.Append("Hello");
                utf8Writer.Append(" ");
                utf8Writer.Append("World!");
                utf8Writer.Append("\u0391"); // greek alpha
                utf8Writer.Append("\uD950\uDF21");
                AssertUtf8Equal(buffer.Slice(0, (int)stream.Position), "Hello World!\u0391\uD950\uDF21");
            }

            stream.Position = 0;
            using(var utf16Writer = new StreamFormatter(stream, FormattingData.InvariantUtf16, pool)) {
                utf16Writer.Append("Hello");
                utf16Writer.Append(" ");
                utf16Writer.Append("World!");
                utf16Writer.Append("\u0391");
                utf16Writer.Append("\uD950\uDF21");
                AssertUtf16Equal(buffer.Slice(0, (int)stream.Position), "Hello World!\u0391\uD950\uDF21");
            }
        }
        public void Int32ToStreamUtf8()
        {
            var buffer = new byte[1024];
            MemoryStream stream = new MemoryStream(buffer);

            using(var writer = new StreamFormatter(stream, FormattingData.InvariantUtf8, pool)) {
                writer.Append(100);
                writer.Append(-100);
                writer.Append('h');
                writer.Append("i!");
                AssertUtf8Equal(buffer.Slice(0, (int)stream.Position), "100-100hi!");
            }
        }
        public void FormatString()
        {
            var buffer = new byte[1024];
            MemoryStream stream = new MemoryStream(buffer);

            var utf8Writer = new StreamFormatter(stream, FormattingData.InvariantUtf8);
            utf8Writer.Append("Hello");
            utf8Writer.Append(" ");
            utf8Writer.Append("World!");
            utf8Writer.Append("\u0391"); // greek alpha
            //utf8Writer.Append("\uD950\uDF21"); // TODO: surrogate pair; this is NIY
            AssertUtf8Equal(buffer.Slice(0, (int)stream.Position), "Hello World!\u0391");

            stream.Position = 0;
            var utf16Writer = new StreamFormatter(stream, FormattingData.InvariantUtf16);
            utf16Writer.Append("Hello");
            utf16Writer.Append(" ");
            utf16Writer.Append("World!");
            utf8Writer.Append("\u0391");
            utf16Writer.Append("\uD950\uDF21");
            AssertUtf16Equal(buffer.Slice(0, (int)stream.Position), "Hello World!\u0391\uD950\uDF21");
        }