public void FormatGuid()
        {
            var guid = Guid.NewGuid();
            var sb = new StringFormatter(pool);

            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 CustomTypeToString()
 {
     var sb = new StringFormatter(pool);
     sb.Append(new Age(56));
     sb.Append(new Age(14, inMonths: true));
     Assert.Equal(sb.ToString(), "56y14m");
 }
        public void CompositeFormattingFormatStrings()
        {
            var formatter = new StringFormatter();
            formatter.Format("Hello{0:x}{1:X}{2:G}", 10, 255, 3);

            Assert.Equal("HelloaFF3", formatter.ToString());
        }
示例#4
0
        public void CustomCulture()
        {
            var sb = new StringFormatter(pool);
            sb.FormattingData = Culture5;

            sb.Append(-1234567890);
            Assert.Equal("_?BBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJAAAAA", sb.ToString());
        }
示例#5
0
 public void CustomTypeToString()
 {
     ManagedBufferPool<byte> pool = new ManagedBufferPool<byte>(1024);
     var sb = new StringFormatter(pool);
     sb.Append(new Age(56));
     sb.Append(new Age(14, inMonths: true));
     Assert.Equal(sb.ToString(), "56y14m");
 }
        public void CompositeFormattingFormatStrings()
        {
            var pool = new ManagedBufferPool<byte>(1024);
            var formatter = new StringFormatter(pool);
            formatter.Format("Hello{0:x}{1:X}{2:G}", 10, 255, 3);

            Assert.Equal("HelloaFF3", formatter.ToString());
        }
示例#7
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 void CompositeFormattingBasics()
        {
            var time = DateTime.UtcNow;
            var pool = new ManagedBufferPool<byte>(1024);
            var formatter = new StringFormatter(pool);
            formatter.Format("{2} - Error {0}. File {1} not found.", 404, "index.html", time);

            Assert.Equal(time.ToString("G") + " - Error 404. File index.html not found.", formatter.ToString());
        }
        public void FormatDateTimeR()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

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

            sb.Append(time, 'O');
            Assert.Equal(time.ToString("O", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
示例#11
0
 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();
 }
        private void CustomCultureFormat()
        {
            StringFormatter sb = new StringFormatter(numbersToWrite * 3);
            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();
        }
 private void InvariantFormatStruct()
 {
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(numbersToWrite * 2);
         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 FormatGuid()
 {
     var guid = Guid.NewGuid();
     var guidsToWrite = numbersToWrite / 10;
     timer.Restart();
     for (int itteration = 0; itteration < itterationsInvariant; itteration++)
     {
         StringFormatter sb = new StringFormatter(guidsToWrite * 36);
         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 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();
        }