Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestBlame.java @ 548:ab21ac7dd833
Line-by-line annotation API and support code in place
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 18 Feb 2013 19:58:51 +0100 |
parents | cd78e8b9d7bc |
children | 83afa680555d |
comparison
equal
deleted
inserted
replaced
547:66fc86e8c0dd | 548:ab21ac7dd833 |
---|---|
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static org.junit.Assert.assertEquals; | 19 import static org.junit.Assert.assertEquals; |
20 import static org.junit.Assert.assertTrue; | 20 import static org.junit.Assert.assertTrue; |
21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; | 21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
22 import static org.tmatesoft.hg.repo.HgRepository.TIP; | |
22 | 23 |
23 import java.io.ByteArrayOutputStream; | 24 import java.io.ByteArrayOutputStream; |
24 import java.io.PrintStream; | 25 import java.io.PrintStream; |
25 import java.util.Arrays; | 26 import java.util.Arrays; |
26 import java.util.regex.Pattern; | 27 import java.util.regex.Pattern; |
65 | 66 |
66 @Test | 67 @Test |
67 public void testFileAnnotate() throws Exception { | 68 public void testFileAnnotate() throws Exception { |
68 HgRepository repo = new HgLookup().detectFromWorkingDir(); | 69 HgRepository repo = new HgLookup().detectFromWorkingDir(); |
69 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | 70 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; |
70 final int[] checkChangesets = new int[] { 539 , 536, 531 }; | |
71 HgDataFile df = repo.getFileNode(fname); | 71 HgDataFile df = repo.getFileNode(fname); |
72 AnnotateFacility af = new AnnotateFacility(); | |
73 FileAnnotateInspector fa = new FileAnnotateInspector(); | |
74 for (int cs : checkChangesets) { | |
75 af.annotateChange(df, cs, new FileAnnotation(fa)); | |
76 } | |
77 | |
78 OutputParser.Stub op = new OutputParser.Stub(); | 72 OutputParser.Stub op = new OutputParser.Stub(); |
79 ExecHelper eh = new ExecHelper(op, null); | 73 ExecHelper eh = new ExecHelper(op, null); |
80 eh.run("hg", "annotate", "-r", String.valueOf(checkChangesets[0]), fname); | 74 |
81 | 75 for (int startChangeset : new int[] { 539, 541/*, TIP */}) { |
82 String[] hgAnnotateLines = splitLines(op.result()); | 76 FileAnnotateInspector fa = new FileAnnotateInspector(); |
83 assertTrue("[sanity]", hgAnnotateLines.length > 0); | 77 new AnnotateFacility().annotate(df, startChangeset, fa); |
84 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, fa.lineRevisions.length); | 78 |
85 | 79 |
86 for (int i = 0; i < fa.lineRevisions.length; i++) { | 80 op.reset(); |
87 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':'))); | 81 eh.run("hg", "annotate", "-r", startChangeset == TIP ? "tip" : String.valueOf(startChangeset), fname); |
88 assertEquals(String.format("Revision mismatch for line %d", i+1), hgAnnotateRevIndex, fa.lineRevisions[i]); | 82 |
83 String[] hgAnnotateLines = splitLines(op.result()); | |
84 assertTrue("[sanity]", hgAnnotateLines.length > 0); | |
85 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, fa.lineRevisions.length); | |
86 | |
87 for (int i = 0; i < fa.lineRevisions.length; i++) { | |
88 int hgAnnotateRevIndex = Integer.parseInt(hgAnnotateLines[i].substring(0, hgAnnotateLines[i].indexOf(':'))); | |
89 assertEquals(String.format("Revision mismatch for line %d", i+1), hgAnnotateRevIndex, fa.lineRevisions[i]); | |
90 } | |
89 } | 91 } |
90 } | 92 } |
91 | 93 |
92 private static String[] splitLines(CharSequence seq) { | 94 private static String[] splitLines(CharSequence seq) { |
93 int lineCount = 0; | 95 int lineCount = 0; |