tests/test-annotate.py
changeset 34430 80215865d154
child 34432 2e32c6a31cc7
equal deleted inserted replaced
34429:b332c01247d8 34430:80215865d154
       
     1 from __future__ import absolute_import
       
     2 from __future__ import print_function
       
     3 
       
     4 import unittest
       
     5 
       
     6 from mercurial import (
       
     7     mdiff,
       
     8 )
       
     9 from mercurial.context import (
       
    10     _annotatepair,
       
    11 )
       
    12 
       
    13 class AnnotateTests(unittest.TestCase):
       
    14     """Unit tests for annotate code."""
       
    15 
       
    16     def testannotatepair(self):
       
    17         self.maxDiff = None # camelcase-required
       
    18 
       
    19         oldfctx = b'old'
       
    20         p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
       
    21         olddata = b'a\nb\n'
       
    22         p1data = b'a\nb\nc\n'
       
    23         p2data = b'a\nc\nd\n'
       
    24         childdata = b'a\nb2\nc\nc2\nd\n'
       
    25         diffopts = mdiff.diffopts()
       
    26 
       
    27         def decorate(text, rev):
       
    28             return ([(rev, i) for i in xrange(1, text.count(b'\n') + 1)], text)
       
    29 
       
    30         # Basic usage
       
    31 
       
    32         oldann = decorate(olddata, oldfctx)
       
    33         p1ann = decorate(p1data, p1fctx)
       
    34         p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
       
    35         self.assertEqual(p1ann[0], [('old', 1), ('old', 2), ('p1', 3)])
       
    36 
       
    37         p2ann = decorate(p2data, p2fctx)
       
    38         p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
       
    39         self.assertEqual(p2ann[0], [('old', 1), ('p2', 2), ('p2', 3)])
       
    40 
       
    41         # Test with multiple parents (note the difference caused by ordering)
       
    42 
       
    43         childann = decorate(childdata, childfctx)
       
    44         childann = _annotatepair([p1ann, p2ann], childfctx, childann, False,
       
    45                                  diffopts)
       
    46         self.assertEqual(childann[0],
       
    47             [('old', 1), ('c', 2), ('p2', 2), ('c', 4), ('p2', 3)]
       
    48         )
       
    49 
       
    50         childann = decorate(childdata, childfctx)
       
    51         childann = _annotatepair([p2ann, p1ann], childfctx, childann, False,
       
    52                                  diffopts)
       
    53         self.assertEqual(childann[0],
       
    54             [('old', 1), ('c', 2), ('p1', 3), ('c', 4), ('p2', 3)]
       
    55         )
       
    56 
       
    57         # Test with skipchild (note the difference caused by ordering)
       
    58 
       
    59         childann = decorate(childdata, childfctx)
       
    60         childann = _annotatepair([p1ann, p2ann], childfctx, childann, True,
       
    61                                  diffopts)
       
    62         self.assertEqual(childann[0],
       
    63             [('old', 1), ('old', 2), ('p2', 2), ('p2', 2), ('p2', 3)]
       
    64         )
       
    65 
       
    66         childann = decorate(childdata, childfctx)
       
    67         childann = _annotatepair([p2ann, p1ann], childfctx, childann, True,
       
    68                                  diffopts)
       
    69         self.assertEqual(childann[0],
       
    70             [('old', 1), ('old', 2), ('p1', 3), ('p1', 3), ('p2', 3)]
       
    71         )
       
    72 
       
    73 if __name__ == '__main__':
       
    74     import silenttestrunner
       
    75     silenttestrunner.main(__name__)