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());
        }
        public void Combination1()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("1");
            fr.Append("2/*a*/3");
            fr.Append("4");
            Assert.AreEqual("12/*a*/34", fr.ToString());

            fr.InsertBefore("/*a*/", "x/*a*/x");
            Assert.AreEqual("12x/*a*/x/*a*/34", fr.ToString());

            fr.InsertBefore("/*a*/", "-");
            Assert.AreEqual("12x-/*a*/x-/*a*/34", fr.ToString());
        }
 public void Append_Simple_OtherLanguages()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("abc");
     fr.Append(@" čćšđž;'[]\");
     Assert.AreEqual(@"abc čćšđž;'[]\", fr.ToString());
 }
 public void Append_Simple()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("a");
     fr.Append("b");
     fr.Append("c");
     Assert.AreEqual("abc", fr.ToString());
 }
        public void Append_Simple_OtherLanguages()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("abc");
            fr.Append(@" čćšđž;'[]\");
            Assert.AreEqual(@"abc čćšđž;'[]\", fr.ToString());
        }
        public void PossiblyUnintuitiveBehaviour_IgnoreTokenIfNotFromSingleText()
        {
            // Behavior is different from standard String.Replace function:
            // Token is ignored if it is composed by concatenation of two different strings.
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*//*b*/");
            fr.Replace("/*a*/", "/");
            fr.Replace("/*b*/", "*c*/");

            Assert.AreEqual("/*c*/", fr.ToString());
            Assert.IsFalse(fr.Contains("/*c*/"));
            bool replaced = fr.Replace("/*c*/", "-");

            Assert.IsFalse(replaced);
            Assert.AreEqual("/*c*/", fr.ToString());
        }
        public void Replace_Simple()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*/");
            fr.Replace("/*a*/", "123");
            Assert.AreEqual("123", fr.ToString());
        }
 public void CaseInsensitive_OtherLanguages()
 {
     var fr = new FastReplacer("{", "}", false);
     fr.Append("{č}");
     Assert.IsTrue(fr.Contains("{č}"));
     Assert.IsTrue(fr.Contains("{Č}"));
     Assert.IsTrue(fr.Replace("{Č}", "x"));
     Assert.AreEqual("x", fr.ToString());
 }
        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());
        }
        public void Append_Simple()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("a");
            fr.Append("b");
            fr.Append("c");
            Assert.AreEqual("abc", fr.ToString());
        }
        public void Replace_RemoveWhenReplaced()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*/");
            Assert.AreEqual(true, fr.Replace("/*a*/", "123"));
            Assert.AreEqual(false, fr.Replace("/*a*/", "456"));
            Assert.AreEqual("123", fr.ToString());
        }
        public void CaseSensitive()
        {
            var fr = new FastReplacer("{", "}");

            fr.Append("{a}");
            Assert.IsTrue(fr.Contains("{a}"));
            Assert.IsFalse(fr.Contains("{A}"));
            Assert.IsFalse(fr.Replace("{A}", "x"));
            Assert.AreEqual("{a}", fr.ToString());
        }
        public void CaseInsensitive_OtherLanguages()
        {
            var fr = new FastReplacer("{", "}", false);

            fr.Append("{č}");
            Assert.IsTrue(fr.Contains("{č}"));
            Assert.IsTrue(fr.Contains("{Č}"));
            Assert.IsTrue(fr.Replace("{Č}", "x"));
            Assert.AreEqual("x", fr.ToString());
        }
        public void InsertBefore_ComplexAndOrder()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*//*b*/");
            fr.InsertBefore("/*b*/", "1");
            fr.InsertBefore("/*a*/", "2");
            fr.InsertBefore("/*b*/", "3");
            fr.InsertBefore("/*a*/", "4");
            Assert.AreEqual("24/*a*/13/*b*/", fr.ToString());
        }
        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());
        }
        public void InsertAfterReverse_ComplexAndOrder()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*//*b*/");
            fr.InsertAfter("/*b*/", "1");
            fr.InsertAfter("/*a*/", "2", true);
            fr.InsertAfter("/*b*/", "3");
            fr.InsertAfter("/*a*/", "4", true);
            Assert.AreEqual("/*a*/42/*b*/13", fr.ToString());
        }
        public void InsertAfterReverse_Simple()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append("/*a*/");
            fr.InsertAfter("/*a*/", "1");
            fr.InsertAfter("/*a*/", "2");
            fr.InsertAfter("/*a*/", "3", reverse: true);
            fr.InsertAfter("/*a*/", "4", reverse: true);
            Assert.AreEqual("/*a*/4312", fr.ToString());
        }
        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());
        }
        private static string DoReplacingWithFastReplacer(string initial, int replaceCount)
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append(initial);
            for (int i = 1; i <= replaceCount; i++)
            {
                string token   = "/*" + i + "*/";
                string newText = "(/*" + (2 * i) + "*//*" + (2 * i + 1) + "*/)";
                fr.Replace(token, newText);
            }
            return(fr.ToString());
        }
        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());
        }
