/// <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> /// 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> public override void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase) { // Maximum string we can display without truncating int maxStringLength = MAX_LINE_LENGTH - PrefixLength // Allow for prefix - 2; // 2 quotation marks expected = MsgUtils.ConvertWhitespace(MsgUtils.ClipString(expected, maxStringLength, mismatch)); actual = MsgUtils.ConvertWhitespace(MsgUtils.ClipString(actual, maxStringLength, mismatch)); // The mismatch position may have changed due to clipping or white // space conversion mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, ignoreCase); TextWriter.Write(Pfx_Expected); WriteExpectedValue(expected); if (ignoreCase) { WriteModifier(Resources.IgnoringCase); } TextWriter.WriteLine(); WriteActualLine(actual); //DisplayDifferences(expected, actual); if (mismatch >= 0) { WriteCaretLine(mismatch); } }
/// <summary> /// Displays the string differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> private void DisplayStringDifferences(MessageWriter writer, string expected, string actual) { int mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, CaseInsensitive); if (expected.Length == actual.Length) { writer.WriteMessageLine(Resources.StringsDiffer_1, expected.Length, mismatch); } else { writer.WriteMessageLine(Resources.StringsDiffer_2, expected.Length, actual.Length, mismatch); } writer.DisplayStringDifferences(expected, actual, mismatch, CaseInsensitive); }
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); } }