summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-02-03 07:29:59 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-02-03 07:29:59 -0500
commit839055cfd98d32c541ac2c074fb0cf6341909d26 (patch)
tree6e271a1e24bc74fddf890228befd192b6827131c /coverage/misc.py
parent093bd6e9949770455768a403162f86d54ce31544 (diff)
downloadpython-coveragepy-git-839055cfd98d32c541ac2c074fb0cf6341909d26.tar.gz
Fiddle with, and test, format_lines
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index 9c4843ef..28aa3b06 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -110,23 +110,28 @@ def format_lines(statements, lines):
For example, if `statements` is [1,2,3,4,5,10,11,12,13,14] and
`lines` is [1,2,5,10,11,13,14] then the result will be "1-2, 5-11, 13-14".
+ Both `lines` and `statements` can be any iterable. All of the elements of
+ `lines` must be in `statements`, and all of the values must be positive
+ integers.
+
"""
- pairs = []
- i = 0
- j = 0
- start = None
statements = sorted(statements)
lines = sorted(lines)
- while i < len(statements) and j < len(lines):
- if statements[i] == lines[j]:
- if start is None:
- start = lines[j]
- end = lines[j]
- j += 1
+
+ pairs = []
+ start = None
+ lidx = 0
+ for stmt in statements:
+ if lidx >= len(lines):
+ break
+ if stmt == lines[lidx]:
+ lidx += 1
+ if not start:
+ start = stmt
+ end = stmt
elif start:
pairs.append((start, end))
start = None
- i += 1
if start:
pairs.append((start, end))
ret = ', '.join(map(nice_pair, pairs))