# retoor <retoor@molodetz.nl>

from devplacepy.docs_prose import _anchor_headings, heading_slug


def test_heading_slug_normalizes():
    assert heading_slug("How the check works") == "how-the-check-works"
    assert heading_slug("Tell-tale AI writing in comments &amp; text") == "tell-tale-ai-writing-in-comments-text"
    assert heading_slug("  <em>Styled</em> Heading!  ") == "styled-heading"
    assert heading_slug("???") == "section"


def test_anchor_headings_injects_ids_and_permalinks():
    rendered = _anchor_headings("<h2>First Part</h2><p>x</p><h3>Sub Part</h3>")
    assert '<h2 id="first-part">' in rendered
    assert '<h3 id="sub-part">' in rendered
    assert rendered.count('class="docs-heading-anchor"') == 2
    assert 'href="#first-part"' in rendered


def test_anchor_headings_deduplicates_slugs():
    rendered = _anchor_headings("<h2>Setup</h2><h2>Setup</h2><h2>Setup</h2>")
    assert '<h2 id="setup">' in rendered
    assert '<h2 id="setup-1">' in rendered
    assert '<h2 id="setup-2">' in rendered


def test_anchor_headings_leaves_h1_untouched():
    rendered = _anchor_headings("<h1>Title</h1><h2>Part</h2>")
    assert "<h1>Title</h1>" in rendered
