/// <summary> /// Display the expected and actual string _values on separate lines. /// If the mismatch parameter is >=0, an additional line is displayed /// line containing a caret that points to the mismatch point. /// </summary> /// <param name="expected">The expected string value</param> /// <param name="actual">The actual string value</param> /// <param name="mismatch">The point at which the strings don't match or -1</param> /// <param name="ignoreCase">If true, case is ignored in string comparisons</param> /// <param name="clipping">If true, clip the strings to fit the max line length</param> public override void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping) { // Maximum string we can display without truncating int maxDisplayLength = MaxLineLength - PrefixLength // Allow for prefix - 2; // 2 quotation marks if (clipping) { MsgUtils.ClipExpectedAndActual(ref expected, ref actual, maxDisplayLength, mismatch); } expected = MsgUtils.EscapeControlChars(expected); actual = MsgUtils.EscapeControlChars(actual); // The mismatch position may have changed due to clipping or white space conversion mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, ignoreCase); Write(Pfx_Expected); Write(MsgUtils.FormatValue(expected)); if (ignoreCase) { Write(", ignoring case"); } WriteLine(); WriteActualLine(actual); //DisplayDifferences(expected, actual); if (mismatch >= 0) { WriteCaretLine(mismatch); } }
/// <summary> /// Method to write single line message with optional args, usually /// written to precede the general failure message, at a given /// indentation level. /// </summary> /// <param name="level">The indentation level of the message</param> /// <param name="message">The message to be written</param> /// <param name="args">Any arguments used in formatting the message</param> public override void WriteMessageLine(int level, string message, params object[] args) { if (message != null) { while (level-- >= 0) { Write(" "); } if (args != null && args.Length > 0) { message = string.Format(message, args); } WriteLine(MsgUtils.EscapeControlChars(message)); } }
public override void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping) { int maxDisplayLength = MaxLineLength - PrefixLength - 2; if (clipping) { MsgUtils.ClipExpectedAndActual(ref expected, ref actual, maxDisplayLength, mismatch); } expected = MsgUtils.EscapeControlChars(expected); actual = MsgUtils.EscapeControlChars(actual); mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, ignoreCase); Write(Pfx_Expected); WriteExpectedValue(expected); if (ignoreCase) { WriteModifier("ignoring case"); } WriteLine(); WriteActualLine(actual); if (mismatch >= 0) { WriteCaretLine(mismatch); } }
public void EscapeNullCharInString() { Assert.That(MsgUtils.EscapeControlChars("\0"), Is.EqualTo("\\0")); }
public void EscapeControlCharsTest(string input, string expected) { Assert.AreEqual(expected, MsgUtils.EscapeControlChars(input)); }
public void EscapeControlCharsTest(string input, string expected) { Assert.That(MsgUtils.EscapeControlChars(input), Is.EqualTo(expected)); }