Exemple #21
0
 /// <summary>
 /// Replace the variables &lt;XXX&gt; in the string
 /// </summary>
 private string ReplaceVariablesIn(string input)
 {
     if (input.ContainsFast("<"))
     {
         var fr = new FastReplacer("<", ">", false);
         fr.Append(input.Replace("<<", $"{(char) 2}").Replace(">>", $"{(char) 3}"));
         // special replacement
         fr.Replace(@"<ROOT>", input.StartsWith(":") ? Regex.Escape(_sourceDirectory) : _sourceDirectory);
         foreach (var variableRule in DeployVarList)
         {
             fr.Replace(variableRule.VariableName, variableRule.Path);
         }
         return(fr.ToString().Replace($"{(char) 2}", "<").Replace($"{(char) 3}", ">"));
     }
     return(input);
 }
        public void Contains_Test()
        {
            string a  = "/*a*/";
            string b  = "/*b*/";
            string c  = "/*c*/";
            var    fr = new FastReplacer("/*", "*/");

            Assert.AreEqual(false, fr.Contains(a));
            fr.Append(a);
            Assert.AreEqual(true, fr.Contains(a));
            fr.Replace(a, b);
            Assert.AreEqual(false, fr.Contains(a));
            Assert.AreEqual(true, fr.Contains(b));
            fr.Replace(b, b);
            Assert.AreEqual(true, fr.Contains(b));
            fr.Replace(b, c);
            Assert.AreEqual(false, fr.Contains(b));
            Assert.AreEqual(c, fr.ToString());
        }
        public void IgnoreTokenMarksInMultilineText()
        {
            var fr = new FastReplacer("/*", "*/");

            fr.Append(@"
/*a
*/
/*
/*b*/
*/");
            Assert.IsTrue(fr.Contains("/*b*/"));
            Assert.IsFalse(fr.Contains("/*a*/"));
            fr.Replace("/*b*/", "123");
            Assert.AreEqual(@"
/*a
*/
/*
123
*/", fr.ToString());
        }
Exemple #24
0
 public void Contains_Test()
 {
     string a = "/*a*/";
     string b = "/*b*/";
     string c = "/*c*/";
     var fr = new FastReplacer("/*", "*/");
     Assert.AreEqual(false, fr.Contains(a));
     fr.Append(a);
     Assert.AreEqual(true, fr.Contains(a));
     fr.Replace(a, b);
     Assert.AreEqual(false, fr.Contains(a));
     Assert.AreEqual(true, fr.Contains(b));
     fr.Replace(b, b);
     Assert.AreEqual(true, fr.Contains(b));
     fr.Replace(b, c);
     Assert.AreEqual(false, fr.Contains(b));
     Assert.AreEqual(c, fr.ToString());
 }
Exemple #25
0
 public void IgnoreTokenMarksInMultilineText()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append(@"
     /*a
     */
     /*
     /*b*/
     */");
     Assert.IsTrue(fr.Contains("/*b*/"));
     Assert.IsFalse(fr.Contains("/*a*/"));
     fr.Replace("/*b*/", "123");
     Assert.AreEqual(@"
     /*a
     */
     /*
     123
     */", fr.ToString());
 }
Exemple #26
0
 public void InsertBefore_ComplexAndOrder()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*//*b*/");
     fr.InsertBefore("/*b*/", "1");
     fr.InsertBefore("/*a*/", "2");
     fr.InsertBefore("/*b*/", "3");
     fr.InsertBefore("/*a*/", "4");
     Assert.AreEqual("24/*a*/13/*b*/", fr.ToString());
 }
Exemple #27
0
        public void PossiblyUnintuitiveBehaviour_IgnoreTokenIfNotFromSingleText()
        {
            // Behaviour is different from standard String.Replace function:
            // Token is ignored if it is composed by concatenation of two different strings.
            var fr = new FastReplacer("/*", "*/");
            fr.Append("/*a*//*b*/");
            fr.Replace("/*a*/", "/");
            fr.Replace("/*b*/", "*c*/");

            Assert.AreEqual("/*c*/", fr.ToString());
            Assert.IsFalse(fr.Contains("/*c*/"));
            bool replaced = fr.Replace("/*c*/", "-");
            Assert.IsFalse(replaced);
            Assert.AreEqual("/*c*/", fr.ToString());
        }
Exemple #28
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());
        }
Exemple #29
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());
        }
Exemple #30
0
 private static string DoReplacingWithFastReplacer(string initial, int replaceCount)
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append(initial);
     for (int i = 1; i <= replaceCount; i++)
     {
         string token = "/*" + i + "*/";
         string newText = "(/*" + (2 * i) + "*//*" + (2 * i + 1) + "*/)";
         fr.Replace(token, newText);
     }
     return fr.ToString();
 }
Exemple #31
0
 public void CaseSensitive()
 {
     var fr = new FastReplacer("{", "}");
     fr.Append("{a}");
     Assert.IsTrue(fr.Contains("{a}"));
     Assert.IsFalse(fr.Contains("{A}"));
     Assert.IsFalse(fr.Replace("{A}", "x"));
     Assert.AreEqual("{a}", fr.ToString());
 }
 public string GenerateCode() => _code.ToString();
Exemple #33
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());
        }
Exemple #34
0
 public void Replace_Simple()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*/");
     fr.Replace("/*a*/", "123");
     Assert.AreEqual("123", fr.ToString());
 }
Exemple #35
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());
 }
Exemple #36
0
 public void Replace_RemoveWhenReplaced()
 {
     var fr = new FastReplacer("/*", "*/");
     fr.Append("/*a*/");
     Assert.AreEqual(true, fr.Replace("/*a*/", "123"));
     Assert.AreEqual(false, fr.Replace("/*a*/", "456"));
     Assert.AreEqual("123", fr.ToString());
 }
Exemple #37
0
        public void Combination1()
        {
            var fr = new FastReplacer("/*", "*/");
            fr.Append("1");
            fr.Append("2/*a*/3");
            fr.Append("4");
            Assert.AreEqual("12/*a*/34", fr.ToString());

            fr.InsertBefore("/*a*/", "x/*a*/x");
            Assert.AreEqual("12x/*a*/x/*a*/34", fr.ToString());

            fr.InsertBefore("/*a*/", "-");
            Assert.AreEqual("12x-/*a*/x-/*a*/34", fr.ToString());
        }
Exemple #38
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());
        }