diff --git a/tests/test_api/test_punycode.py b/tests/test_api/test_punycode.py new file mode 100644 index 00000000..46ba4c78 --- /dev/null +++ b/tests/test_api/test_punycode.py @@ -0,0 +1,28 @@ +from markdown_it import _punycode + + +def test_to_ascii_encodes_non_ascii_labels(): + assert _punycode.to_ascii("bücher.de") == "xn--bcher-kva.de" + # ASCII labels are passed through unchanged. + assert _punycode.to_ascii("example.com") == "example.com" + + +def test_to_unicode_decodes_xn_prefix_labels(): + assert _punycode.to_unicode("xn--bcher-kva.de") == "bücher.de" + # Labels without the xn-- prefix are passed through unchanged. + assert _punycode.to_unicode("example.com") == "example.com" + + +def test_email_addresses_only_map_the_domain(): + # The local part is left intact, only the domain is punycoded. + assert _punycode.to_ascii("user@bücher.de") == "user@xn--bcher-kva.de" + assert _punycode.to_unicode("user@xn--bcher-kva.de") == "user@bücher.de" + + +def test_alternative_dot_separators(): + # U+3002, U+FF0E and U+FF61 are treated as label separators. + assert _punycode.to_ascii("www\u3002bücher\uff0ede") == "www.xn--bcher-kva.de" + + +def test_encode_decode_round_trip(): + assert _punycode.decode(_punycode.encode("bücher")) == "bücher"