revlog: add a doctest to _trimchunk
authorBoris Feld <boris.feld@octobus.net>
Tue, 10 Jul 2018 10:04:44 +0200
changeset 38638 740f7d447222
parent 38637 e33f784f2a44
child 38639 2dd4cf273804
revlog: add a doctest to _trimchunk
mercurial/revlog.py
tests/test-doctest.py
--- a/mercurial/revlog.py	Tue Jul 10 10:04:31 2018 +0200
+++ b/mercurial/revlog.py	Tue Jul 10 10:04:44 2018 +0200
@@ -218,6 +218,41 @@
 
 def _trimchunk(revlog, revs, startidx, endidx=None):
     """returns revs[startidx:endidx] without empty trailing revs
+
+    Doctest Setup
+    >>> revlog = _testrevlog([
+    ...  5,  #0
+    ...  10, #1
+    ...  12, #2
+    ...  12, #3 (empty)
+    ...  17, #4
+    ...  21, #5
+    ...  21, #6 (empty)
+    ... ])
+
+    Contiguous cases:
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 0)
+    [0, 1, 2, 3, 4, 5]
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 0, 5)
+    [0, 1, 2, 3, 4]
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 0, 4)
+    [0, 1, 2]
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 2, 4)
+    [2]
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 3)
+    [3, 4, 5]
+    >>> _trimchunk(revlog, [0, 1, 2, 3, 4, 5, 6], 3, 5)
+    [3, 4]
+
+    Discontiguous cases:
+    >>> _trimchunk(revlog, [1, 3, 5, 6], 0)
+    [1, 3, 5]
+    >>> _trimchunk(revlog, [1, 3, 5, 6], 0, 2)
+    [1]
+    >>> _trimchunk(revlog, [1, 3, 5, 6], 1, 3)
+    [3, 5]
+    >>> _trimchunk(revlog, [1, 3, 5, 6], 1)
+    [3, 5]
     """
     length = revlog.length
 
--- a/tests/test-doctest.py	Tue Jul 10 10:04:31 2018 +0200
+++ b/tests/test-doctest.py	Tue Jul 10 10:04:44 2018 +0200
@@ -60,6 +60,7 @@
 testmod('mercurial.pathutil')
 testmod('mercurial.parser')
 testmod('mercurial.pycompat')
+testmod('mercurial.revlog')
 testmod('mercurial.revsetlang')
 testmod('mercurial.smartset')
 testmod('mercurial.store')