jotdown/tests/lib.rs

52 lines
1.9 KiB
Rust
Raw Normal View History

#[cfg(feature = "suite_bench")]
mod bench;
2022-11-12 12:46:13 -05:00
#[cfg(feature = "suite")]
mod suite;
#[cfg(any(feature = "suite", feature = "suite_bench"))]
2022-11-12 12:46:13 -05:00
#[macro_export]
macro_rules! suite_test {
($src:expr, $expected:expr) => {
2023-02-11 09:04:20 -05:00
use jotdown::Render;
2022-11-12 12:46:13 -05:00
let src = $src;
let expected = $expected;
let p = jotdown::Parser::new(src);
let mut actual = String::new();
2023-02-11 09:04:20 -05:00
jotdown::html::Renderer.push(p, &mut actual).unwrap();
2022-11-12 12:46:13 -05:00
assert_eq!(
actual.trim(),
expected.trim(),
concat!(
"\n",
"\x1b[0;1m========================= INPUT ============================\x1b[0m\n",
"\x1b[2m{}",
"\x1b[0;1m=================== ACTUAL vs EXPECTED =====================\x1b[0m\n",
"{}",
"\x1b[0;1m============================================================\x1b[0m\n",
),
$src,
{
let a = actual.trim().split('\n');
let b = expected.trim().split('\n');
let max = a.clone().count().max(b.clone().count());
let a_width = a.clone().map(|a| a.len()).max().unwrap_or(0);
a.chain(std::iter::repeat(""))
.zip(b.chain(std::iter::repeat("")))
.take(max)
.map(|(a, b)| {
format!(
"\x1b[{}m{:a_width$}\x1b[0m {}= \x1b[{}m{}\x1b[0m\n",
if a == b { "2" } else { "31" },
a,
if a == b { '=' } else { '!' },
if a == b { "2" } else { "32" },
b,
a_width = a_width,
)
})
.collect::<String>()
},
);
};
}