2019-12-25 23:12:08 +02:00
|
|
|
from typing import Any, Callable, Optional, Tuple
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from aiogram.utils import markdown
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestMarkdown:
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"func,args,sep,result",
|
|
|
|
|
[
|
|
|
|
|
[markdown.text, ("test", "test"), " ", "test test"],
|
|
|
|
|
[markdown.text, ("test", "test"), "\n", "test\ntest"],
|
|
|
|
|
[markdown.text, ("test", "test"), None, "test test"],
|
|
|
|
|
[markdown.bold, ("test", "test"), " ", "*test test*"],
|
|
|
|
|
[markdown.hbold, ("test", "test"), " ", "<b>test test</b>"],
|
2019-12-31 17:56:12 +02:00
|
|
|
[markdown.italic, ("test", "test"), " ", "_test test_\r"],
|
2019-12-25 23:12:08 +02:00
|
|
|
[markdown.hitalic, ("test", "test"), " ", "<i>test test</i>"],
|
|
|
|
|
[markdown.code, ("test", "test"), " ", "`test test`"],
|
|
|
|
|
[markdown.hcode, ("test", "test"), " ", "<code>test test</code>"],
|
|
|
|
|
[markdown.pre, ("test", "test"), " ", "```test test```"],
|
|
|
|
|
[markdown.hpre, ("test", "test"), " ", "<pre>test test</pre>"],
|
2019-12-31 17:56:12 +02:00
|
|
|
[markdown.underline, ("test", "test"), " ", "__test test__"],
|
2019-12-25 23:12:08 +02:00
|
|
|
[markdown.hunderline, ("test", "test"), " ", "<u>test test</u>"],
|
2019-12-31 17:56:12 +02:00
|
|
|
[markdown.strikethrough, ("test", "test"), " ", "~test test~"],
|
2019-12-25 23:12:08 +02:00
|
|
|
[markdown.hstrikethrough, ("test", "test"), " ", "<s>test test</s>"],
|
|
|
|
|
[markdown.link, ("test", "https://aiogram.dev"), None, "[test](https://aiogram.dev)"],
|
|
|
|
|
[
|
|
|
|
|
markdown.hlink,
|
|
|
|
|
("test", "https://aiogram.dev"),
|
|
|
|
|
None,
|
|
|
|
|
'<a href="https://aiogram.dev">test</a>',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
markdown.hide_link,
|
|
|
|
|
("https://aiogram.dev",),
|
|
|
|
|
None,
|
|
|
|
|
'<a href="https://aiogram.dev">​</a>',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_formatter(
|
|
|
|
|
self, func: Callable[[Any], Any], args: Tuple[str], sep: Optional[str], result: str
|
|
|
|
|
):
|
|
|
|
|
assert func(*args, **({"sep": sep} if sep is not None else {})) == result # type: ignore
|