D4796: testing: add more testing for ifileindex.lookup()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sat Sep 29 00:19:17 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The tests demonstrate some... questionable behavior of revlog.lookup().

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4796

AFFECTED FILES
  mercurial/testing/storage.py

CHANGE DETAILS

diff --git a/mercurial/testing/storage.py b/mercurial/testing/storage.py
--- a/mercurial/testing/storage.py
+++ b/mercurial/testing/storage.py
@@ -90,6 +90,30 @@
         with self.assertRaises(error.LookupError):
             f.lookup(b'%d' % nullrev)
 
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'badvalue')
+
+        self.assertEqual(f.lookup(hex(nullid)[0:12]), nullid)
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'-2')
+
+        # TODO this is wonky.
+        self.assertEqual(f.lookup(b'0'), nullid)
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'1')
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'11111111111111111111111111111111111111')
+
+        for i in range(-5, 5):
+            if i == nullrev:
+                continue
+
+            with self.assertRaises(LookupError):
+                f.lookup(i)
+
         self.assertEqual(f.linkrev(nullrev), nullrev)
 
         for i in range(-5, 5):
@@ -170,8 +194,22 @@
 
         self.assertEqual(f.lookup(node), node)
         self.assertEqual(f.lookup(0), node)
+        self.assertEqual(f.lookup(-1), nullid)
         self.assertEqual(f.lookup(b'0'), node)
         self.assertEqual(f.lookup(hex(node)), node)
+        self.assertEqual(f.lookup(hex(node)[0:12]), node)
+
+        with self.assertRaises(IndexError):
+            f.lookup(-2)
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'-2')
+
+        with self.assertRaises(IndexError):
+            f.lookup(1)
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'1')
 
         self.assertEqual(f.linkrev(0), 0)
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list