From c7105090786d34bbb7cc1da9cead7441411ad858 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Mar 2021 17:47:49 +0200 Subject: test(cheddar): Add simple Markdown rendering tests Covers some of the odd things we do, specifically callouts and code rendering. Change-Id: Ib8542373b434b53d277b0d8c9ddb78ac7c5176a5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2689 Tested-by: BuildkiteCI Reviewed-by: flokli --- tools/cheddar/src/tests.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/cheddar/src/tests.rs (limited to 'tools/cheddar/src/tests.rs') diff --git a/tools/cheddar/src/tests.rs b/tools/cheddar/src/tests.rs new file mode 100644 index 000000000000..8b8219b22d7c --- /dev/null +++ b/tools/cheddar/src/tests.rs @@ -0,0 +1,63 @@ +use super::*; +use std::io::BufReader; + +// Markdown rendering expectation, ignoring leading and trailing +// whitespace in the input and output. +fn expect_markdown(input: &str, expected: &str) { + let mut input_buf = BufReader::new(input.trim().as_bytes()); + let mut out_buf: Vec = vec![]; + format_markdown(&mut input_buf, &mut out_buf); + + let out_string = String::from_utf8(out_buf).expect("output should be UTF8"); + assert_eq!(out_string.trim(), expected.trim()); +} + +#[test] +fn renders_simple_markdown() { + expect_markdown("hello", "

hello

\n"); +} + +#[test] +fn renders_callouts() { + expect_markdown( + "TODO some task.", + r#"

+TODO some task. +

+"#, + ); + + expect_markdown( + "WARNING: be careful", + r#"

+WARNING: be careful +

+"#, + ); + + expect_markdown( + "TIP: note the thing", + r#"

+TIP: note the thing +

+"#, + ); +} + +#[test] +fn renders_code_snippets() { + expect_markdown( + r#" +Code: +```nix +toString 42 +``` +"#, + r#" +

Code:

+
+toString 42
+
+"#, + ); +} -- cgit 1.4.1