();
}
#[cfg(test)]
mod tests {
use crate::utils::markdown::spoiler_rule::add;
use markdown_it::MarkdownIt;
#[test]
fn test_spoiler_markdown() {
let tests: Vec<_> = vec![
(
"invalid spoiler",
"::: spoiler click to see more\nbut I never finished",
"::: spoiler click to see more\nbut I never finished
\n",
),
(
"another invalid spoiler",
"::: spoiler\nnever added the lead in\n:::",
"::: spoiler\nnever added the lead in\n:::
\n",
),
(
"basic spoiler, but no newline at the end",
"::: spoiler click to see more\nhow spicy!\n:::",
"click to see more
how spicy!\n
\n"
),
(
"basic spoiler with a newline at the end",
"::: spoiler click to see more\nhow spicy!\n:::\n",
"click to see more
how spicy!\n
\n"
),
(
"spoiler with extra markdown on the call to action (no extra parsing)",
"::: spoiler _click to see more_\nhow spicy!\n:::\n",
"_click to see more_
how spicy!\n
\n"
),
(
"spoiler with extra markdown in the fenced spoiler block",
"::: spoiler click to see more\n**how spicy!**\n*i have many lines*\n:::\n",
"click to see more
how spicy!\ni have many lines\n
\n"
),
(
"spoiler mixed with other content",
"hey you\npsst, wanna hear a secret?\n::: spoiler lean in and i'll tell you\n**you are breathtaking!**\n:::\nwhatcha think about that?",
"hey you\npsst, wanna hear a secret?
\nlean in and i'll tell you
you are breathtaking!\n
\nwhatcha think about that?
\n"
),
(
"spoiler mixed with indented content",
"- did you know that\n::: spoiler the call was\n***coming from inside the house!***\n:::\n - crazy, right?",
"\nthe call was
coming from inside the house!\n
\n\n"
)
];
tests.iter().for_each(|&(msg, input, expected)| {
let md = &mut MarkdownIt::new();
markdown_it::plugins::cmark::add(md);
add(md);
assert_eq!(
md.parse(input).xrender(),
expected,
"Testing {}, with original input '{}'",
msg,
input
);
});
}
}