private void CheckTag(string code, string tag) { if (!_code.Contains(tag)) { throw new FrameworkException($"Generated script does not contain tag \"{tag}\"." + $" Error occurred while inserting code \"{code.Limit(200, "...")}\"."); } }
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()); }
private void CheckTag(string code, string tag) { if (!_code.Contains(tag)) { throw new FrameworkException(string.Format( "Generated script does not contain tag \"{0}\". Error occurred while inserting code \"{1}\".", tag, code.Limit(200))); } }
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()); }
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."); }
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()); }
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 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 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()); }