Browse Source

Upgrade DiffLib.

The old version had a bug that caused tests to fail when the last method in a test file was surrounded by #if/#endif.
pull/1030/head
Daniel Grunwald 7 years ago
parent
commit
7f84bcfbb5
  1. 44
      ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs
  2. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

44
ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs

@ -29,44 +29,46 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -29,44 +29,46 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
{
public static bool Compare(string input1, string input2, StringWriter diff, Func<string, string> normalizeLine, string[] definedSymbols = null)
{
var differ = new AlignedDiff<string>(
NormalizeAndSplitCode(input1, definedSymbols ?? new string[0]),
NormalizeAndSplitCode(input2, definedSymbols ?? new string[0]),
new CodeLineEqualityComparer(normalizeLine),
new StringSimilarityComparer(),
new StringAlignmentFilter());
var collection1 = NormalizeAndSplitCode(input1, definedSymbols ?? new string[0]);
var collection2 = NormalizeAndSplitCode(input2, definedSymbols ?? new string[0]);
var diffSections = DiffLib.Diff.CalculateSections(
collection1, collection2, new CodeLineEqualityComparer(normalizeLine)
);
var alignedDiff = Diff.AlignElements(collection1, collection2, diffSections, new StringSimilarityDiffElementAligner());
bool result = true, ignoreChange;
int line1 = 0, line2 = 0;
foreach (var change in differ.Generate()) {
switch (change.Change) {
case ChangeType.Same:
foreach (var change in alignedDiff) {
switch (change.Operation) {
case DiffOperation.Match:
diff.Write("{0,4} {1,4} ", ++line1, ++line2);
diff.Write(" ");
diff.WriteLine(change.Element1);
diff.WriteLine(change.ElementFromCollection1.Value);
break;
case ChangeType.Added:
case DiffOperation.Insert:
diff.Write(" {1,4} ", line1, ++line2);
result &= ignoreChange = ShouldIgnoreChange(change.Element2);
result &= ignoreChange = ShouldIgnoreChange(change.ElementFromCollection2.Value);
diff.Write(ignoreChange ? " " : " + ");
diff.WriteLine(change.Element2);
diff.WriteLine(change.ElementFromCollection2.Value);
break;
case ChangeType.Deleted:
case DiffOperation.Delete:
diff.Write("{0,4} ", ++line1, line2);
result &= ignoreChange = ShouldIgnoreChange(change.Element1);
result &= ignoreChange = ShouldIgnoreChange(change.ElementFromCollection1.Value);
diff.Write(ignoreChange ? " " : " - ");
diff.WriteLine(change.Element1);
diff.WriteLine(change.ElementFromCollection1.Value);
break;
case ChangeType.Changed:
case DiffOperation.Modify:
case DiffOperation.Replace:
diff.Write("{0,4} ", ++line1, line2);
result = false;
diff.Write("(-) ");
diff.WriteLine(change.Element1);
diff.WriteLine(change.ElementFromCollection1.Value);
diff.Write(" {1,4} ", line1, ++line2);
diff.Write("(+) ");
diff.WriteLine(change.Element2);
diff.WriteLine(change.ElementFromCollection2.Value);
break;
}
}
@ -128,7 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -128,7 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
}
}
private static IEnumerable<string> NormalizeAndSplitCode(string input, IEnumerable<string> definedSymbols)
private static IList<string> NormalizeAndSplitCode(string input, IEnumerable<string> definedSymbols)
{
var syntaxTree = CSharpSyntaxTree.ParseText(input, new CSharpParseOptions(preprocessorSymbols: definedSymbols));
var result = new DeleteDisabledTextRewriter().Visit(syntaxTree.GetRoot());

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffLib" Version="1.0.0.55" />
<PackageReference Include="DiffLib" Version="2017.7.26.1241" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.8.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />

Loading…
Cancel
Save