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) == "
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) == "
") assert(format_body(">>double\n>grouped single", MATRIX_FORMATS) == "double
") assert(format_body(">>>tripple\n>single\n>>double", MATRIX_FORMATS) == "double\ngrouped single
") 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) == "\nsingle\ntrippledouble
\n>none\ntripple
") def test_nested(): assert(format_body("`*~_code span_~*`", MATRIX_FORMATS) == "double
*~_code span_~*")
assert(format_body("*_~`code span`~_*", MATRIX_FORMATS) == "code span") assert(format_body("*bold*not bold*", MATRIX_FORMATS) == "boldnot bold*") assert(format_body("*_bold*_", MATRIX_FORMATS) == "_bold_") 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("__not underlined__", MATRIX_FORMATS) == "__not underlined__") 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 thecode span
end")
assert(format_body("in the ~middle~ here", MATRIX_FORMATS) == "in the quote\nnothing\nnothing\n
") def test_weird_utf8(): assert(format_body("โค๏ธ๐๐๐๐ ```๐๐๐๐๐ค``` ๐๐๐โฃ๏ธ", MATRIX_FORMATS) == "โค๏ธ๐๐๐๐another quote withfour
๐๐๐๐๐ค ๐๐๐โฃ๏ธ")
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) == "
", ""),
"||": ("", "")
}
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*