aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Schumacher2010-07-12 15:31:18 (EDT)
committerJeff Schumacher2010-07-12 17:48:31 (EDT)
commitf666cc755b35a8f57a7c208c88230f7ab7c1d07b (patch)
treebd1fd90ceba20136ab4236069e53155c0697d4de
parentbc08fafb411566522b232e37a2ec971db00676d6 (diff)
downloadjgit-f666cc755b35a8f57a7c208c88230f7ab7c1d07b.zip
jgit-f666cc755b35a8f57a7c208c88230f7ab7c1d07b.tar.gz
jgit-f666cc755b35a8f57a7c208c88230f7ab7c1d07b.tar.bz2
Added more test cases for RenameDetectorrefs/changes/23/1123/3
I added test cases to cover the majority of the code. It's not 100% coverage yet, but the remaining bits are small. Change-Id: Ib534c8e94b13358b8b22cf54e2ff84132bae6d14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java117
1 files changed, 108 insertions, 9 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
index fe0c565..86b40e2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
@@ -54,6 +54,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
public class RenameDetectorTest extends RepositoryTestCase {
private static final String PATH_A = "src/A";
+ private static final String PATH_B = "src/B";
private static final String PATH_H = "src/H";
private static final String PATH_Q = "src/Q";
@@ -109,8 +110,8 @@ public class RenameDetectorTest extends RepositoryTestCase {
DiffEntry a = DiffEntry.add(PATH_A, foo);
DiffEntry b = DiffEntry.delete(PATH_Q, foo);
- DiffEntry c = DiffEntry.add("README", bar);
- DiffEntry d = DiffEntry.delete("REEDME", bar);
+ DiffEntry c = DiffEntry.add(PATH_H, bar);
+ DiffEntry d = DiffEntry.delete(PATH_B, bar);
rd.add(a);
rd.add(b);
@@ -119,8 +120,30 @@ public class RenameDetectorTest extends RepositoryTestCase {
List<DiffEntry> entries = rd.compute();
assertEquals(2, entries.size());
- assertRename(d, c, 100, entries.get(0));
- assertRename(b, a, 100, entries.get(1));
+ assertRename(b, a, 100, entries.get(0));
+ assertRename(d, c, 100, entries.get(1));
+ }
+
+ public void testExactRename_MultipleIdenticalDeletes() throws Exception {
+ ObjectId foo = blob("foo");
+
+ DiffEntry a = DiffEntry.delete(PATH_A, foo);
+ DiffEntry b = DiffEntry.delete(PATH_B, foo);
+
+ DiffEntry c = DiffEntry.delete(PATH_H, foo);
+ DiffEntry d = DiffEntry.add(PATH_Q, foo);
+
+ rd.add(a);
+ rd.add(b);
+ rd.add(c);
+ rd.add(d);
+
+ // Pairs the add with the first delete added
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(3, entries.size());
+ assertEquals(b, entries.get(0));
+ assertEquals(c, entries.get(1));
+ assertRename(a, d, 100, entries.get(2));
}
public void testInexactRename_OnePair() throws Exception {
@@ -146,8 +169,8 @@ public class RenameDetectorTest extends RepositoryTestCase {
ObjectId cId = blob("some\nsort\nof\ntext\n");
ObjectId dId = blob("completely\nunrelated\ntext\n");
- DiffEntry c = DiffEntry.add("c", cId);
- DiffEntry d = DiffEntry.delete("d", dId);
+ DiffEntry c = DiffEntry.add(PATH_B, cId);
+ DiffEntry d = DiffEntry.delete(PATH_H, dId);
rd.add(a);
rd.add(b);
@@ -156,9 +179,9 @@ public class RenameDetectorTest extends RepositoryTestCase {
List<DiffEntry> entries = rd.compute();
assertEquals(3, entries.size());
- assertSame(c, entries.get(0));
- assertSame(d, entries.get(1));
- assertRename(b, a, 66, entries.get(2));
+ assertRename(b, a, 66, entries.get(0));
+ assertSame(c, entries.get(1));
+ assertSame(d, entries.get(2));
}
public void testInexactRename_LastByteDifferent() throws Exception {
@@ -176,6 +199,21 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 88, entries.get(0));
}
+ public void testInexactRename_NewlinesOnly() throws Exception {
+ ObjectId aId = blob("\n\n\n");
+ ObjectId bId = blob("\n\n\n\n");
+
+ DiffEntry a = DiffEntry.add(PATH_A, aId);
+ DiffEntry b = DiffEntry.delete(PATH_Q, bId);
+
+ rd.add(a);
+ rd.add(b);
+
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(1, entries.size());
+ assertRename(b, a, 74, entries.get(0));
+ }
+
public void testInexactRenames_OnePair2() throws Exception {
ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n");
ObjectId bId = blob("ac\nab\nab\nab\naa\na0\na1\n");
@@ -267,6 +305,67 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1));
}
+ public void testNoRenames_SymlinkAndFileSamePath() throws Exception {
+ ObjectId aId = blob("src/dest");
+
+ DiffEntry a = DiffEntry.delete(PATH_A, aId);
+ DiffEntry b = DiffEntry.add(PATH_A, aId);
+ a.oldMode = FileMode.SYMLINK;
+
+ rd.add(a);
+ rd.add(b);
+
+ // Deletes should be first
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(2, entries.size());
+ assertSame(a, entries.get(0));
+ assertSame(b, entries.get(1));
+ }
+
+ public void testSetRenameScore_IllegalArgs() throws Exception {
+ try {
+ rd.setRenameScore(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+
+ try {
+ rd.setRenameScore(101);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
+ }
+
+ public void testRenameLimit() throws Exception {
+ ObjectId aId = blob("foo\nbar\nbaz\nblarg\n");
+ ObjectId bId = blob("foo\nbar\nbaz\nblah\n");
+ DiffEntry a = DiffEntry.add(PATH_A, aId);
+ DiffEntry b = DiffEntry.delete(PATH_B, bId);
+
+ ObjectId cId = blob("a\nb\nc\nd\n");
+ ObjectId dId = blob("a\nb\nc\n");
+ DiffEntry c = DiffEntry.add(PATH_H, cId);
+ DiffEntry d = DiffEntry.delete(PATH_Q, dId);
+
+ rd.add(a);
+ rd.add(b);
+ rd.add(c);
+ rd.add(d);
+
+ rd.setRenameLimit(1);
+
+ assertTrue(rd.isOverRenameLimit());
+
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(4, entries.size());
+ assertSame(a, entries.get(0));
+ assertSame(b, entries.get(1));
+ assertSame(c, entries.get(2));
+ assertSame(d, entries.get(3));
+ }
+
private ObjectId blob(String content) throws Exception {
return testDb.blob(content).copy();
}