java-diff-utils icon indicating copy to clipboard operation
java-diff-utils copied to clipboard

Adding a new line at the end of a file is ignored

Open michaelprichardson opened this issue 4 years ago • 1 comments

Describe the bug When adding a new line to a file it is ignored

To Reproduce Steps to reproduce the behavior:

  1. Using the following test (kotlin)
val beforeContent = "rootProject.name = \"sample-repo\""
val afterContent = "rootProject.name = \"sample-repo\"\n"
val patch = "diff --git a/settings.gradle b/settings.gradle\n" +
        "index ef3b8e2..ab30124 100644\n" +
        "--- a/settings.gradle\n" +
        "+++ b/settings.gradle\n" +
        "@@ -1 +1 @@\n" +
        "-rootProject.name = \"sample-repo\"\n" +
        "\\ No newline at end of file\n" +
        "+rootProject.name = \"sample-repo\"\n"

val unifiedDiff = UnifiedDiffReader.parseUnifiedDiff(patch.byteInputStream())
val unifiedAfterContent = unifiedDiff.files[0].patch.applyTo(beforeContent.split("\n")).joinToString("\n")
assertEquals(afterContent, unifiedAfterContent)

Expected behavior The test should have equal content after applying the patch

michaelprichardson avatar Dec 02 '21 22:12 michaelprichardson

You are right. I investigated so much time implementing this \ No newline at ... and forgot to use it for the patch itself. :)

wumpz avatar Dec 12 '21 22:12 wumpz

Stale issue message

github-actions[bot] avatar Jan 05 '23 02:01 github-actions[bot]