From ac16d7aef1ed3c8d184c19fa7e5c48aba121de8e Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Tue, 20 Jun 2017 10:54:32 +0800 Subject: [PATCH] Added some tests for the original build_header_links function --- src/renderer/html_handlebars/hbs_renderer.rs | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 5948e9ab..fe78c920 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -419,8 +419,7 @@ fn build_header_links(html: String, filename: &str) -> String { id = id.replace(sub, ""); } let id = id.chars() - .filter(|c| if c.is_alphanumeric() || c == '-' || c == '_') - .map(|c| { + .filter_map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { if c.is_ascii() { Some(c.to_ascii_lowercase()) } else { @@ -561,3 +560,27 @@ struct RenderItemContext<'a> { data: serde_json::Map, is_index: bool, } + + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn original_build_header_links() { + let inputs = vec![ + ("blah blah

Foo

", r#"blah blah

Foo

"#), + ("

Foo

", r#"

Foo

"#), + ("

Foo^bar

", r#"

Foo^bar

"#), + ("

", r#"

"#), + ("

", r#"

"#), + ("

Foo

Foo

", r#"

Foo

Foo

"#), + ]; + + for (src, should_be) in inputs { + let got = build_header_links(src.to_string(), "bar.rs"); + assert_eq!(got, should_be); + } + } +} \ No newline at end of file