Files
mirrors-miniirc_matrix/test_formatting.py

29 lines
1.0 KiB
Python
Raw Normal View History

2022-12-26 11:18:59 +13:00
from miniirc_matrix import _Event, _irc_to_html, _matrix_html_to_irc
def test_irc_to_html():
2024-10-05 14:27:21 +13:00
assert _irc_to_html('Hello world!') == (None, set())
assert _irc_to_html('\x02Bold') == ('<strong>Bold</strong>', set())
2022-12-26 11:18:59 +13:00
assert (_irc_to_html('\x021 \x1d2\x02 3') ==
2024-10-05 14:27:21 +13:00
('<strong>1 <em>2</em></strong><em> 3</em>', set()))
assert (_irc_to_html('@test:example.com: \x1dHello') ==
('<a href="https://matrix.to/#/@test:example.com">'
'@test:example.com</a>: <em>Hello</em>', {'@test:example.com'}))
2022-12-26 11:18:59 +13:00
def html_to_irc(html):
res, html_parsed_ok = _matrix_html_to_irc(_Event({
'format': 'org.matrix.custom.html',
'formatted_body': html,
}))
assert html_parsed_ok
return res
def test_html_to_irc():
assert html_to_irc('Hello <b>world</b>!') == 'Hello \x02world\x02!'
assert html_to_irc('Hello\nworld!') == 'Hello\nworld!'
assert html_to_irc('Hello<br>world!') == 'Hello\nworld!'
assert html_to_irc('Hello<br/>world!') == 'Hello\nworld!'