mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-20 21:18:13 +02:00
test: cover char-span line-range helper
This commit is contained in:
parent
0f32b35d3e
commit
90502d21d3
1 changed files with 39 additions and 0 deletions
39
surfsense_backend/tests/unit/utils/test_text_spans.py
Normal file
39
surfsense_backend/tests/unit/utils/test_text_spans.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""Unit tests for char-span -> line-range conversion."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.utils.text_spans import char_span_to_line_range
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
_TEXT = "line1\nline2\nline3"
|
||||
|
||||
|
||||
def test_single_line_span() -> None:
|
||||
start = _TEXT.index("line2")
|
||||
assert char_span_to_line_range(_TEXT, start, start + len("line2")) == (2, 2)
|
||||
|
||||
|
||||
def test_first_line_span() -> None:
|
||||
assert char_span_to_line_range(_TEXT, 0, len("line1")) == (1, 1)
|
||||
|
||||
|
||||
def test_last_line_span() -> None:
|
||||
start = _TEXT.index("line3")
|
||||
assert char_span_to_line_range(_TEXT, start, len(_TEXT)) == (3, 3)
|
||||
|
||||
|
||||
def test_multi_line_span() -> None:
|
||||
# "line1\nline2" spans lines 1-2.
|
||||
assert char_span_to_line_range(_TEXT, 0, _TEXT.index("line2") + 5) == (1, 2)
|
||||
|
||||
|
||||
def test_empty_span_resolves_to_its_line() -> None:
|
||||
start = _TEXT.index("line2")
|
||||
assert char_span_to_line_range(_TEXT, start, start) == (2, 2)
|
||||
|
||||
|
||||
def test_offsets_clamped_to_text_bounds() -> None:
|
||||
assert char_span_to_line_range(_TEXT, -5, 10_000) == (1, 3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue