diff test/org/tmatesoft/hg/test/TestBlame.java @ 573:e49f9d9513fa

Partial blame when start/end revisions are in the middle of a single filename history
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 12 Apr 2013 19:50:21 +0200
parents 36853bb80a35
children 707b5c7c6fa4
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestBlame.java	Fri Apr 12 18:30:55 2013 +0200
+++ b/test/org/tmatesoft/hg/test/TestBlame.java	Fri Apr 12 19:50:21 2013 +0200
@@ -18,11 +18,15 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.tmatesoft.hg.core.HgIterateDirection.NewToOld;
+import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
 import static org.tmatesoft.hg.repo.HgRepository.TIP;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -186,6 +190,39 @@
 		errorCollector.assertTrue(String.format("Annotate API reported excessive diff: %s ", apiResult.toString()), apiResult.isEmpty());
 	}
 
+	
+	@Test
+	public void testPartialHistoryFollow() throws Exception {
+		HgRepository repo = Configuration.get().find("test-annotate2");
+		HgDataFile df = repo.getFileNode("file1b.txt");
+		// rev3: file1 -> file1a,  rev7: file1a -> file1b, tip: rev10
+		HgBlameFacility bf = new HgBlameFacility(df);
+		DiffOutInspector insp = new DiffOutInspector(new PrintStream(new OutputStream() {
+			@Override
+			public void write(int b) throws IOException {
+				// NULL OutputStream
+			}
+		}));
+		// rev6 changes rev4, rev4 changes rev3. Plus, anything changed 
+		// earlier than rev2 shall be reported as new from change3
+		int[] change_2_8_new2old = new int[] {4, 6, 3, 4, -1, 3}; 
+		int[] change_2_8_old2new = new int[] {-1, 3, 3, 4, 4, 6 };
+		bf.annotate(2, 8, insp, NewToOld);
+		Assert.assertArrayEquals(change_2_8_new2old, insp.getReportedRevisionPairs());
+		insp.reset();
+		bf.annotate(2, 8, insp, OldToNew);
+		Assert.assertArrayEquals(change_2_8_old2new, insp.getReportedRevisionPairs());
+		// same as 2 to 8, with addition of rev9 changes rev7  (rev6 to rev7 didn't change content, only name)
+		int[] change_3_9_new2old = new int[] {7, 9, 4, 6, 3, 4, -1, 3 }; 
+		int[] change_3_9_old2new = new int[] {-1, 3, 3, 4, 4, 6, 7, 9 };
+		insp.reset();
+		bf.annotate(3, 9, insp, NewToOld);
+		Assert.assertArrayEquals(change_3_9_new2old, insp.getReportedRevisionPairs());
+		insp.reset();
+		bf.annotate(3, 9, insp, OldToNew);
+		Assert.assertArrayEquals(change_3_9_old2new, insp.getReportedRevisionPairs());
+	}
+
 	@Test
 	public void testAnnotateCmdFollowNoFollow() throws Exception {
 		HgRepoFacade hgRepoFacade = new HgRepoFacade();
@@ -369,6 +406,14 @@
 			return x;
 		}
 		
+		int[] getReportedRevisionPairs() {
+			return reportedRevisionPairs.toArray();
+		}
+		
+		void reset() {
+			reportedRevisionPairs.clear();
+		}
+		
 		public void same(EqualBlock block) {
 			// nothing 
 		}