From 2336e6aa9032ed6c58a40ef71fa7d4566e65e19f Mon Sep 17 00:00:00 2001 From: joaofreires Date: Fri, 11 Nov 2022 13:48:57 -0300 Subject: [PATCH] add new tests --- src/utils/mod.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) 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()) + ), + "

example

\n" + ); + } + + #[test] + fn replace_root_links() { + assert_eq!( + render_markdown_with_abs_path( + "[example](/testing)", + false, + None, + Some(&"ABS_PATH".to_string()) + ), + "

example

\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()) + ), + "

example

\n" + ); + assert_eq!( + render_markdown_with_abs_path( + "[example](/bar.md)", + false, + Some(Path::new("foo/chapter.md")), + Some(&"ABS_PATH".to_string()) + ), + "

example

\n" + ); + assert_eq!( + render_markdown_with_abs_path( + "[example](/bar.html)", + false, + Some(Path::new("foo/chapter.md")), + None + ), + "

example

\n" + ); + } + + #[test] + fn preserves_relative_links() { + assert_eq!( + render_markdown_with_abs_path( + "[example](../testing)", + false, + None, + Some(&"ABS_PATH".to_string()) + ), + "

example

\n" + ); + } + + #[test] + fn preserves_root_links() { + assert_eq!( + render_markdown_with_abs_path("[example](/testing)", false, None, None), + "

example

\n" + ); + } + } #[allow(deprecated)] mod id_from_content { use super::super::id_from_content;