changeset 40001:215fd73cfe52

testing: add more testing for ifileindex.lookup() The tests demonstrate some... questionable behavior of revlog.lookup(). Differential Revision: https://phab.mercurial-scm.org/D4796
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:00:20 -0700
parents 8af835af0a85
children 0e8836be9541
files mercurial/testing/storage.py
diffstat 1 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/testing/storage.py	Fri Sep 28 10:20:37 2018 -0700
+++ b/mercurial/testing/storage.py	Fri Sep 28 11:00:20 2018 -0700
@@ -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)