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();
        }
예제 #2
0
 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");
 }
예제 #3
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");
 }
예제 #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 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 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();
        }
예제 #8
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();
        }
예제 #10
0
 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();
 }
예제 #11
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);
         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();
        }