Skip to content

Commit

Permalink
included some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed May 14, 2022
1 parent ea9942d commit 0545519
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package com.github.difflib.patch;

import com.github.difflib.DiffUtils;
import static com.github.difflib.patch.Patch.CONFLICT_PRODUCES_MERGE_CONFLICT;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
Expand All @@ -27,6 +29,7 @@
* @author tw
*/
public class PatchWithMeyerDiffTest {

@Test
public void testPatch_Change_withExceptionProcessor() {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
Expand All @@ -48,4 +51,18 @@ public void testPatch_Change_withExceptionProcessor() {
fail(e.getMessage());
}
}

@Test
public void testPatchThreeWayIssue138() throws PatchFailedException {
List<String> base = Arrays.asList("Imagine there's no heaven".split("\\s+"));
List<String> left = Arrays.asList("Imagine there's no HEAVEN".split("\\s+"));
List<String> right = Arrays.asList("IMAGINE there's no heaven".split("\\s+"));

Patch<String> rightPatch = DiffUtils.diff(base, right)
.withConflictOutput(CONFLICT_PRODUCES_MERGE_CONFLICT);

List<String> applied = rightPatch.applyTo(left);

assertEquals("IMAGINE there's no HEAVEN", applied.stream().collect(joining(" ")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,28 @@ public void testIssue129SkipDeltaDecompression() {

assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE CHANGE CHANGE EQUAL EQUAL EQUAL");
}

@Test
public void testIssue129SkipWhitespaceChanges() throws IOException {
String original = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_1.txt")).collect(joining("\n"));
String revised = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_2.txt")).collect(joining("\n"));

DiffRowGenerator generator = DiffRowGenerator.create()
.showInlineDiffs(true)
.mergeOriginalRevised(true)
.inlineDiffByWord(true)
.ignoreWhiteSpaces(true)
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
.build();
List<DiffRow> rows = generator.generateDiffRows(
Arrays.asList(original.split("\n")),
Arrays.asList(revised.split("\n")));

assertThat(rows).hasSize(13);

rows.stream()
.filter(item -> item.getTag() != DiffRow.Tag.EQUAL)
.forEach(System.out::println);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated
to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or
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
dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live.
It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not
consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it,
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
forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought
here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that
from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that
we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of
freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and
dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether
that nation, or 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 dedicate a portion of that field, as a final resting place for those who here gave their lives
that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we
can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who
struggled here, have consecrated it, 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 forget what they did here. It is for us the living, rather, to be dedicated
here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here
dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause
for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died
in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the
people, for the people, shall not perish from the earth.

0 comments on commit 0545519

Please sign in to comment.