public void Simplify(string leftDocument, string rightDocument, int expectedNumberOfDiffs) { DiffSet originalDiffSet = DiffSet.GetDiffSet(leftDocument, rightDocument); DiffSet simplifiedDiffSet = originalDiffSet.Simplify(); using (TestLog.BeginSection("Original DiffSet")) originalDiffSet.WriteTo(TestLog.Default); using (TestLog.BeginSection("Simplified DiffSet")) simplifiedDiffSet.WriteTo(TestLog.Default); VerifyDiffSetIsValid(simplifiedDiffSet); Assert.LessThanOrEqualTo(simplifiedDiffSet.Diffs.Count, originalDiffSet.Diffs.Count); Assert.AreEqual(expectedNumberOfDiffs, simplifiedDiffSet.Diffs.Count); }
/// <summary> /// Adds two raw labeled values formatted using <see cref="Formatter" /> and includes /// formatting of their differences. /// </summary> /// <remarks> /// <para> /// The order in which this method is called determines the order in which the /// values will appear relative to other labeled values. /// </para> /// </remarks> /// <param name="leftLabel">The left label.</param> /// <param name="leftValue">The left value.</param> /// <param name="rightLabel">The right label.</param> /// <param name="rightValue">The right value.</param> /// <returns>The builder, to allow for fluent method chaining.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="leftLabel"/> or /// <paramref name="rightLabel"/> is null.</exception> public AssertionFailureBuilder AddRawLabeledValuesWithDiffs( string leftLabel, object leftValue, string rightLabel, object rightValue) { if (leftLabel == null) { throw new ArgumentNullException("leftLabel"); } if (rightLabel == null) { throw new ArgumentNullException("rightLabel"); } if (ReferenceEquals(leftValue, rightValue)) { AddRawLabeledValue(String.Format("{0} & {1}", leftLabel, rightLabel), leftValue); AddLabeledValue("Remark", "Both values are the same instance."); } else { string formattedLeftValue = Formatter.Format(leftValue); string formattedRightValue = Formatter.Format(rightValue); if (formattedLeftValue == formattedRightValue) { AddLabeledValue(String.Format("{0} & {1}", leftLabel, rightLabel), formattedLeftValue); AddLabeledValue("Remark", "Both values look the same when formatted but they are distinct instances."); } else { DiffSet diffSet = DiffSet.GetDiffSet(formattedLeftValue, formattedRightValue); diffSet = diffSet.Simplify(); var highlightedLeftValueWriter = new StructuredTextWriter(); var highlightedRightValueWriter = new StructuredTextWriter(); diffSet.WriteTo(highlightedLeftValueWriter, DiffStyle.LeftOnly, formattedLeftValue.Length <= AssertionFailure.MaxFormattedValueLength ? int.MaxValue : CompressedDiffContextLength); diffSet.WriteTo(highlightedRightValueWriter, DiffStyle.RightOnly, formattedRightValue.Length <= AssertionFailure.MaxFormattedValueLength ? int.MaxValue : CompressedDiffContextLength); AddLabeledValue(leftLabel, highlightedLeftValueWriter.ToStructuredText()); AddLabeledValue(rightLabel, highlightedRightValueWriter.ToStructuredText()); } } return(this); }
internal static void Check(string a, string b) { TestLog.WriteLine("A: " + a); TestLog.WriteLine("B: " + b); // Standard diff. DiffSet diffSet = DiffSet.GetDiffSet(a, b); TestLog.Write("Diff: "); TestLog.WriteLine(diffSet); VerifyDiffSetIsValid(diffSet); // Also check simplified form. DiffSet simplifiedDiffSet = diffSet.Simplify(); TestLog.Write("Simplified Diff: "); TestLog.WriteLine(simplifiedDiffSet); VerifyDiffSetIsValid(simplifiedDiffSet); Assert.LessThanOrEqualTo(simplifiedDiffSet.Diffs.Count, diffSet.Diffs.Count); }