|
| 1 | +/* |
| 2 | + * Copyright 2022 java-diff-utils. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.github.difflib.unifieddiff; |
| 17 | + |
| 18 | +import com.github.difflib.patch.PatchFailedException; |
| 19 | +import java.io.ByteArrayInputStream; |
| 20 | +import java.io.IOException; |
| 21 | +import java.util.Arrays; |
| 22 | +import static java.util.stream.Collectors.joining; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 24 | +import org.junit.jupiter.api.Disabled; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +@Disabled("for next release") |
| 28 | +public class UnifiedDiffRoundTripNewLineTest { |
| 29 | + @Test |
| 30 | + public void testIssue135MissingNoNewLineInPatched() throws IOException, PatchFailedException { |
| 31 | + String beforeContent = "rootProject.name = \"sample-repo\""; |
| 32 | + String afterContent = "rootProject.name = \"sample-repo\"\n"; |
| 33 | + String patch = "diff --git a/settings.gradle b/settings.gradle\n" + |
| 34 | + "index ef3b8e2..ab30124 100644\n" + |
| 35 | + "--- a/settings.gradle\n" + |
| 36 | + "+++ b/settings.gradle\n" + |
| 37 | + "@@ -1 +1 @@\n" + |
| 38 | + "-rootProject.name = \"sample-repo\"\n" + |
| 39 | + "\\ No newline at end of file\n" + |
| 40 | + "+rootProject.name = \"sample-repo\"\n"; |
| 41 | + UnifiedDiff unifiedDiff = UnifiedDiffReader.parseUnifiedDiff(new ByteArrayInputStream(patch.getBytes())); |
| 42 | + String unifiedAfterContent = unifiedDiff.getFiles().get(0).getPatch() |
| 43 | + .applyTo(Arrays.asList(beforeContent.split("\n"))).stream().collect(joining("\n")); |
| 44 | + assertEquals(afterContent, unifiedAfterContent); |
| 45 | + } |
| 46 | +} |
0 commit comments