Skip to content

Commit 0545519

Browse files
committed
included some more tests
1 parent ea9942d commit 0545519

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithMeyerDiffTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
package com.github.difflib.patch;
1717

1818
import com.github.difflib.DiffUtils;
19+
import static com.github.difflib.patch.Patch.CONFLICT_PRODUCES_MERGE_CONFLICT;
1920
import java.util.Arrays;
2021
import java.util.List;
22+
import static java.util.stream.Collectors.joining;
2123
import static org.junit.jupiter.api.Assertions.assertEquals;
2224
import static org.junit.jupiter.api.Assertions.fail;
2325
import org.junit.jupiter.api.Test;
@@ -27,6 +29,7 @@
2729
* @author tw
2830
*/
2931
public class PatchWithMeyerDiffTest {
32+
3033
@Test
3134
public void testPatch_Change_withExceptionProcessor() {
3235
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
@@ -48,4 +51,18 @@ public void testPatch_Change_withExceptionProcessor() {
4851
fail(e.getMessage());
4952
}
5053
}
54+
55+
@Test
56+
public void testPatchThreeWayIssue138() throws PatchFailedException {
57+
List<String> base = Arrays.asList("Imagine there's no heaven".split("\\s+"));
58+
List<String> left = Arrays.asList("Imagine there's no HEAVEN".split("\\s+"));
59+
List<String> right = Arrays.asList("IMAGINE there's no heaven".split("\\s+"));
60+
61+
Patch<String> rightPatch = DiffUtils.diff(base, right)
62+
.withConflictOutput(CONFLICT_PRODUCES_MERGE_CONFLICT);
63+
64+
List<String> applied = rightPatch.applyTo(left);
65+
66+
assertEquals("IMAGINE there's no HEAVEN", applied.stream().collect(joining(" ")));
67+
}
5168
}

java-diff-utils/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,28 @@ public void testIssue129SkipDeltaDecompression() {
761761

762762
assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE CHANGE CHANGE EQUAL EQUAL EQUAL");
763763
}
764+
765+
@Test
766+
public void testIssue129SkipWhitespaceChanges() throws IOException {
767+
String original = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_1.txt")).collect(joining("\n"));
768+
String revised = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_2.txt")).collect(joining("\n"));
769+
770+
DiffRowGenerator generator = DiffRowGenerator.create()
771+
.showInlineDiffs(true)
772+
.mergeOriginalRevised(true)
773+
.inlineDiffByWord(true)
774+
.ignoreWhiteSpaces(true)
775+
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
776+
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
777+
.build();
778+
List<DiffRow> rows = generator.generateDiffRows(
779+
Arrays.asList(original.split("\n")),
780+
Arrays.asList(revised.split("\n")));
781+
782+
assertThat(rows).hasSize(13);
783+
784+
rows.stream()
785+
.filter(item -> item.getTag() != DiffRow.Tag.EQUAL)
786+
.forEach(System.out::println);
787+
}
764788
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated
2+
to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or
3+
any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to
4+
dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live.
5+
It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not
6+
consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it,
7+
far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never
8+
forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought
9+
here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that
10+
from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that
11+
we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of
12+
freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and
2+
dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether
3+
that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that
4+
war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives
5+
that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we
6+
can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who
7+
struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long
8+
remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated
9+
here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here
10+
dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause
11+
for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died
12+
in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the
13+
people, for the people, shall not perish from the earth.

0 commit comments

Comments
 (0)