Browse Source

Ignore blank, comment and directive lines when aligning code diffs

The pretty-print comparison already treats blank lines, comment-only lines
and preprocessor directives as ignorable, but only when scoring a single
diff entry: they still sat in the line collections handed to the aligner. A
run of #if/#else/#endif around a statement could then push the aligner into
matching an adjacent brace as inserted-and-deleted, failing a test whose
decompiled output was in fact correct. Drop those lines before diffing so
they cannot skew the alignment.

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/4014/head
Siegfried Pammer 4 weeks ago
parent
commit
f3f80cd463
  1. 8
      ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs

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

@ -210,7 +210,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -210,7 +210,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
var syntaxTree = CSharpSyntaxTree.ParseText(input, new CSharpParseOptions(preprocessorSymbols: definedSymbols));
var result = new DeleteDisabledTextRewriter().Visit(syntaxTree.GetRoot());
input = result.ToFullString();
return input.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
// Drop lines that are ignored anyway (blank, comment-only, preprocessor directives)
// so they cannot sit between real lines and skew the diff alignment - a run of #if/
// #else/#endif around a statement could otherwise make the aligner report an adjacent
// brace as inserted-and-deleted.
return input.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries)
.Where(line => !ShouldIgnoreChange(line))
.ToList();
}
}
}

Loading…
Cancel
Save