ReMe/tests/unit/test_line_anchor.py
jinliyl a9ec334adc
feat: simplify wikilink semantics and support line anchors (#412)
* feat: simplify local links and support line anchors

* fix: align line anchor tests with CI lint

* fix: preserve local links across file moves

* fix: encode markdown paths when rewriting links

* refactor(read): keep explicit line range parameters

* fix: simplify legacy link predicate compatibility

* docs: align local link behavior with implementation

* fix: skip unsupported markdown destination escapes

* fix: normalize workspace link paths across platforms

* fix: bound markdown link scanning

* fix: keep local link processing linear

* docs: clarify permissive markdown link parsing

* fix: handle local link processing failures

* refactor: limit file links to wikilink syntax

* docs: align wikilink contract with implementation

* fix: normalize dream and neighbor paths on Windows

* fix: resolve workspace path for neighbor expansion
2026-08-05 11:47:50 +08:00

31 lines
1.1 KiB
Python

"""Tests for GitHub-style line anchor parsing."""
import pytest
from reme.utils import format_line_anchor, parse_line_anchor
def test_parse_supported_line_anchors():
"""Single lines, continuous ranges, and comma-separated ranges parse."""
assert parse_line_anchor("L9") == [(9, 9)]
assert parse_line_anchor("L9-L10") == [(9, 10)]
assert parse_line_anchor("L9-L10,L15-L20") == [(9, 10), (15, 20)]
def test_parse_merges_overlapping_and_adjacent_ranges():
"""Normalization merges ranges whose covered lines touch."""
ranges = parse_line_anchor("L9-L12,L11-L15,L16")
assert ranges == [(9, 16)]
assert format_line_anchor(ranges) == "L9-L16"
def test_non_line_heading_is_unchanged():
"""Ordinary heading anchors are outside this parser's contract."""
assert parse_line_anchor("Introduction") is None
@pytest.mark.parametrize("anchor", ["L0", "L10-L9", "L9-Lx", "L9,"])
def test_invalid_line_anchor_rejected(anchor):
"""Line-looking anchors fail clearly when malformed or out of range."""
with pytest.raises(ValueError):
parse_line_anchor(anchor)