Spaces:
Running
Running
Download tests/test_text_utils.py from ArielJoe/Prompt-Builder: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/tests/test_text_utils.py
- Command line
-
hf download hf://spaces/ArielJoe/Prompt-Builder/tests/test_text_utils.py
-
curl -L -o test_text_utils.py https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/tests/test_text_utils.py
1.13 kB
| """Unit tests for core.text_utils helpers.""" | |
| from __future__ import annotations | |
| from core.text_utils import align_norm_span, apply_replacements, spans_overlap | |
| def test_spans_overlap_boundary_and_containment_cases() -> None: | |
| assert spans_overlap(0, 5, 3, 8) is True | |
| assert spans_overlap(1, 10, 3, 5) is True | |
| assert spans_overlap(0, 5, 5, 8) is False | |
| assert spans_overlap(5, 8, 0, 5) is False | |
| assert spans_overlap(0, 2, 4, 6) is False | |
| def test_align_norm_span_maps_normalized_offsets_back_to_original() -> None: | |
| orig = "Tolong buat terimakasiiih ya" | |
| norm = "Tolong buat terimakasih ya" | |
| start, end = align_norm_span(12, 23, norm, orig) | |
| assert orig[start:end] == "terimakasiiih" | |
| assert align_norm_span(0, 3, "", orig) == (0, 0) | |
| assert align_norm_span(0, 3, norm, "") == (0, 0) | |
| def test_apply_replacements_preserves_offsets_across_multiple_edits() -> None: | |
| text = "Gw mau makan nasi brg dia" | |
| result = apply_replacements(text, [(0, 2, "Saya"), (18, 21, "bersama")]) | |
| assert result == "Saya mau makan nasi bersama dia" | |
| assert apply_replacements(text, []) == text | |