"""Unit tests for storage-format HTML -> Markdown conversion.""" from confluence_crawler.markdown import ( page_filename, render_markdown, slugify, storage_to_markdown, ) def test_slugify_sanitizes_illegal_chars(): assert slugify('a/b\\c:d*e?f"gi|j') == "a-b-c-d-e-f-g-h-i-j" assert slugify(" Hello World ") == "Hello-World" assert slugify("///") == "untitled" def test_storage_to_markdown_basic(): html = "

Hello

Some bold and italic text.

" md = storage_to_markdown(html) assert "Hello" in md assert "**bold**" in md assert "*italic*" in md def test_storage_to_markdown_table(): html = "
ab
12
" md = storage_to_markdown(html) assert "a" in md and "b" in md and "1" in md and "2" in md def test_storage_to_markdown_empty(): assert storage_to_markdown("") == "" assert storage_to_markdown(" ") == "" def test_storage_to_markdown_deeply_nested_no_crash(): """Regression: deeply nested tables must not raise RecursionError.""" nested = "
" * 7000 + "core" + "
" * 7000 md = storage_to_markdown(nested) assert "core" in md # content preserved via fallback def test_render_markdown_has_front_matter(): page = { "id": "123", "title": "My Page", "space": {"key": "DEV"}, "version": {"number": 3, "when": "2025-01-01T00:00:00.000Z"}, "body": {"storage": {"value": "

Hello

"}}, } md = render_markdown(page, "https://wiki.example.com") assert "title: My Page" in md assert "page_id: 123" in md assert "space: DEV" in md assert "https://wiki.example.com/pages/viewpage.action?pageId=123" in md assert "# My Page" in md assert "Hello" in md def test_page_filename_unique_and_safe(): p1 = page_filename({"id": "1", "title": "A/B: C"}) p2 = page_filename({"id": "2", "title": "A/B: C"}) assert p1 != p2 assert p1 == "1_A-B-C.md" assert p2 == "2_A-B-C.md"