File: test_util_lines.py

package info (click to toggle)
sphinx 8.2.3-12
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 26,960 kB
  • sloc: python: 105,864; javascript: 6,474; perl: 449; makefile: 178; sh: 37; xml: 19; ansic: 2
file content (24 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import annotations

import pytest

from sphinx.util._lines import parse_line_num_spec


def test_parse_line_num_spec() -> None:
    assert parse_line_num_spec('1,2,3', 10) == [0, 1, 2]
    assert parse_line_num_spec('4, 5, 6', 10) == [3, 4, 5]
    assert parse_line_num_spec('-4', 10) == [0, 1, 2, 3]
    assert parse_line_num_spec('7-9', 10) == [6, 7, 8]
    assert parse_line_num_spec('7-', 10) == [6, 7, 8, 9]
    assert parse_line_num_spec('1,7-', 10) == [0, 6, 7, 8, 9]
    assert parse_line_num_spec('7-7', 10) == [6]
    assert parse_line_num_spec('11-', 10) == [10]
    with pytest.raises(ValueError, match="invalid line number spec: '1-2-3'"):
        parse_line_num_spec('1-2-3', 10)
    with pytest.raises(ValueError, match="invalid line number spec: 'abc-def'"):
        parse_line_num_spec('abc-def', 10)
    with pytest.raises(ValueError, match="invalid line number spec: '-'"):
        parse_line_num_spec('-', 10)
    with pytest.raises(ValueError, match="invalid line number spec: '3-1'"):
        parse_line_num_spec('3-1', 10)