Object[] historyA = new Object[] {"a", 2, 2, 5, 5, "c", 0, 1, 2, 4, "b", 0, 1, 0, 1};
Object[] historyB = new Object[] {"b", 2, 3, 3, 4, "a", 0, 1, 0, 2 };
Object[] historyC = new Object[] {"c", 0, 1, 2, 4, "b", 0, 1, 0, 1 };
Object[] historyD = new Object[] {"d", 1, 1, 5, 5, "b", 2, 3, 3, 4, "a", 0, 1, 0, 2};
FileRenameHistory frh = new FileRenameHistory(0, 5);
for (Object[] history : new Object[][] {historyA, historyB, historyC, historyD}) {
String fname = history[0].toString();
HgDataFile df = repo.getFileNode(fname);
Assert.assertFalse(frh.isOutOfRange(df, df.getLastRevision()));
frh.build(df, df.getLastRevision());
int recordIndex = 0;
errorCollector.assertEquals(history.length / 5, frh.chunks());
for (Chunk c : frh.iterate(HgIterateDirection.NewToOld)) {
compareChunk(fname, c, history, recordIndex++);
}
errorCollector.assertEquals("Shall compare full history", history.length, recordIndex * 5);
}
//
HgDataFile df = repo.getFileNode("d");
Assert.assertFalse(frh.isOutOfRange(df, 0));
frh.build(df, 0);
errorCollector.assertEquals(1, frh.chunks());
Chunk c = frh.iterate(NewToOld).iterator().next();
compareChunk("abandoned d(0)", c, new Object[] { "d", 0, 0, 4, 4 }, 0);
//
df = repo.getFileNode("a");
Assert.assertFalse(frh.isOutOfRange(df, 0));
frh.build(df, 0);
errorCollector.assertEquals(1, frh.chunks());
c = frh.iterate(NewToOld).iterator().next();
compareChunk("a(0) and boundary checks", c, new Object[] { "a", 0, 0, 0, 0 }, 0);
//
repo = Configuration.get().find("test-annotate"); // need a long file history
df = repo.getFileNode("file1");
Assert.assertTrue("[sanity]", repo.getChangelog().getLastRevision() >=9);
Assert.assertTrue("[sanity]", df.exists() && df.getLastRevision() >= 9);
frh = new FileRenameHistory(0, 9);
frh.build(df, 9);
errorCollector.assertEquals(1, frh.chunks());
c = frh.iterate(NewToOld).iterator().next();
compareChunk("regular file, no renames", c, new Object[] { "file1", 0, 9, 0, 9 }, 0);
// restricted range
frh = new FileRenameHistory(3, 6);
Assert.assertFalse(frh.isOutOfRange(df, 9));
frh.build(df, 9); // start from out of range revision
errorCollector.assertEquals(1, frh.chunks());
c = frh.iterate(OldToNew).iterator().next();
compareChunk("regular file, no renames, in range 3..6", c, new Object[] { "file1", 3, 6, 3, 6 }, 0);
}