from slidge_style_parser import format_body MATRIX_FORMATS = { "_": ("", ""), "*": ("", ""), "~": ("", ""), "`": ("", ""), "```": ("
", "
"), ">": ("
", "
"), "||": ("", "") } def test_basic(): assert(format_body("_underline_", MATRIX_FORMATS) == "underline") assert(format_body("*bold*", MATRIX_FORMATS) == "bold") assert(format_body("~strikethrough~", MATRIX_FORMATS) == "strikethrough") assert(format_body("`code span`", MATRIX_FORMATS) == "code span") assert(format_body("```code\nblock```", MATRIX_FORMATS) == "
code\nblock
") assert(format_body("||spoiler||", MATRIX_FORMATS) == "spoiler") def test_quotes(): assert(format_body(">single", MATRIX_FORMATS) == "
single
") assert(format_body(">single\n>grouped", MATRIX_FORMATS) == "
single\ngrouped
") assert(format_body(">>double", MATRIX_FORMATS) == "
double
") assert(format_body(">>double\n>grouped single", MATRIX_FORMATS) == "
double
\ngrouped single
") assert(format_body(">>>tripple\n>single\n>>double", MATRIX_FORMATS) == "
tripple
\nsingle\n
double
") def test_escaped(): assert(format_body("\\_no underline_", MATRIX_FORMATS) == "_no underline_") assert(format_body("\\\\_no underline_", MATRIX_FORMATS) == "\\_no underline_") assert(format_body(">>>tripple\n\\>none\n>>double", MATRIX_FORMATS) == "
tripple
\n>none\n
double
") def test_nested(): assert(format_body("`*~_code span_~*`", MATRIX_FORMATS) == "*~_code span_~*") assert(format_body("*_~`code span`~_*", MATRIX_FORMATS) == "code span") assert(format_body(">*_~`code span`~_*", MATRIX_FORMATS) == "
code span
") assert(format_body("*bold star >*< star bold*", MATRIX_FORMATS) == "bold star >*< star bold") assert(format_body("*_bold*_", MATRIX_FORMATS) == "_bold_") assert(format_body("__underlined__", MATRIX_FORMATS) == "underlined") def test_no_changes(): assert(format_body("", MATRIX_FORMATS) == "") assert(format_body("~~ empty `````` styles **", MATRIX_FORMATS) == "~~ empty `````` styles **") assert(format_body("this is not an empty string", MATRIX_FORMATS) == "this is not an empty string") assert(format_body("arrow ->", MATRIX_FORMATS) == "arrow ->") assert(format_body(" > no quote", MATRIX_FORMATS) == " > no quote") assert(format_body("_not underlined", MATRIX_FORMATS) == "_not underlined") assert(format_body("|not a spoiler|", MATRIX_FORMATS) == "|not a spoiler|") assert(format_body("`no code\nblock here`", MATRIX_FORMATS) == "`no code\nblock here`") def test_assorted(): assert(format_body("at the ```end```", MATRIX_FORMATS) == "at the
end
") assert(format_body("in the ~middle~ here", MATRIX_FORMATS) == "in the middle here") assert(format_body("_underline_ *bold* ~strikethrough~ >not quote ||spoiler||\n>quote\nnothing\nnothing\n>>>>another quote with ||~_*```four```*_~||", MATRIX_FORMATS) == "underline bold strikethrough >not quote spoiler\n
quote
\nnothing\nnothing\n
another quote with
four
") def test_weird_utf8(): assert(format_body("โค๏ธ๐Ÿ’“๐Ÿ’•๐Ÿ’–๐Ÿ’— ```๐Ÿ’™๐Ÿ’š๐Ÿ’›๐Ÿ’œ๐Ÿ–ค``` ๐Ÿ’๐Ÿ’ž๐Ÿ’Ÿโฃ๏ธ", MATRIX_FORMATS) == "โค๏ธ๐Ÿ’“๐Ÿ’•๐Ÿ’–๐Ÿ’—
๐Ÿ’™๐Ÿ’š๐Ÿ’›๐Ÿ’œ๐Ÿ–ค
๐Ÿ’๐Ÿ’ž๐Ÿ’Ÿโฃ๏ธ") assert(format_body("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง _underline_๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆโ€๐Ÿ‘ง", MATRIX_FORMATS) == "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง underline๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆโ€๐Ÿ‘ง") assert(format_body("\u202eRight to left", MATRIX_FORMATS) == "\u202eRight to left") assert(format_body(">\u202eRight to left quote?", MATRIX_FORMATS) == "
\u202eRight to left quote?
") assert(format_body("_Invisible\u200bseparator_", MATRIX_FORMATS) == "Invisible\u200bseparator") assert(format_body("~\u200b~", MATRIX_FORMATS) == "\u200b") LIMITED_FORMATS = { "_": ("", ""), "~": ("", ""), "`": ("", ""), "||": ("", "") } def test_limited(): assert(format_body("_underline_ *bold* ~strikethrough~ >not quote ||spoiler||\n>quote\nnothing\nnothing\n>>>>another quote with ||~_*```four```*_~||", LIMITED_FORMATS) == "underline *bold* strikethrough >not quote spoiler\n>quote\nnothing\nnothing\n>>>>another quote with *```four```*")