git / moonbite-network / tests/test_forum_emoji.py · raw

"""Forum emoji: self-hosted Twemoji images, shortcodes, and no way to turnuser text into markup."""import forumimport forum_emojidef html(text):    return str(forum.render_body(text))def test_unicode_emoji_become_self_hosted_images():    out = html("found one \U0001F680")    assert '<img class="fx-emoji" src="/static/emoji/1f680.svg"' in out    # skin tone and ZWJ sequences resolve to their own artwork    assert "1f44d-1f3fd.svg" in html("\U0001F44D\U0001F3FD")    assert "1f468-200d-1f469-200d-1f467.svg" in html("\U0001F468‍\U0001F469‍\U0001F467")def test_plain_text_symbols_stay_text():    out = html("#1 (c) © 2026 version 3")    assert "<img" not in outdef test_shortcodes_and_custom_moonbite():    out = html(":rocket: :moonbite: :not_a_real_one:")    assert "1f680.svg" in out and "custom/moonbite.svg" in out    assert ":not_a_real_one:" in outdef test_code_spans_stay_literal():    out = html("`:rocket: \U0001F680`")    assert "<code>:rocket: \U0001F680</code>" in outdef test_escaping_still_holds_around_emoji():    out = html('<img src=x onerror=alert(1)> \U0001F680 :rocket:')    assert "onerror" not in out.replace("&lt;img src=x onerror=alert(1)&gt;", "")    assert str(forum.emojify_text("<b>\U0001F680</b>")).startswith("&lt;b&gt;<img")def test_emoji_only_posts_go_jumbo():    assert 'class="fx-jumbo"' in html("\U0001F389\U0001F389")    assert 'class="fx-jumbo"' not in html("nice \U0001F389")    assert forum_emoji.emoji_only(":moonbite:")def test_every_picker_emoji_has_artwork():    for group in forum_emoji.picker_data():        for item in group["items"]:            assert item["k"].startswith("custom/") or item["k"][:-4] in forum_emoji._NAMES