From e73742c4fcb46308a69e64f91dd871132b39d22e Mon Sep 17 00:00:00 2001 From: Tobias Warneke Date: Sat, 23 Jul 2022 01:29:37 +0200 Subject: [PATCH] --- .github/release.yml | 8 ++++ .../UnifiedDiffRoundTripNewLineTest.java | 46 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/release.yml create mode 100644 java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffRoundTripNewLineTest.java diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..b9134ea --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,8 @@ +changelog: + categories: + - title: Bugs solved + labels: + - "bug" + - title: Changes and new Features + labels: + - "*" \ No newline at end of file diff --git a/java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffRoundTripNewLineTest.java b/java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffRoundTripNewLineTest.java new file mode 100644 index 0000000..725e0e2 --- /dev/null +++ b/java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffRoundTripNewLineTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 java-diff-utils. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.difflib.unifieddiff; + +import com.github.difflib.patch.PatchFailedException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Arrays; +import static java.util.stream.Collectors.joining; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled("for next release") +public class UnifiedDiffRoundTripNewLineTest { + @Test + public void testIssue135MissingNoNewLineInPatched() throws IOException, PatchFailedException { + String beforeContent = "rootProject.name = \"sample-repo\""; + String afterContent = "rootProject.name = \"sample-repo\"\n"; + String 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"; + UnifiedDiff unifiedDiff = UnifiedDiffReader.parseUnifiedDiff(new ByteArrayInputStream(patch.getBytes())); + String unifiedAfterContent = unifiedDiff.getFiles().get(0).getPatch() + .applyTo(Arrays.asList(beforeContent.split("\n"))).stream().collect(joining("\n")); + assertEquals(afterContent, unifiedAfterContent); + } +}