marki-docx/tests/test_differ.py

45 lines
1.5 KiB
Python
Raw Normal View History

"""Tests for structural drift detection (FR-700)."""
from __future__ import annotations
from markidocx.differ import compare
class TestCompare:
def test_identical_text_no_drift(self) -> None:
md = "# Heading\n\nParagraph.\n\n- item one\n- item two"
report = compare(md, md)
assert not report.has_drift
assert report.preserved
assert not report.broken
assert not report.degraded
def test_missing_heading_detected(self) -> None:
original = "# Heading One\n\n## Heading Two\n\nText."
reimported = "# Heading One\n\nText."
report = compare(original, reimported)
assert report.has_drift
assert any("Heading Two" in b for b in report.broken)
def test_missing_list_item_detected(self) -> None:
original = "- alpha\n- beta\n- gamma"
reimported = "- alpha\n- gamma"
report = compare(original, reimported)
assert report.has_drift
assert any("beta" in b for b in report.broken)
def test_preserved_links_tracked(self) -> None:
md = "See [example](https://example.com) for details."
report = compare(md, md)
assert any("link" in p for p in report.preserved)
def test_empty_strings_no_drift(self) -> None:
report = compare("", "")
assert not report.has_drift
def test_table_presence_checked(self) -> None:
original = "| A | B |\n|---|---|\n| 1 | 2 |"
reimported = "No table here."
report = compare(original, reimported)
assert report.has_drift