# retoor <retoor@molodetz.nl>

from devplacepy.services.telegram.format import (
    markdown_to_telegram_html,
    split_for_telegram,
)


def test_markdown_basic_formatting():
    out = markdown_to_telegram_html("Hello **bold** and _em_ and `code`")
    assert "<b>bold</b>" in out
    assert "<i>em</i>" in out
    assert "<code>code</code>" in out


def test_markdown_link_kept():
    out = markdown_to_telegram_html("see [docs](https://example.com/x)")
    assert '<a href="https://example.com/x">docs</a>' in out


def test_markdown_escapes_special_characters():
    out = markdown_to_telegram_html("a < b & c > d")
    assert "&lt;" in out and "&amp;" in out and "&gt;" in out


def test_markdown_drops_unsupported_tags():
    out = markdown_to_telegram_html("# Heading\n\ntext")
    assert "<h1>" not in out
    assert "<b>Heading</b>" in out


def test_split_respects_limit():
    chunks = split_for_telegram("a" * 5000, limit=3900)
    assert all(len(chunk) <= 3900 for chunk in chunks)
    assert "".join(chunks) == "a" * 5000


def test_split_short_text_single_chunk():
    assert split_for_telegram("hello") == ["hello"]


def test_split_breaks_single_oversized_line():
    chunks = split_for_telegram("b" * 9000, limit=4000)
    assert all(len(chunk) <= 4000 for chunk in chunks)
    assert "".join(chunks) == "b" * 9000


def test_split_empty_text_returns_single_empty_chunk():
    assert split_for_telegram("") == [""]


def test_markdown_empty_input_is_empty():
    assert markdown_to_telegram_html("") == ""
