|
| 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 | +packagecom.github.difflib.unifieddiff; |
| 17 | + |
| 18 | +importcom.github.difflib.patch.PatchFailedException; |
| 19 | +importjava.io.ByteArrayInputStream; |
| 20 | +importjava.io.IOException; |
| 21 | +importjava.util.Arrays; |
| 22 | +importstaticjava.util.stream.Collectors.joining; |
| 23 | +importstaticorg.junit.jupiter.api.Assertions.assertEquals; |
| 24 | +importorg.junit.jupiter.api.Disabled; |
| 25 | +importorg.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +@Disabled("for next release") |
| 28 | +publicclassUnifiedDiffRoundTripNewLineTest { |
| 29 | +@Test |
| 30 | +publicvoidtestIssue135MissingNoNewLineInPatched()throwsIOException,PatchFailedException { |
| 31 | +StringbeforeContent ="rootProject.name =\"sample-repo\""; |
| 32 | +StringafterContent ="rootProject.name =\"sample-repo\"\n"; |
| 33 | +Stringpatch ="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 | +UnifiedDiffunifiedDiff =UnifiedDiffReader.parseUnifiedDiff(newByteArrayInputStream(patch.getBytes())); |
| 42 | +StringunifiedAfterContent =unifiedDiff.getFiles().get(0).getPatch() |
| 43 | + .applyTo(Arrays.asList(beforeContent.split("\n"))).stream().collect(joining("\n")); |
| 44 | +assertEquals(afterContent,unifiedAfterContent); |
| 45 | + } |
| 46 | +} |