diff --git a/src/DiffEngineViewer.Tests/FileScreenTests.WhitespaceOnly.verified.txt b/src/DiffEngineViewer.Tests/FileScreenTests.WhitespaceOnly.verified.txt new file mode 100644 index 00000000..0f4ad098 --- /dev/null +++ b/src/DiffEngineViewer.Tests/FileScreenTests.WhitespaceOnly.verified.txt @@ -0,0 +1,24 @@ ++----------------------------------------------------------------------------------------------+ +| Sample.received.txt <> Sample.verified.txt diff | ++----------------------------------------------+-----------------------------------------------+ +| Sample.received.txt | Sample.verified.txt | ++----------------------------------------------+-----------------------------------------------+ +| 1 the quick | 1 the quick | +| ~ 2 brown fox | ~ 2 brown fox | +| ~ 3 dog | ~ 3 dog | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | +| | | ++----------------------------------------------+-----------------------------------------------+ +| [Accept] [Close] lines 1-3 of 3 | ++----------------------------------------------------------------------------------------------+ \ No newline at end of file diff --git a/src/DiffEngineViewer.Tests/FileScreenTests.cs b/src/DiffEngineViewer.Tests/FileScreenTests.cs index 05b6122a..ce53bbef 100644 --- a/src/DiffEngineViewer.Tests/FileScreenTests.cs +++ b/src/DiffEngineViewer.Tests/FileScreenTests.cs @@ -16,6 +16,18 @@ public Task LeftEmpty() => public Task RightEmpty() => Verify(Fixtures.Render(Fixtures.File(right: ""))); + /// + /// A snapshot that differs only in whitespace still has to render as a difference. DiffPlex + /// ignores whitespace by default, which turned this into three Unchanged rows. + /// + [Test] + public Task WhitespaceOnly() => + Verify( + Fixtures.Render( + Fixtures.File( + "the quick\n brown fox\ndog ", + "the quick\nbrown fox\ndog"))); + [Test] public Task LongLines() { diff --git a/src/DiffEngineViewer/DiffRows.cs b/src/DiffEngineViewer/DiffRows.cs index 635f13aa..708ae671 100644 --- a/src/DiffEngineViewer/DiffRows.cs +++ b/src/DiffEngineViewer/DiffRows.cs @@ -10,7 +10,15 @@ static class DiffRows public static (IReadOnlyList Left, IReadOnlyList Right) Build(string leftText, string rightText) { // DiffPlex is old/new oriented. Left is the received (new) side, right the expected (old). - var model = SideBySideDiffBuilder.Diff(rightText, leftText); + // ignoreWhiteSpace defaults to true, which is wrong for a snapshot: a test that fails only + // on indentation or a trailing space came back Unchanged on every row, so the panes drew no + // markers, NextChange found nothing, and the reviewer was shown a failure with no visible + // difference. Whitespace is exactly what the F# layout convention is about. + var model = SideBySideDiffBuilder.Diff( + rightText, + leftText, + ignoreWhiteSpace: false, + ignoreCase: false); return (Convert(model.NewText.Lines), Convert(model.OldText.Lines)); }