Files
DeepTutor/tests/reading/test_grounding.py
Bingxi Zhao (Frank) 57df37b75f Merge pull request #1119 from evan188199-tech/codex/feat-reading-translation
# Conflicts:
#	pyproject.toml
#	web/components/reading/ReadingExtensionBar.tsx
#	web/locales/en/app.json
#	web/locales/zh/app.json
#	web/tests/reading-extensions.test.ts
2026-08-31 20:08:59 +08:00

20 lines
631 B
Python

from deeptutor.reading._grounding import grounding_context, selection_range
def test_selection_range_maps_collapsed_whitespace_back_to_source() -> None:
text = "before\n\tverified phrase after"
bounds = selection_range(text, "verified phrase")
assert bounds is not None
assert text[bounds[0] : bounds[1]] == "verified phrase"
def test_grounding_context_keeps_a_late_selection_inside_the_bound() -> None:
text = "prefix " * 2_000 + "verified phrase" + " suffix" * 2_000
context = grounding_context(text, "verified phrase")
assert len(context) == 6_000
assert "verified phrase" in context