Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestBlame.java @ 680:58a6900f845d
Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 21 Jul 2013 17:15:34 +0200 |
parents | 1c49c0cee540 |
children | 7839ff0bfd78 |
comparison
equal
deleted
inserted
replaced
679:19f5167c2155 | 680:58a6900f845d |
---|---|
260 cmd.execute(ai); | 260 cmd.execute(ai); |
261 ar.run(changeset, false); | 261 ar.run(changeset, false); |
262 doAnnotateLineCheck(changeset, ar, ai); | 262 doAnnotateLineCheck(changeset, ar, ai); |
263 } | 263 } |
264 | 264 |
265 private void doAnnotateLineCheck(int cs, AnnotateRunner ar, AnnotateInspector hg4jResult) { | |
266 String[] hgAnnotateLines = ar.getLines(); | |
267 assertTrue("[sanity]", hgAnnotateLines.length > 0); | |
268 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, hg4jResult.getLineCount()); | |
269 | |
270 for (int i = 0; i < hgAnnotateLines.length; i++) { | |
271 String[] hgLine = hgAnnotateLines[i].split(":"); | |
272 assertTrue(hgAnnotateLines[i], hgLine.length >= 3); | |
273 int hgAnnotateRevIndex = Integer.parseInt(hgLine[0].trim()); | |
274 int hgFirstAppLine = Integer.parseInt(hgLine[1].trim()); | |
275 String hgLineText = hgAnnotateLines[i].substring(hgLine[0].length() + hgLine[1].length() + 2).trim(); | |
276 errorCollector.assertEquals(String.format("Revision mismatch for line %d (annotating rev: %d)", i+1, cs), hgAnnotateRevIndex, hg4jResult.getChangeset(i)); | |
277 errorCollector.assertEquals(hgLineText, hg4jResult.getLine(i).trim()); | |
278 errorCollector.assertEquals(hgFirstAppLine, hg4jResult.getOriginLine(i)); | |
279 } | |
280 } | |
281 | |
282 | |
283 @Test | 265 @Test |
284 public void testDiffTwoRevisions() throws Exception { | 266 public void testDiffTwoRevisions() throws Exception { |
285 HgRepository repo = Configuration.get().find("test-annotate"); | 267 HgRepository repo = Configuration.get().find("test-annotate"); |
286 HgDataFile df = repo.getFileNode("file1"); | 268 HgDataFile df = repo.getFileNode("file1"); |
287 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); | 269 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); |
317 // | 299 // |
318 String[] apiResult = splitLines(bos.toString()); | 300 String[] apiResult = splitLines(bos.toString()); |
319 String[] expected = splitLines(gp.result()); | 301 String[] expected = splitLines(gp.result()); |
320 Assert.assertArrayEquals(expected, apiResult); | 302 Assert.assertArrayEquals(expected, apiResult); |
321 } | 303 } |
304 | |
305 @Test | |
306 public void testAnnotateMergeMapViaBase() throws Exception { | |
307 HgRepository repo = Configuration.get().find("test-annotate3"); | |
308 HgDataFile df1 = repo.getFileNode("file1"); | |
309 HgDataFile df4 = repo.getFileNode("file4"); | |
310 HgDataFile df5 = repo.getFileNode("file5"); | |
311 assertTrue("[sanity]", df1.exists() && df4.exists()); | |
312 // hg annotate handles merge in its own way, here we check | |
313 // how map(diff(p1->base->p2)) merge strategy works | |
314 final String file1AnnotateResult = "3:1:1\n3:2:2x\n3:3:3y\n2:4:z\n0:1:1\n1:2:2x\n4:3:3y\n"; | |
315 final String file4AnnotateResult = "3:1:1\n1:2:2x\n4:3:3y\n2:4:z\n0:1:1\n3:6:2x\n3:7:3y\n"; | |
316 final String file5AnnotateResult = "0:1:1\n1:2:2x\n4:3:3y\n2:4:z\n5:5:1\n5:6:2x\n5:7:3y\n"; | |
317 HgAnnotateCommand cmd = new HgAnnotateCommand(repo); | |
318 cmd.changeset(5); | |
319 AnnotateInspector insp = new AnnotateInspector(); | |
320 // file1 | |
321 cmd.file(df1, false).execute(insp); | |
322 doAnnotateLineCheck(5, splitLines(file1AnnotateResult), insp); | |
323 // file4 | |
324 cmd.file(df4, false).execute(insp = new AnnotateInspector()); | |
325 doAnnotateLineCheck(5, splitLines(file4AnnotateResult), insp); | |
326 // file5 | |
327 cmd.file(df5, false).execute(insp = new AnnotateInspector()); | |
328 doAnnotateLineCheck(5, splitLines(file5AnnotateResult), insp); | |
329 } | |
322 | 330 |
323 // TODO HgWorkingCopyStatusCollector (and HgStatusCollector), with their ancestors (rev 59/69) have examples | 331 // TODO HgWorkingCopyStatusCollector (and HgStatusCollector), with their ancestors (rev 59/69) have examples |
324 // of *incorrect* assignment of common lines (like "}") - our impl doesn't process common lines in any special way | 332 // of *incorrect* assignment of common lines (like "}") - our impl doesn't process common lines in any special way |
325 // while original diff lib does. Would be nice to behave as close to original, as possible. | 333 // while original diff lib does. Would be nice to behave as close to original, as possible. |
326 | 334 |
347 } while (lineStart < seq.length()); | 355 } while (lineStart < seq.length()); |
348 assert ix == lineCount; | 356 assert ix == lineCount; |
349 return rv; | 357 return rv; |
350 } | 358 } |
351 | 359 |
360 private void doAnnotateLineCheck(int cs, AnnotateRunner ar, AnnotateInspector hg4jResult) { | |
361 String[] hgAnnotateLines = ar.getLines(); | |
362 assertTrue("[sanity]", hgAnnotateLines.length > 0); | |
363 assertEquals("Number of lines reported by native annotate and our impl", hgAnnotateLines.length, hg4jResult.getLineCount()); | |
364 doAnnotateLineCheck(cs, hgAnnotateLines, hg4jResult); | |
365 } | |
366 | |
367 private void doAnnotateLineCheck(int cs, String[] expectedAnnotateLines, AnnotateInspector hg4jResult) { | |
368 for (int i = 0; i < expectedAnnotateLines.length; i++) { | |
369 String[] hgLine = expectedAnnotateLines[i].split(":"); | |
370 assertTrue(expectedAnnotateLines[i], hgLine.length >= 3); | |
371 int hgAnnotateRevIndex = Integer.parseInt(hgLine[0].trim()); | |
372 int hgFirstAppLine = Integer.parseInt(hgLine[1].trim()); | |
373 String hgLineText = expectedAnnotateLines[i].substring(hgLine[0].length() + hgLine[1].length() + 2).trim(); | |
374 errorCollector.assertEquals(String.format("Revision mismatch for line %d (annotating rev: %d)", i+1, cs), hgAnnotateRevIndex, hg4jResult.getChangeset(i)); | |
375 errorCollector.assertEquals("Line text", hgLineText, hg4jResult.getLine(i).trim()); | |
376 errorCollector.assertEquals("Line in origin", hgFirstAppLine, hg4jResult.getOriginLine(i)); | |
377 } | |
378 } | |
352 | 379 |
353 private void ccc() throws Throwable { | 380 private void ccc() throws Throwable { |
354 HgRepository repo = new HgLookup().detect("/home/artem/hg/hgtest-annotate-merge/"); | 381 HgRepository repo = new HgLookup().detect("/home/artem/hg/hgtest-annotate-merge/"); |
355 HgDataFile df = repo.getFileNode("file.txt"); | 382 HgDataFile df = repo.getFileNode("file.txt"); |
356 DiffOutInspector dump = new DiffOutInspector(System.out); | 383 DiffOutInspector dump = new DiffOutInspector(System.out); |