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
"#, ); } #[test] fn highlights_bug_link() { expect_markdown( "Please look at b/123.", "

Please look at b/123.

", ); } #[test] fn highlights_cl_link() { expect_markdown( "Please look at cl/420.", "

Please look at cl/420.

", ); } #[test] fn highlights_r_link() { expect_markdown( "Fixed in r/3268.", "

Fixed in r/3268.

", ); } #[test] fn highlights_multiple_shortlinks() { expect_markdown( "Please look at cl/420, b/123.", "

Please look at cl/420, b/123.

", ); expect_markdown( "b/213/cl/213 are different things", "

b/213/cl/213 are different things

", ); } #[test] fn ignores_invalid_shortlinks() { expect_markdown("b/abc is not a real bug", "

b/abc is not a real bug

"); } #[test] fn syntax_set_loaded() { assert!(SYNTAXES.syntaxes().len() > 0) }