from __future__ import annotations
from review_highlight_toggle import (
build_highlight_terms,
build_highlighted_preview_html,
find_exact_highlight_spans,
)
def test_build_highlight_terms_uses_only_included_complete_replacements():
rows = [
{"include": True, "find": "SYNTHETIC_NAME", "replace_with": "[PERSON_1]"},
{"include": False, "find": "SYNTHETIC_ADDRESS", "replace_with": "[ADDRESS_1]"},
{"include": True, "find": "SYNTHETIC_EMPTY_REPLACEMENT", "replace_with": ""},
{"include": True, "find": "", "replace_with": "[NO_FIND]"},
]
assert build_highlight_terms(rows) == ["[PERSON_1]"]
def test_build_highlight_terms_deduplicates_and_sorts_longest_first():
rows = [
{"include": True, "find": "SYNTHETIC_A", "replace_with": "[A]"},
{"include": True, "find": "SYNTHETIC_B", "replace_with": "[A_LONGER]"},
{"include": True, "find": "SYNTHETIC_C", "replace_with": "[A]"},
]
assert build_highlight_terms(rows) == ["[A_LONGER]", "[A]"]
def test_find_exact_highlight_spans_uses_exact_matching_only():
text = "SYNTHETIC [PERSON_1] and [PERSON_10] stay separate."
spans = find_exact_highlight_spans(text, ["[PERSON_1]"])
assert spans == [(10, 20)]
assert text[spans[0][0] : spans[0][1]] == "[PERSON_1]"
def test_build_highlighted_preview_html_escapes_document_text_before_wrapping():
text = "SYNTHETIC [PERSON_1]"
html = build_highlighted_preview_html(text, ["[PERSON_1]"])
assert "