Browse Source

Added more test cases for RenameDetector

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
stable-0.9
Jeff Schumacher 15 years ago
parent
commit
f666cc755b
  1. 117
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java

117
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 { public class RenameDetectorTest extends RepositoryTestCase {
private static final String PATH_A = "src/A"; 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_H = "src/H";
private static final String PATH_Q = "src/Q"; 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 a = DiffEntry.add(PATH_A, foo);
DiffEntry b = DiffEntry.delete(PATH_Q, foo); DiffEntry b = DiffEntry.delete(PATH_Q, foo);
DiffEntry c = DiffEntry.add("README", bar); DiffEntry c = DiffEntry.add(PATH_H, bar);
DiffEntry d = DiffEntry.delete("REEDME", bar); DiffEntry d = DiffEntry.delete(PATH_B, bar);
rd.add(a); rd.add(a);
rd.add(b); rd.add(b);
@ -119,8 +120,30 @@ public class RenameDetectorTest extends RepositoryTestCase {
List<DiffEntry> entries = rd.compute(); List<DiffEntry> entries = rd.compute();
assertEquals(2, entries.size()); assertEquals(2, entries.size());
assertRename(d, c, 100, entries.get(0)); assertRename(b, a, 100, entries.get(0));
assertRename(b, a, 100, entries.get(1)); 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 { public void testInexactRename_OnePair() throws Exception {
@ -146,8 +169,8 @@ public class RenameDetectorTest extends RepositoryTestCase {
ObjectId cId = blob("some\nsort\nof\ntext\n"); ObjectId cId = blob("some\nsort\nof\ntext\n");
ObjectId dId = blob("completely\nunrelated\ntext\n"); ObjectId dId = blob("completely\nunrelated\ntext\n");
DiffEntry c = DiffEntry.add("c", cId); DiffEntry c = DiffEntry.add(PATH_B, cId);
DiffEntry d = DiffEntry.delete("d", dId); DiffEntry d = DiffEntry.delete(PATH_H, dId);
rd.add(a); rd.add(a);
rd.add(b); rd.add(b);
@ -156,9 +179,9 @@ public class RenameDetectorTest extends RepositoryTestCase {
List<DiffEntry> entries = rd.compute(); List<DiffEntry> entries = rd.compute();
assertEquals(3, entries.size()); assertEquals(3, entries.size());
assertSame(c, entries.get(0)); assertRename(b, a, 66, entries.get(0));
assertSame(d, entries.get(1)); assertSame(c, entries.get(1));
assertRename(b, a, 66, entries.get(2)); assertSame(d, entries.get(2));
} }
public void testInexactRename_LastByteDifferent() throws Exception { public void testInexactRename_LastByteDifferent() throws Exception {
@ -176,6 +199,21 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 88, entries.get(0)); 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 { public void testInexactRenames_OnePair2() throws Exception {
ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n"); ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n");
ObjectId bId = blob("ac\nab\nab\nab\naa\na0\na1\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)); 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 { private ObjectId blob(String content) throws Exception {
return testDb.blob(content).copy(); return testDb.blob(content).copy();
} }

Loading…
Cancel
Save