Debian Codegraph @

tests/test_util/test_util_lines.py

raw
1 from __future__ import annotations
2
3 import pytest
4
5 from sphinx.util._lines import parse_line_num_spec
6
7
8 def test_parse_line_num_spec() -> None:
9 assert parse_line_num_spec('1,2,3', 10) == [0, 1, 2]
10 assert parse_line_num_spec('4, 5, 6', 10) == [3, 4, 5]
11 assert parse_line_num_spec('-4', 10) == [0, 1, 2, 3]
12 assert parse_line_num_spec('7-9', 10) == [6, 7, 8]
13 assert parse_line_num_spec('7-', 10) == [6, 7, 8, 9]
14 assert parse_line_num_spec('1,7-', 10) == [0, 6, 7, 8, 9]
15 assert parse_line_num_spec('7-7', 10) == [6]
16 assert parse_line_num_spec('11-', 10) == [10]
17 with pytest.raises(ValueError, match="invalid line number spec: '1-2-3'"):
18 parse_line_num_spec('1-2-3', 10)
19 with pytest.raises(ValueError, match="invalid line number spec: 'abc-def'"):
20 parse_line_num_spec('abc-def', 10)
21 with pytest.raises(ValueError, match="invalid line number spec: '-'"):
22 parse_line_num_spec('-', 10)
23 with pytest.raises(ValueError, match="invalid line number spec: '3-1'"):
24 parse_line_num_spec('3-1', 10)