diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 6636ed5f..d4d83e05 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -422,6 +422,88 @@ more text with spaces } } + mod render_markdown_with_abs_path { + use super::super::render_markdown_with_abs_path; + use std::path::Path; + + #[test] + fn preserves_external_links() { + assert_eq!( + render_markdown_with_abs_path( + "[example](https://www.rust-lang.org/)", + false, + None, + Some(&"ABS_PATH".to_string()) + ), + "
\n" + ); + } + + #[test] + fn replace_root_links() { + assert_eq!( + render_markdown_with_abs_path( + "[example](/testing)", + false, + None, + Some(&"ABS_PATH".to_string()) + ), + "\n" + ); + } + + #[test] + fn replace_root_links_using_path() { + assert_eq!( + render_markdown_with_abs_path( + "[example](bar.md)", + false, + Some(Path::new("foo/chapter.md")), + Some(&"ABS_PATH".to_string()) + ), + "\n" + ); + assert_eq!( + render_markdown_with_abs_path( + "[example](/bar.md)", + false, + Some(Path::new("foo/chapter.md")), + Some(&"ABS_PATH".to_string()) + ), + "\n" + ); + assert_eq!( + render_markdown_with_abs_path( + "[example](/bar.html)", + false, + Some(Path::new("foo/chapter.md")), + None + ), + "\n" + ); + } + + #[test] + fn preserves_relative_links() { + assert_eq!( + render_markdown_with_abs_path( + "[example](../testing)", + false, + None, + Some(&"ABS_PATH".to_string()) + ), + "\n" + ); + } + + #[test] + fn preserves_root_links() { + assert_eq!( + render_markdown_with_abs_path("[example](/testing)", false, None, None), + "\n" + ); + } + } #[allow(deprecated)] mod id_from_content { use super::super::id_from_content;