"""Tests for talemate.util.diff.
Covers dmp_inline_diff (HTML diff with span markup) and plain_text_diff
(bracket-marker diff).
"""
from talemate.util.diff import dmp_inline_diff, plain_text_diff
# ---------------------------------------------------------------------------
# dmp_inline_diff
# ---------------------------------------------------------------------------
def test_dmp_inline_diff_identical_returns_unwrapped_text():
"""Identical inputs should yield text without any diff markup."""
text = "hello world"
result = dmp_inline_diff(text, text)
assert result == text
assert "diff-delete" not in result
assert "diff-insert" not in result
def test_dmp_inline_diff_pure_insertion_marks_inserted_chunk():
"""When text2 adds content, the new chunk is wrapped in diff-insert."""
result = dmp_inline_diff("hello", "hello world")
assert "diff-insert" in result
assert "diff-delete" not in result
# Original text appears unwrapped, insertion appears in span
assert "hello" in result
assert '' in result
assert " world" in result
def test_dmp_inline_diff_pure_deletion_marks_deleted_chunk():
"""When text2 removes content, the missing chunk is wrapped in diff-delete."""
result = dmp_inline_diff("hello world", "hello")
assert "diff-delete" in result
assert "diff-insert" not in result
assert '' in result
assert " world" in result
def test_dmp_inline_diff_replacement_has_both_delete_and_insert():
"""A replacement should produce both delete and insert spans."""
result = dmp_inline_diff("hello world", "hello there")
assert '' in result
assert '' in result
def test_dmp_inline_diff_html_special_chars_are_escaped():
"""HTML-special characters in the text must be escaped in the output."""
text1 = "before"
text2 = "before & more"
result = dmp_inline_diff(text1, text2)
# Raw HTML characters must NOT appear in the output
assert "