Exemple #1
0
        public void InsertBetweenExistingPositions()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text("ab");
            TSPosition p1 = builder.CreatePosition();

            builder.Text("cd");
            TSPosition p2 = builder.CreatePosition();

            builder.Text("ef");

            Assert.AreEqual(2, p1.CharactersAfterPreviousPosition);
            Assert.AreEqual(2, p1.GetIndexInBuilder());
            Assert.AreEqual(2, p2.CharactersAfterPreviousPosition);
            Assert.AreEqual(4, p2.GetIndexInBuilder());

            builder.Insert(3, "Z");
            Assert.AreEqual("abcZdef", builder.ToString());

            Assert.AreEqual(2, p1.CharactersAfterPreviousPosition);
            Assert.AreEqual(2, p1.GetIndexInBuilder());
            Assert.AreEqual(3, p2.CharactersAfterPreviousPosition);
            Assert.AreEqual(5, p2.GetIndexInBuilder());
        }
Exemple #2
0
        public void CreatePositionWithEmptyBuilder()
        {
            TSBuilder  builder = new TSBuilder();
            TSPosition p       = builder.CreatePosition();

            Assert.AreEqual(0, p.CharactersAfterPreviousPosition);
            Assert.AreEqual(0, p.GetIndexInBuilder());
            Assert.AreSame(p, builder.CreatePosition());
        }
Exemple #3
0
        public void InsertAtAnExistingPosition()
        {
            TSBuilder  builder = new TSBuilder();
            TSPosition p       = builder.CreatePosition();

            builder.Insert(0, "abcd");
            Assert.AreEqual("abcd", builder.ToString());
            Assert.AreEqual(4, p.CharactersAfterPreviousPosition);
            Assert.AreEqual(4, p.GetIndexInBuilder());
        }
        public void CreatePositionWithNonEmptyBuilder()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text("abcd");
            TSPosition p = builder.CreatePosition();

            Assert.Equal(4, p.CharactersAfterPreviousPosition);
            Assert.Equal(4, p.GetIndexInBuilder());
            Assert.Same(p, builder.CreatePosition());
        }
Exemple #5
0
        public void CreatePositionWhenAnotherPositionAlreadyExists()
        {
            TSBuilder  builder = new TSBuilder();
            TSPosition p1      = builder.CreatePosition();

            builder.Text("abcd");
            TSPosition p2 = builder.CreatePosition();

            Assert.AreEqual(0, p1.CharactersAfterPreviousPosition);
            Assert.AreEqual(0, p1.GetIndexInBuilder());
            Assert.AreEqual(4, p2.CharactersAfterPreviousPosition);
            Assert.AreEqual(4, p2.GetIndexInBuilder());
        }
Exemple #6
0
        public void InsertAfterAnExistingPosition()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text("abc");
            TSPosition p = builder.CreatePosition();

            builder.Text("df");

            Assert.AreEqual(3, p.CharactersAfterPreviousPosition);
            Assert.AreEqual(3, p.GetIndexInBuilder());

            builder.Insert(4, "e");

            Assert.AreEqual(3, p.CharactersAfterPreviousPosition);
            Assert.AreEqual(3, p.GetIndexInBuilder());
        }
        public void InsertBeforeAnExistingPosition()
        {
            TSBuilder builder = new TSBuilder();

            builder.Text("abd");
            TSPosition p = builder.CreatePosition();

            builder.Text("ef");

            Assert.Equal(3, p.CharactersAfterPreviousPosition);
            Assert.Equal(3, p.GetIndexInBuilder());

            builder.Insert(2, "c");

            Assert.Equal(4, p.CharactersAfterPreviousPosition);
            Assert.Equal(4, p.GetIndexInBuilder());
        }
Exemple #8
0
        /// <summary>
        /// Create a position object that will track a certain position within the TSBuilder's content.
        /// </summary>
        /// <returns></returns>
        public TSPosition CreatePosition()
        {
            TSPosition position;
            int        contentLength = contents.Length;

            if (!positions.Any())
            {
                position = new TSPosition(null, contentLength);
                positions.Add(position);
            }
            else
            {
                position = positions.Last();
                int lastPositionIndexInBuilder = position.GetIndexInBuilder();
                if (lastPositionIndexInBuilder != contentLength)
                {
                    position = new TSPosition(position, contentLength - lastPositionIndexInBuilder);
                    positions.Add(position);
                }
            }
            return(position);
        }