tests/test-rust-revlog.py
changeset 51249 2966b88d4531
parent 51239 7eea2e4109ae
child 51251 0409bd6ba663
equal deleted inserted replaced
51248:8b243e2a3bc4 51249:2966b88d4531
     1 import struct
     1 import struct
     2 import unittest
     2 import unittest
       
     3 
       
     4 from mercurial.node import hex
     3 
     5 
     4 try:
     6 try:
     5     from mercurial import rustext
     7     from mercurial import rustext
     6 
     8 
     7     rustext.__name__  # trigger immediate actual import
     9     rustext.__name__  # trigger immediate actual import
    55 
    57 
    56         # let's check bool for an empty one
    58         # let's check bool for an empty one
    57         self.assertFalse(LazyAncestors(rustidx, [0], 0, False))
    59         self.assertFalse(LazyAncestors(rustidx, [0], 0, False))
    58 
    60 
    59 
    61 
       
    62 @unittest.skipIf(
       
    63     rustext is None,
       
    64     "rustext module revlog relies on is not available",
       
    65 )
       
    66 class RustRevlogNodeTreeClassTest(revlogtesting.RustRevlogBasedTestBase):
       
    67     def test_standalone_nodetree(self):
       
    68         idx = self.parserustindex()
       
    69         nt = revlog.NodeTree(idx)
       
    70         for i in range(4):
       
    71             nt.insert(i)
       
    72 
       
    73         bin_nodes = [entry[7] for entry in idx]
       
    74         hex_nodes = [hex(n) for n in bin_nodes]
       
    75 
       
    76         for i, node in enumerate(hex_nodes):
       
    77             self.assertEqual(nt.prefix_rev_lookup(node), i)
       
    78             self.assertEqual(nt.prefix_rev_lookup(node[:5]), i)
       
    79 
       
    80         # all 4 revisions in idx (standard data set) have different
       
    81         # first nybbles in their Node IDs,
       
    82         # hence `nt.shortest()` should return 1 for them, except when
       
    83         # the leading nybble is 0 (ambiguity with NULL_NODE)
       
    84         for i, (bin_node, hex_node) in enumerate(zip(bin_nodes, hex_nodes)):
       
    85             shortest = nt.shortest(bin_node)
       
    86             expected = 2 if hex_node[0] == ord('0') else 1
       
    87             self.assertEqual(shortest, expected)
       
    88             self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i)
       
    89 
       
    90 
    60 if __name__ == '__main__':
    91 if __name__ == '__main__':
    61     import silenttestrunner
    92     import silenttestrunner
    62 
    93 
    63     silenttestrunner.main(__name__)
    94     silenttestrunner.main(__name__)