mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
first test with conflict output
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PatchTest {
|
||||
|
||||
@@ -78,4 +79,48 @@ public class PatchTest {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Change_withExceptionProcessor() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to);
|
||||
|
||||
changeTest_from.set(2, "CDC");
|
||||
|
||||
patch.withConflictOutput(new ConflictOutput<String>() {
|
||||
@Override
|
||||
public void processConflict(VerifyChunk verifyChunk, AbstractDelta<String> delta, List<String> result) throws PatchFailedException {
|
||||
if (result.size() > delta.getSource().getPosition()) {
|
||||
List<String> orgData = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < delta.getSource().size(); i++) {
|
||||
orgData.add(result.get(delta.getSource().getPosition()));
|
||||
result.remove(delta.getSource().getPosition());
|
||||
}
|
||||
|
||||
orgData.add(0, "<<<<<< HEAD");
|
||||
orgData.add("======");
|
||||
orgData.addAll(delta.getSource().getLines());
|
||||
orgData.add(">>>>>>> PATCH");
|
||||
|
||||
result.addAll(delta.getSource().getPosition(), orgData);
|
||||
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
List<String> data = DiffUtils.patch(changeTest_from, patch);
|
||||
assertEquals(9, data.size());
|
||||
|
||||
assertEquals(Arrays.asList("aaa", "<<<<<< HEAD", "bbb", "CDC", "======", "bbb", "ccc", ">>>>>>> PATCH", "ddd"), data);
|
||||
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user