add unit test for message slice

This commit is contained in:
Mix
2022-01-17 00:29:09 +08:00
parent 3b4c4d3081
commit b037be4485
3 changed files with 62 additions and 20 deletions

View File

@ -1,17 +0,0 @@
from utils import make_fake_message
def test_message_template():
from nonebot.adapters import MessageTemplate
Message = make_fake_message()
template = MessageTemplate("{a:custom}{b:text}{c:image}", Message)
@template.add_format_spec
def custom(input: str) -> str:
return input + "-custom!"
formatted = template.format(a="test", b="test", c="https://example.com/test")
assert formatted.extract_plain_text() == "test-custom!test"
assert str(formatted) == "test-custom!test[fake:image]"