Exemple #1
0
        public virtual void TestGrow()
        {
            Token         t   = new Token();
            StringBuilder buf = new StringBuilder("ab");

            for (int i = 0; i < 20; i++)
            {
                char[] content = buf.ToString().ToCharArray();
                t.CopyBuffer(content, 0, content.Length);
                Assert.AreEqual(buf.Length, t.Length);
                Assert.AreEqual(buf.ToString(), t.ToString());
                buf.Append(buf.ToString());
            }
            Assert.AreEqual(1048576, t.Length);

            // now as a string, second variant
            t   = new Token();
            buf = new StringBuilder("ab");
            for (int i = 0; i < 20; i++)
            {
                t.SetEmpty().Append(buf);
                string content = buf.ToString();
                Assert.AreEqual(content.Length, t.Length);
                Assert.AreEqual(content, t.ToString());
                buf.Append(content);
            }
            Assert.AreEqual(1048576, t.Length);

            // Test for slow growth to a long term
            t   = new Token();
            buf = new StringBuilder("a");
            for (int i = 0; i < 20000; i++)
            {
                t.SetEmpty().Append(buf);
                string content = buf.ToString();
                Assert.AreEqual(content.Length, t.Length);
                Assert.AreEqual(content, t.ToString());
                buf.Append("a");
            }
            Assert.AreEqual(20000, t.Length);

            // Test for slow growth to a long term
            t   = new Token();
            buf = new StringBuilder("a");
            for (int i = 0; i < 20000; i++)
            {
                t.SetEmpty().Append(buf);
                string content = buf.ToString();
                Assert.AreEqual(content.Length, t.Length);
                Assert.AreEqual(content, t.ToString());
                buf.Append("a");
            }
            Assert.AreEqual(20000, t.Length);
        }
Exemple #2
0
        public virtual void TestToString()
        {
            char[] b = new char[] { 'a', 'l', 'o', 'h', 'a' };
            Token  t = new Token("", 0, 5);

            t.CopyBuffer(b, 0, 5);
            Assert.AreEqual("aloha", t.ToString());

            t.SetEmpty().Append("hi there");
            Assert.AreEqual("hi there", t.ToString());
        }
Exemple #3
0
        public virtual void TestMixedStringArray()
        {
            Token t = new Token("hello", 0, 5);

            Assert.AreEqual(t.Length, 5);
            Assert.AreEqual(t.ToString(), "hello");
            t.SetEmpty().Append("hello2");
            Assert.AreEqual(t.Length, 6);
            Assert.AreEqual(t.ToString(), "hello2");
            t.CopyBuffer("hello3".ToCharArray(), 0, 6);
            Assert.AreEqual(t.ToString(), "hello3");

            char[] buffer = t.Buffer();
            buffer[1] = 'o';
            Assert.AreEqual(t.ToString(), "hollo3");
        }