from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from yuxi.channels.adapters.telegram.format import (
markdown_to_html,
strip_all_tags,
_convert_bold,
_convert_italic,
_convert_code_blocks,
_convert_inline_code,
_convert_links,
_sanitize_html,
)
class TestMarkdownToHTML:
def test_bold_conversion(self):
result = markdown_to_html("**hello**")
assert result == "hello"
def test_italic_conversion(self):
result = markdown_to_html("*hello*")
assert "hello" in result
def test_italic_underscore(self):
result = markdown_to_html("_hello_")
assert "hello" in result
def test_bold_and_italic(self):
result = markdown_to_html("**bold** and *italic*")
assert "bold" in result
assert "italic" in result
def test_strikethrough(self):
result = markdown_to_html("~~deleted~~")
assert "deleted" in result
def test_inline_code(self):
result = markdown_to_html("use `print()`")
assert "print()" in result
def test_code_block(self):
result = markdown_to_html("```python\nprint('hello')\n```")
assert "
" in result
assert "print" in result
def test_link_conversion(self):
result = markdown_to_html("[click here](https://example.com)")
assert 'click here' in result
def test_spoiler_conversion(self):
result = markdown_to_html("||secret||")
assert "secret " in result
def test_plain_text_passthrough(self):
result = markdown_to_html("hello world")
assert "hello world" in result
def test_escape_special_chars(self):
result = markdown_to_html("price & 5")
assert "&" in result
def test_sanitize_html_input(self):
result = markdown_to_html("clean")
assert "clean" in result
def test_strip_all_tags(self):
result = strip_all_tags("hello world")
assert result == "hello world"
def test_strip_all_tags_no_tags(self):
result = strip_all_tags("plain text")
assert result == "plain text"