public void CustomTypeToString()
 {
     var sb = new StringFormatter();
     sb.Append(new Age(56));
     sb.Append(new Age(14, inMonths: true));
     Assert.Equal(sb.ToString(), "56y14m");
 }
        public void FormatGuid()
        {
            var guid = Guid.NewGuid();
            var sb = new StringFormatter();

            sb.Append(guid);
            Assert.Equal(guid.ToString(), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'D');
            Assert.Equal(guid.ToString("D"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'N');
            Assert.Equal(guid.ToString("N"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'B');
            Assert.Equal(guid.ToString("B"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'P');
            Assert.Equal(guid.ToString("P"), sb.ToString());
            sb.Clear();
        }
 public void BasicStringFormatter()
 {
     var sb = new StringFormatter();
     sb.Append("hi");
     sb.Append(1);
     sb.Append("hello");
     sb.Append((sbyte)-20);
     Assert.Equal("hi1hello-20", sb.ToString());
 }
示例#4
0
        public void CustomCulture()
        {
            var sb = new StringFormatter();
            sb.Encoding = EncodingProvider.CreateEncoding("pl-PL");

            sb.Append(-10000, TextFormat.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
示例#5
0
        public void CustomCulture()
        {
            var sb = new StringFormatter();
            sb.Encoding = Culture5;

            sb.Append(-1234567890);
            Assert.Equal("_?BBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJAAAAA", sb.ToString());
        }
示例#6
0
        public void CustomCulture()
        {
            var sb = new StringFormatter(ArrayPool<byte>.Shared);
            sb.FormattingData = FormattingDataProvider.CreateFormattingData("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
        public void FormatDateTimeR()
        {
            var time = DateTime.UtcNow;
            var sb   = new StringFormatter();

            sb.Append(time, Format.Symbol.R);
            Assert.Equal(time.ToString("R"), sb.ToString());
            sb.Clear();
        }
 public void CheckTimeSpan(TimeSpan value, string format)
 {
     var parsed = Format.Parse(format);
     var formatter = new StringFormatter(pool);
     formatter.Append(value, parsed);
     var result = formatter.ToString();
     var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
     Assert.Equal(clrResult, result);
 }
示例#9
0
        public void FormatDateTimeOffsetR()
        {
            var time = DateTimeOffset.UtcNow;
            var sb   = new StringFormatter(pool);

            sb.Append(time, 'R');
            Assert.Equal(time.ToString("R"), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeO()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'O');
            Assert.Equal(time.ToString("O", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
示例#11
0
        public void CustomCulture()
        {
            var sb = new StringFormatter(pool);

            sb.FormattingData = Culture5;

            sb.Append(-1234567890);
            Assert.Equal("_?BBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJAAAAA", sb.ToString());
        }
示例#12
0
        public void CustomCulture()
        {
            var sb = new StringFormatter();

            sb.FormattingData = FormattingDataProvider.CreateFormattingData("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
        public void FormatTimeSpan()
        {
            var time = new TimeSpan(1000, 23, 40, 30, 12345);
            var sb   = new StringFormatter();

            sb.Append(time);
            Assert.Equal(time.ToString("", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeO()
        {
            var time = DateTime.UtcNow;
            var sb   = new StringFormatter();

            sb.Append(time, 'O');
            Assert.Equal(time.ToString("O", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeG()
        {
            var time = DateTime.UtcNow;
            var sb   = new StringFormatter();

            sb.Append(time, 'G');
            Assert.Equal(time.ToString("G"), sb.ToString());
            sb.Clear();
        }
示例#16
0
        public void CustomCulture()
        {
            var pool = new ManagedBufferPool<byte>(1024);
            var sb = new StringFormatter(pool);
            sb.FormattingData = FormattingDataProvider.CreateFormattingData("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
        public void FormatDateTimeG()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'G');
            Assert.Equal(time.ToString("G"), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeOffsetR()
        {
            var time = DateTimeOffset.UtcNow;
            var sb = new StringFormatter(pool);

            sb.Append(time, 'R');
            Assert.Equal(time.ToString("R"), sb.ToString());
            sb.Clear();
        }
示例#19
0
        public void CustomCulture()
        {
            var sb = new StringFormatter();

            sb.SymbolTable = EncodingProvider.CreateEncoding("pl-PL");

            sb.Append(-10000, 'N');
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
        public void FormatTimeSpan()
        {
            var time = new TimeSpan(1000, 23, 40, 30, 12345);
            var sb = new StringFormatter();

            sb.Append(time);
            Assert.Equal(time.ToString("", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
示例#21
0
        public void CustomCulture()
        {
            var sb = new StringFormatter(ArrayPool <byte> .Shared);

            sb.Encoding = EncodingProvider.CreateEncoding("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
        public void FormatXPrecision()
        {
            var x = StandardFormat.Parse("x10");
            var X = StandardFormat.Parse("X10");

            var sb = new StringFormatter();

            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("00000000ff00000000FF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("00FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("00FFFFFFFE", sb.ToString());
        }
        public void FormatX()
        {
            var x = StandardFormat.Parse("x");
            var X = StandardFormat.Parse("X");

            var sb = new StringFormatter();

            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("ffFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("FFFFFFFE", sb.ToString());
        }
示例#24
0
        public void CustomCulture()
        {
            ManagedBufferPool <byte> pool = new ManagedBufferPool <byte>(1024);
            var sb = new StringFormatter(pool);

            sb.FormattingData = Culture5;

            sb.Append(-1234567890);
            Assert.Equal("_?BBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJAAAAA", sb.ToString());
        }
        public string FormatWithStringFormatter()
        {
            var builder = new StringFormatter(this.Numbers);

            for (var i = 0; i < this.Numbers; i++)
            {
                builder.Append(i % 10);
            }

            return(builder.ToString());
        }
示例#26
0
        public string InvariantFormatStruct()
        {
            var sb = new StringFormatter(NumbersToWrite * 2, pool);

            for (int i = 0; i < NumbersToWrite; i++)
            {
                sb.Append(new Age(i % 10));
            }

            return(sb.ToString());
        }
示例#27
0
        public string InvariantFormatIntDec()
        {
            var sb = new StringFormatter(NumbersToWrite, pool);

            for (int i = 0; i < NumbersToWrite; i++)
            {
                sb.Append(((int)(i % 10)));
            }

            return(sb.ToString());
        }
示例#28
0
        public void CheckTimeSpan(TimeSpan value, string format)
        {
            var parsed    = Format.Parse(format);
            var formatter = new StringFormatter(pool);

            formatter.Append(value, parsed);
            var result    = formatter.ToString();
            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);

            Assert.Equal(clrResult, result);
        }
        public void FormatDefault()
        {
            var sb = new StringFormatter();

            sb.Append('C');
            sb.Append((sbyte)-10);
            sb.Append((byte)99);
            sb.Append((short)-10);
            sb.Append((ushort)99);
            sb.Append((int)-10);
            sb.Append((uint)99);
            sb.Append((long)-10);
            sb.Append((ulong)99);
            var result = sb.ToString();

            Assert.Equal("C-1099-1099-1099-1099", result);
        }
        private void CheckByte(byte value, string format, string expected)
        {
            var formatter = new StringFormatter(pool);
            var parsed = Format.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
示例#31
0
        public string InvariantFormatIntHex()
        {
            var sb     = new StringFormatter(NumbersToWrite, pool);
            var format = new StandardFormat('X', StandardFormat.NoPrecision);

            for (int i = 0; i < NumbersToWrite; i++)
            {
                sb.Append(((int)(i % 10)), format);
            }

            return(sb.ToString());
        }
        private void CheckInt64(long value, string format, string expected, StringFormatter formatter)
        {
            var parsed = StandardFormat.Parse(format);

            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();

            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);

            Assert.Equal(clrResult, result);
        }
        public void FloatFormatting()
        {
            var sb = new StringFormatter(pool);

            sb.Append(Double.NaN);
            var result = sb.ToString();
            Assert.Equal("NaN", result);
            sb.Clear();

            sb.Append(Double.PositiveInfinity);
            result = sb.ToString();
            Assert.Equal("Infinity", result);
            sb.Clear();

            sb.Append(Double.NegativeInfinity);
            result = sb.ToString();
            Assert.Equal("-Infinity", result);
            sb.Clear();

            sb.Append(1.2);
            result = sb.ToString();
            Assert.Equal("1.2", result);
        }
示例#34
0
        public string CustomCultureFormat()
        {
            var sb = new StringFormatter(NumbersToWrite * 3, pool);

            sb.SymbolTable = _symbolTable;

            for (int i = 0; i < NumbersToWrite; i++)
            {
                var next = (i % 128) + 101;
                sb.Append(next);
            }

            return(sb.ToString());
        }
示例#35
0
        public string FormatGuid()
        {
            var guid         = Guid.NewGuid();
            var guidsToWrite = NumbersToWrite / 10;

            var sb = new StringFormatter(guidsToWrite * 36, pool);

            for (int i = 0; i < guidsToWrite; i++)
            {
                sb.Append(guid);
            }

            return(sb.ToString());
        }
        public void FormatDPrecision()
        {
            var format = Format.Parse("D3");
            var sb     = new StringFormatter(pool);

            sb.Append((sbyte)-10, format);
            sb.Append((byte)99, format);
            sb.Append((short)-10, format);
            sb.Append((ushort)99, format);
            sb.Append((int)-10, format);
            sb.Append((uint)99, format);
            sb.Append((long)-10, format);
            sb.Append((ulong)99, format);
            var result = sb.ToString();

            Assert.Equal("-010099-010099-010099-010099", result);
        }
        public void FormatG()
        {
            var format = ParsedFormat.Parse("G");
            var sb     = new StringFormatter();

            sb.Append((sbyte)-10, format);
            sb.Append((byte)99, format);
            sb.Append((short)-10, format);
            sb.Append((ushort)99, format);
            sb.Append((int)-10, format);
            sb.Append((uint)99, format);
            sb.Append((long)-10, format);
            sb.Append((ulong)99, format);
            var result = sb.ToString();

            Assert.Equal("-1099-1099-1099-1099", result);
        }
        private void CheckByte(byte value, string format, string expected)
        {
            var formatter = new StringFormatter();
            var parsed    = ParsedFormat.Parse(format);

            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();

            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);

            Assert.Equal(clrResult, result);
        }
        public void FormatNPrecision()
        {
            var format = StandardFormat.Parse("N1");
            var sb     = new StringFormatter();

            sb.Append((sbyte)-10, format);
            sb.Append((byte)99, format);
            sb.Append((short)-10, format);
            sb.Append((ushort)99, format);
            sb.Append((int)-10, format);
            sb.Append((uint)99, format);
            sb.Append((long)-10, format);
            sb.Append((ulong)99, format);
            var result = sb.ToString();

            Assert.Equal("-10.099.0-10.099.0-10.099.0-10.099.0", result);
        }
        public void FloatFormatting()
        {
            var sb = new StringFormatter();

            sb.Append(Double.NaN);
            var result = sb.ToString();

            Assert.Equal("NaN", result);
            sb.Clear();

            sb.Append(Double.PositiveInfinity);
            result = sb.ToString();
            Assert.Equal("Infinity", result);
            sb.Clear();

            sb.Append(Double.NegativeInfinity);
            result = sb.ToString();
            Assert.Equal("-Infinity", result);
            sb.Clear();

            sb.Append(1.2);
            result = sb.ToString();
            Assert.Equal("1.2", result);
        }
示例#41
0
 private void InvariantFormatStruct()
 {
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(numbersToWrite * 2, pool);
         for (int i = 0; i < numbersToWrite; i++)
         {
             sb.Append(new Age(i % 10));
         }
         var text = sb.ToString();
         if (text.Length != numbersToWrite * 2)
         {
             throw new Exception($"test failed [{text.Length} != {numbersToWrite * 2}]");
         }
     }
     PrintTime();
 }
示例#42
0
 private void InvariantFormatIntHex()
 {
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(numbersToWrite, pool);
         for (int i = 0; i < numbersToWrite; i++)
         {
             sb.Append(((int)(i % 10)), Format.Parsed.HexUppercase);
         }
         var text = sb.ToString();
         if (text.Length != numbersToWrite)
         {
             throw new Exception("test failed");
         }
     }
     PrintTime();
 }
示例#43
0
 private void InvariantFormatIntDec()
 {
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(numbersToWrite, pool);
         for (int i = 0; i < numbersToWrite; i++)
         {
             sb.Append(((int)(i % 10)));
         }
         var text = sb.ToString();
         if (text.Length != numbersToWrite)
         {
             throw new Exception("test failed");
         }
     }
     PrintTime();
 }
        private void InvariantFormatIntHex()
        {
            ManagedBufferPool <byte> pool = new ManagedBufferPool <byte>(1024);

            timer.Restart();
            for (int itteration = 0; itteration < itterationsInvariant; itteration++)
            {
                StringFormatter sb = new StringFormatter(numbersToWrite, pool);
                for (int i = 0; i < numbersToWrite; i++)
                {
                    sb.Append(((int)(i % 10)), Format.Parsed.HexUppercase);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
示例#45
0
        private void InvariantFormatIntHex()
        {
            ParsedFormat format = new ParsedFormat('X', ParsedFormat.NoPrecision);

            timer.Restart();
            for (int itteration = 0; itteration < itterationsInvariant; itteration++)
            {
                StringFormatter sb = new StringFormatter(numbersToWrite, pool);
                for (int i = 0; i < numbersToWrite; i++)
                {
                    sb.Append(((int)(i % 10)), format);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
示例#46
0
 private void InvariantFormatStruct()
 {
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(numbersToWrite * 2, pool);
         for (int i = 0; i < numbersToWrite; i++)
         {
             sb.Append(new Age(i % 10));
         }
         var text = sb.ToString();
         if (text.Length != numbersToWrite * 2)
         {
             throw new Exception("test failed");
         }
     }
     PrintTime();
 }
        private void CheckInt64(long value, string format, string expected, StringFormatter formatter)
        {
            var parsed = TextFormat.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
示例#48
0
        private void CustomCultureFormat()
        {
            StringFormatter sb = new StringFormatter(numbersToWrite * 3, pool);
            sb.FormattingData = CreateCustomCulture();

            timer.Restart();
            for (int itteration = 0; itteration < itterationsCulture; itteration++)
            {
                sb.Clear();
                for (int i = 0; i < numbersToWrite; i++)
                {
                    var next = (i % 128) + 101;
                    sb.Append(next);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite * 3)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
示例#49
0
 private void FormatGuid()
 {
     var guid = Guid.NewGuid();
     var guidsToWrite = numbersToWrite / 10;
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(guidsToWrite * 36, pool);
         for (int i = 0; i < guidsToWrite; i++)
         {
             sb.Append(guid);
         }
         var text = sb.ToString();
         if (text.Length != guidsToWrite * 36)
         {
             throw new Exception("test failed");
         }
     }
     PrintTime();
 }
        public void FormatXPrecision()
        {
            var x = Format.Parse("x10");
            var X = Format.Parse("X10");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("00000000ff00000000FF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("00FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("00FFFFFFFE", sb.ToString());
        }
        public void FormatX()
        {
            var x = Format.Parse("x");
            var X = Format.Parse("X");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("ffFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("FFFFFFFE", sb.ToString());
        }
 public void FormatNPrecision()
 {
     var format = Format.Parse("N1");
     var sb = new StringFormatter(pool);
     sb.Append((sbyte)-10, format);
     sb.Append((byte)99, format);
     sb.Append((short)-10, format);
     sb.Append((ushort)99, format);
     sb.Append((int)-10, format);
     sb.Append((uint)99, format);
     sb.Append((long)-10, format);
     sb.Append((ulong)99, format);
     var result = sb.ToString();
     Assert.Equal("-10.099.0-10.099.0-10.099.0-10.099.0", result);
 }
 public void FormatDefault()
 {
     var sb = new StringFormatter(pool);
     sb.Append('C');
     sb.Append((sbyte)-10);
     sb.Append((byte)99);
     sb.Append((short)-10);
     sb.Append((ushort)99);
     sb.Append((int)-10);
     sb.Append((uint)99);
     sb.Append((long)-10);
     sb.Append((ulong)99);
     var result = sb.ToString();
     Assert.Equal("C-1099-1099-1099-1099", result);
 }
 public void FormatD()
 {
     var format = Format.Parse("D");
     var sb = new StringFormatter();
     sb.Append((sbyte)-10, format);
     sb.Append((byte)99, format);
     sb.Append((short)-10, format);
     sb.Append((ushort)99, format);
     sb.Append((int)-10, format);
     sb.Append((uint)99, format);
     sb.Append((long)-10, format);
     sb.Append((ulong)99, format);
     var result = sb.ToString();
     Assert.Equal("-1099-1099-1099-1099", result);
 }