cleanup and fixes: comparator in Patch was broken which caused incorrect delta sorting, Chunk does not store lines as a separate field, in fact it is an attribute of the Chunk.lines collection.Minor cleanup in tests, still more to be done in geenerated udiff tests

This commit is contained in:
shotwave
2011-03-25 21:28:13 +00:00
parent 4f9928e4ef
commit 02ded9901f
12 changed files with 217 additions and 304 deletions

View File

@@ -1,46 +1,35 @@
package diffutils;
import difflib.DiffUtils;
import difflib.Patch;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import difflib.DiffUtils;
import difflib.Patch;
public class PatchTest extends TestCase {
private List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
private List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
private List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
private List<String> deleteTest_to = Arrays.asList("ggg");
private List<String> insertTest_from = Arrays.asList("hhh");
private List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
public void testPatch_Insert() {
Patch patch = DiffUtils.diff(insertTest_from, insertTest_to);
try {
assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch));
} catch (Exception e) {
e.printStackTrace();
}
public void testPatch_Insert() throws Exception {
final List<String> insertTest_from = Arrays.asList("hhh");
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
final Patch patch = DiffUtils.diff(insertTest_from, insertTest_to);
assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch));
}
public void testPatch_Delete() {
Patch patch = DiffUtils.diff(deleteTest_from, deleteTest_to);
try {
assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch));
} catch (Exception e) {
e.printStackTrace();
}
public void testPatch_Delete() throws Exception {
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
final List<String> deleteTest_to = Arrays.asList("ggg");
final Patch patch = DiffUtils.diff(deleteTest_from, deleteTest_to);
assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch));
}
public void testPatch_Change() {
Patch patch = DiffUtils.diff(changeTest_from, changeTest_to);
try {
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch));
} catch (Exception e) {
e.printStackTrace();
}
public void testPatch_Change() throws Exception {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
final Patch patch = DiffUtils.diff(changeTest_from, changeTest_to);
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch));
}
}