From f3f80cd46379bc38604e54ab40fe1a2913ed5100 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 22 Aug 2026 21:35:09 +0200 Subject: [PATCH] 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 --- ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs b/ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs index cbeb7f79b..6751fa8a5 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/CodeAssert.cs @@ -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(); } } }