Skip to content

Commit

Permalink
Update to DiffPlex 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 29, 2021
1 parent 44af285 commit f52d6dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<BasicReferenceAssembliesNetStandard13Version>1.2.4</BasicReferenceAssembliesNetStandard13Version>
<BenchmarkDotNetVersion>0.13.0</BenchmarkDotNetVersion>
<BenchmarkDotNetDiagnosticsWindowsVersion>0.13.0</BenchmarkDotNetDiagnosticsWindowsVersion>
<DiffPlexVersion>1.4.4</DiffPlexVersion>
<DiffPlexVersion>1.5.0</DiffPlexVersion>
<FakeSignVersion>0.9.2</FakeSignVersion>
<HumanizerCoreVersion>2.2.0</HumanizerCoreVersion>
<ICSharpCodeDecompilerVersion>6.1.0.5902</ICSharpCodeDecompilerVersion>
Expand Down
22 changes: 16 additions & 6 deletions src/Compilers/Test/Core/Assert/AssertEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using DiffPlex;
using DiffPlex.Chunkers;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand All @@ -28,6 +29,10 @@ namespace Roslyn.Test.Utilities
/// </summary>
public static class AssertEx
{
private static readonly IChunker s_lineChunker = new LineChunker();
private static readonly IChunker s_lineEndingsPreservingChunker = new LineEndingsPreservingChunker();
private static readonly InlineDiffBuilder s_diffBuilder = new InlineDiffBuilder(new Differ());

#region AssertEqualityComparer<T>

private class AssertEqualityComparer<T> : IEqualityComparer<T>
Expand Down Expand Up @@ -242,30 +247,35 @@ public static void EqualOrDiff(string expected, string actual, string message =
return;
}

var diffBuilder = new InlineDiffBuilder(new Differ());
var diff = diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false);
var diff = s_diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, s_lineChunker);
var messageBuilder = new StringBuilder();
messageBuilder.AppendLine(
string.IsNullOrEmpty(message)
? "Actual and expected values differ. Expected shown in baseline of diff:"
: message);

if (!diff.Lines.Any(line => line.Type == ChangeType.Inserted || line.Type == ChangeType.Deleted))
{
// We have a failure only caused by line ending differences; recalculate with line endings visible
diff = s_diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, s_lineEndingsPreservingChunker);
}

foreach (var line in diff.Lines)
{
switch (line.Type)
{
case ChangeType.Inserted:
messageBuilder.Append("+");
messageBuilder.Append('+');
break;
case ChangeType.Deleted:
messageBuilder.Append("-");
messageBuilder.Append('-');
break;
default:
messageBuilder.Append(" ");
messageBuilder.Append(' ');
break;
}

messageBuilder.AppendLine(line.Text);
messageBuilder.AppendLine(line.Text.Replace("\r", "<CR>").Replace("\n", "<LF>"));
}

Assert.True(false, messageBuilder.ToString());
Expand Down

0 comments on commit f52d6dc

Please sign in to comment.