Exemple #1
0
        public void TestExpansion_Fill()
        {
            StringMaker sm;

            for (int capacity = 0; capacity < 20; capacity++)
            {
                sm = new StringMaker(capacity);
                sm.Fill('X', 6);
                var actual   = sm.ExtractString();
                var expected = string.Format("{0}", "XXXXXX");
                Assert.Equal(expected, actual);
                sm.Dispose();
            }

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Fill('X', 6);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Fill('X', 6);
            Assert.Equal(string.Empty, sm.ExtractSpan().ToString());
            sm.Dispose();

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Fill('X', 6);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();
        }
Exemple #2
0
        public void TestExpansion_Int64()
        {
            StringMaker sm;
            string      expected;
            string      actual;

            long o = 123456;

            for (int capacity = 0; capacity < 20; capacity++)
            {
#if PUBLIC_STRINGMAKER
                sm = new StringMaker(capacity);
                sm.Append(o);
                actual   = sm.ExtractString();
                expected = string.Format("{0}", o);
                Assert.Equal(expected, actual);
                sm.Dispose();

                sm = new StringMaker(capacity);
                sm.Append(o);
                actual = sm.ExtractSpan().ToString();
                Assert.Equal(expected, actual);
                sm.Dispose();
#endif
                for (int width = -10; width < 10; width++)
                {
                    sm = new StringMaker(capacity);
                    sm.Append(o, "", null, width);
                    actual   = sm.ExtractString();
                    expected = string.Format(string.Format("{{0,{0}}}", width), o);
                    Assert.Equal(expected, actual);
                    sm.Dispose();

                    sm = new StringMaker(capacity);
                    sm.Append(o, "", null, width);
                    actual = sm.ExtractSpan().ToString();
                    Assert.Equal(expected, actual);
                    sm.Dispose();
                }
            }

#if PUBLIC_STRINGMAKER
            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();
#endif

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o, string.Empty, null, 0);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractSpan().ToString());
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();
        }
Exemple #3
0
        public void TestExpansion_Char()
        {
            StringMaker sm;
            string      expected;
            string      actual;

            char o = 'x';

            for (int capacity = 0; capacity < 20; capacity++)
            {
                sm = new StringMaker(capacity);
                sm.Append(o);
                actual   = sm.ExtractString();
                expected = string.Format("{0}", o);
                Assert.Equal(expected, actual);
                sm.Dispose();

                for (int width = -10; width < 10; width++)
                {
                    sm = new StringMaker(capacity);
                    sm.Append(o, width);
                    actual   = sm.ExtractString();
                    expected = string.Format(string.Format("{{0,{0}}}", width), o);
                    Assert.Equal(expected, actual);
                    sm.Dispose();
                }
            }

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o, 0);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractSpan().ToString());
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o, 2);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();

            sm = new StringMaker(Array.Empty <char>(), true);
            sm.Append(o, -2);
            Assert.True(sm.Overflowed);
            Assert.Equal(string.Empty, sm.ExtractString());
            sm.Dispose();
        }