public void InsertBetweenExistingPositions()
        {
            JSBuilder builder = new JSBuilder();

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

            builder.Text("cd");
            BuilderPosition 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());
        }
        public void CreatePositionWithEmptyBuilder()
        {
            JSBuilder       builder = new JSBuilder();
            BuilderPosition p       = builder.CreatePosition();

            Assert.AreEqual(0, p.CharactersAfterPreviousPosition);
            Assert.AreEqual(0, p.GetIndexInBuilder());
            Assert.AreSame(p, builder.CreatePosition());
        }
        public void CreatePositionWhenAnotherPositionAlreadyExists()
        {
            JSBuilder       builder = new JSBuilder();
            BuilderPosition p1      = builder.CreatePosition();

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

            Assert.AreEqual(0, p1.CharactersAfterPreviousPosition);
            Assert.AreEqual(0, p1.GetIndexInBuilder());
            Assert.AreEqual(4, p2.CharactersAfterPreviousPosition);
            Assert.AreEqual(4, p2.GetIndexInBuilder());
        }
        public void InsertAtAnExistingPosition()
        {
            JSBuilder       builder = new JSBuilder();
            BuilderPosition p       = builder.CreatePosition();

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

            builder.Text("abc");
            BuilderPosition 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());
        }
Exemple #6
0
 protected BuilderPosition CreatePosition()
 {
     return(builder.CreatePosition());
 }