|
| 1 | +"""Markdown page-content selection must return exactly the requested lines, |
| 2 | +mirroring the PDF path — not the whole [min, max] range (PR #272 review / #280).""" |
| 3 | + |
| 4 | + |
| 5 | +def _md_structure(): |
| 6 | + # line_num 40 sits *between* 5 and 100 but is NOT requested below. |
| 7 | + return [ |
| 8 | + {"line_num": 5, "text": "line five", "nodes": [ |
| 9 | + {"line_num": 40, "text": "line forty (should be excluded)", "nodes": []}, |
| 10 | + ]}, |
| 11 | + {"line_num": 100, "text": "line hundred", "nodes": []}, |
| 12 | + {"line_num": 101, "text": "line 101", "nodes": []}, |
| 13 | + ] |
| 14 | + |
| 15 | + |
| 16 | +def test_get_md_page_content_returns_only_requested_lines(): |
| 17 | + from pageindex.index.utils import get_md_page_content |
| 18 | + |
| 19 | + out = get_md_page_content(_md_structure(), [5, 100]) |
| 20 | + # exactly the two requested lines — not 5, 40, 100 (the old range behavior) |
| 21 | + assert [r["page"] for r in out] == [5, 100] |
| 22 | + assert all("forty" not in r["content"] for r in out) |
| 23 | + |
| 24 | + |
| 25 | +def test_get_md_page_content_empty_spec(): |
| 26 | + from pageindex.index.utils import get_md_page_content |
| 27 | + |
| 28 | + assert get_md_page_content(_md_structure(), []) == [] |
| 29 | + |
| 30 | + |
| 31 | +def test_retrieve_md_page_content_returns_only_requested_lines(): |
| 32 | + # The legacy retrieve path has its own copy of the same logic. |
| 33 | + from pageindex.retrieve import _get_md_page_content |
| 34 | + |
| 35 | + out = _get_md_page_content({"structure": _md_structure()}, [5, 100]) |
| 36 | + assert [r["page"] for r in out] == [5, 100] |
0 commit comments