Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to DiffPlex 1.5.0 #58016

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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