mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
parselinenos() raise errors for "10-1" range
This commit is contained in:
parent
0e9c2e6027
commit
f562af06b2
@ -393,9 +393,11 @@ def parselinenos(spec, total):
|
||||
items.append(int(begend[0]) - 1)
|
||||
elif len(begend) == 2:
|
||||
start, end = begend
|
||||
start = start or 1 # left half open (cf. -10)
|
||||
end = end or total # right half open (cf. 10-)
|
||||
items.extend(range(int(start) - 1, int(end)))
|
||||
start = int(start or 1) # left half open (cf. -10)
|
||||
end = int(end or total) # right half open (cf. 10-)
|
||||
if start > end: # invalid range (cf. 10-1)
|
||||
raise ValueError
|
||||
items.extend(range(start - 1, end))
|
||||
else:
|
||||
raise ValueError
|
||||
except Exception:
|
||||
|
@ -105,9 +105,12 @@ def test_parselinenos():
|
||||
assert parselinenos('7-9', 10) == [6, 7, 8]
|
||||
assert parselinenos('7-', 10) == [6, 7, 8, 9]
|
||||
assert parselinenos('1,7-', 10) == [0, 6, 7, 8, 9]
|
||||
assert parselinenos('7-7', 10) == [6]
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('1-2-3', 10)
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('abc-def', 10)
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('-', 10)
|
||||
with pytest.raises(ValueError):
|
||||
parselinenos('3-1', 10)
|
||||
|
Loading…
Reference in New Issue
Block a user