Files
tuimble/tests/test_strip_html.py
Username 65de74193a test: add _strip_html edge cases and config validation tests
strip_html: nested tags, malformed HTML, comments, entities.
config: unknown key filtering, missing file, mixed valid/invalid.
2026-02-24 16:38:02 +01:00

60 lines
1.4 KiB
Python

"""Tests for _strip_html edge cases."""
from tuimble.app import _strip_html
def test_plain_text_unchanged():
assert _strip_html("hello world") == "hello world"
def test_simple_tags_stripped():
assert _strip_html("<b>bold</b>") == "bold"
def test_nested_tags():
assert _strip_html("<div><p>text</p></div>") == "text"
def test_self_closing_tags():
assert _strip_html("line<br/>break") == "linebreak"
def test_entities_unescaped():
assert _strip_html("&amp; &lt; &gt;") == "& < >"
def test_html_entities_in_tags():
assert _strip_html("<b>&amp;</b>") == "&"
def test_mumble_style_message():
"""Typical Mumble chat message with anchor tag."""
msg = '<a href="https://example.com">link text</a> and more'
assert _strip_html(msg) == "link text and more"
def test_img_tag_with_attributes():
assert _strip_html('before<img src="x.png" alt="pic"/>after') == "beforeafter"
def test_comment_stripped():
assert _strip_html("before<!-- comment -->after") == "beforeafter"
def test_empty_string():
assert _strip_html("") == ""
def test_only_tags():
assert _strip_html("<br><hr><img/>") == ""
def test_unclosed_tag():
"""Malformed HTML should not crash."""
result = _strip_html("<b>unclosed")
assert "unclosed" in result
def test_multiple_entities():
assert _strip_html("&quot;quoted&quot;") == '"quoted"'