"""Tests for :mod:`genshin_tcg.markup`.""" from __future__ import annotations from genshin_tcg.markup import clean_markup, inline_symbols, panel_ink, sanitize, strip_markup def test_clean_markup_converts_color_tags() -> None: assert clean_markup("Or") == 'Or' def test_clean_markup_converts_escaped_newlines() -> None: assert clean_markup("a\\nb") == "a
b" def test_clean_markup_keeps_colour_and_underline_spans() -> None: raw = 'DGT' expected = 'DGT' assert clean_markup(raw) == expected def test_clean_markup_applies_colour_map() -> None: raw = 'DGT' assert clean_markup(raw, color_map=panel_ink) == 'DGT' def test_panel_ink_neutralises_achromatic_and_darkens_hues() -> None: # White would be invisible on the frosted panel, so it collapses to ink. # The dataset writes colours as #RRGGBBAA, so the trailing byte is alpha. assert panel_ink("#FFFFFFFF") == "#3a332a" assert panel_ink("#FFFFFF") == "#3a332a" # Chromatic keyword colours keep their hue but gain contrast. assert panel_ink("#FFD780FF") == "#986F16" # gold assert panel_ink("#7EC236FF") == "#588826" # Dendro green # Anything that is not a hex colour is passed through untouched. assert panel_ink("red") == "red" def test_sanitize_removes_script_and_event_handlers() -> None: dirty = 'ok' cleaned = sanitize(dirty) assert "script" not in cleaned assert "alert" not in cleaned assert "onclick" not in cleaned assert cleaned == 'ok' def test_sanitize_unwraps_unknown_tags_but_keeps_text() -> None: assert sanitize("
hello world
") == "hello world" def test_sanitize_drops_non_allowlisted_styles() -> None: cleaned = sanitize('x') assert cleaned == 'x' def test_strip_markup_returns_plain_text() -> None: assert strip_markup("a\\nb") == "a b" def test_inline_symbols_prefixes_keyword_only_in_text() -> None: html = 'DGT Pyro' result = inline_symbols(html, {"Pyro": "[ICON]"}) assert result == 'DGT [ICON]Pyro' def test_inline_symbols_respects_word_boundaries_and_attributes() -> None: html = 'Pyromane' result = inline_symbols(html, {"Pyro": "[ICON]"}) # "Pyro" inside the attribute and inside "Pyromane" must not match. assert result == html def test_inline_symbols_no_symbols_is_identity() -> None: assert inline_symbols("x", {}) == "x"