示例#1
0
 private static void FailUsingToken(string token)
 {
     ShouldFail(delegate
     {
         var fr = new FastReplacer("/*", "*/");
         fr.Append("/*a*/");
         fr.Contains(token);
     }, "Expected exception was not thrown while using token \"" + token + "\" in function Contains.");
     ShouldFail(delegate
     {
         var fr = new FastReplacer("/*", "*/");
         fr.Append("/*a*/");
         fr.Replace(token, "x");
     }, "Expected exception was not thrown while using token \"" + token + "\" in function Replace.");
     ShouldFail(delegate
     {
         var fr = new FastReplacer("/*", "*/");
         fr.Append("/*a*/");
         fr.InsertBefore(token, "x");
     },
                "Expected exception was not thrown while using token \"" + token + "\" in function InsertBefore.");
     ShouldFail(delegate
     {
         var fr = new FastReplacer("/*", "*/");
         fr.Append("/*a*/");
         fr.InsertAfter(token, "x");
     },
                "Expected exception was not thrown while using token \"" + token + "\" in function InsertAfter.");
 }
示例#2
0
 public void InsertAfter_Simple()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*/");
     fr.InsertAfter("/*a*/", "123");
     Assert.AreEqual("/*a*/123", fr.ToString());
 }
示例#3
0
        public void ReturnValue()
        {
            var fr = new FastReplacer("/*", "*/");
            fr.Append("/*a*/");
            Assert.AreEqual(true, fr.InsertAfter("/*a*/", "1"));
            Assert.AreEqual(true, fr.InsertBefore("/*a*/", "2"));
            Assert.AreEqual(true, fr.Replace("/*a*/", "/*b*/"));
            Assert.AreEqual(false, fr.InsertAfter("/*a*/", "1"));
            Assert.AreEqual(false, fr.InsertBefore("/*a*/", "2"));
            Assert.AreEqual(false, fr.Replace("/*a*/", "/*c*/"));
            Assert.AreEqual("2/*b*/1", fr.ToString());

            Assert.AreEqual(true, fr.Replace("/*b*/", "/*a*/"));
            Assert.AreEqual(false, fr.Replace("/*x*/", "x1"));
            Assert.AreEqual(false, fr.Replace("/*b*/", "x4"));
            Assert.AreEqual(false, fr.Replace("/*c*/", "x5"));
            Assert.AreEqual(true, fr.Replace("/*a*/", "x6"));
            Assert.AreEqual("2x61", fr.ToString());
        }
示例#4
0
 public void InsertAfter_ComplexAndOrder()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*//*b*/");
     fr.InsertAfter("/*b*/", "1");
     fr.InsertAfter("/*a*/", "2");
     fr.InsertAfter("/*b*/", "3");
     fr.InsertAfter("/*a*/", "4");
     Assert.AreEqual("/*a*/24/*b*/13", fr.ToString());
 }
示例#5
0
        public void Combination_TokenReuse()
        {
            var fr = new FastReplacer("/*", "*/");
            fr.Append("/*a*/");
            fr.Replace("/*a*/", "/*a*/");
            Assert.AreEqual("/*a*/", fr.ToString());

            fr.InsertAfter("/*a*/", "/*a*/");
            Assert.AreEqual("/*a*//*a*/", fr.ToString());

            fr.InsertBefore("/*a*/", "/*a*/");
            Assert.AreEqual("/*a*//*a*//*a*//*a*/", fr.ToString());
        }
示例#6
0
 public void Combination_OrderAdvanced()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*/");
     fr.InsertAfter("/*a*/", "1");
     fr.InsertAfter("/*a*/", "2");
     fr.Replace("/*a*/", "/*a*/");
     fr.InsertAfter("/*a*/", "3");
     Assert.AreEqual("/*a*/312", fr.ToString());
 }
示例#7
0
        public void Combination_Order()
        {
            var fr = new FastReplacer("/*", "*/");
            fr.Append("/*a*//*b*/");

            fr.InsertBefore("/*b*/", "1");
            fr.InsertBefore("/*b*/", "2");
            fr.InsertAfter("/*a*/", "3");
            fr.InsertAfter("/*a*/", "4");
            fr.InsertBefore("/*b*/", "5");
            fr.InsertAfter("/*a*/", "6");
            Assert.AreEqual("/*a*/346125/*b*/", fr.ToString());

            fr.Replace("/*a*/", "7");
            fr.Replace("/*b*/", "8");
            Assert.AreEqual("73461258", fr.ToString());
        }
示例#8
0
        public void Combination2()
        {
            var fr = new FastReplacer("/*", "*/");
            fr.Append("/*a*/");
            fr.InsertAfter("/*a*/", "/*c*/");
            fr.Replace("/*a*/", "/*b*/");
            fr.InsertAfter("/*b*/", "/*d*/");

            fr.Replace("/*a*/", "a");
            fr.Replace("/*b*/", "b");
            fr.Replace("/*c*/", "c");
            fr.Replace("/*d*/", "d");
            Assert.AreEqual("bdc", fr.ToString());
        }