add new tests

This commit is contained in:
joaofreires 2022-11-11 13:48:57 -03:00
parent e2b0b05ef8
commit 2336e6aa90
No known key found for this signature in database
GPG Key ID: C21AD65E2F4A6C65
1 changed files with 82 additions and 0 deletions

View File

@ -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())
),
"<p><a href=\"https://www.rust-lang.org/\">example</a></p>\n"
);
}
#[test]
fn replace_root_links() {
assert_eq!(
render_markdown_with_abs_path(
"[example](/testing)",
false,
None,
Some(&"ABS_PATH".to_string())
),
"<p><a href=\"ABS_PATH/testing\">example</a></p>\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())
),
"<p><a href=\"ABS_PATH/foo/bar.html\">example</a></p>\n"
);
assert_eq!(
render_markdown_with_abs_path(
"[example](/bar.md)",
false,
Some(Path::new("foo/chapter.md")),
Some(&"ABS_PATH".to_string())
),
"<p><a href=\"ABS_PATH/foo/bar.html\">example</a></p>\n"
);
assert_eq!(
render_markdown_with_abs_path(
"[example](/bar.html)",
false,
Some(Path::new("foo/chapter.md")),
None
),
"<p><a href=\"foo/bar.html\">example</a></p>\n"
);
}
#[test]
fn preserves_relative_links() {
assert_eq!(
render_markdown_with_abs_path(
"[example](../testing)",
false,
None,
Some(&"ABS_PATH".to_string())
),
"<p><a href=\"../testing\">example</a></p>\n"
);
}
#[test]
fn preserves_root_links() {
assert_eq!(
render_markdown_with_abs_path("[example](/testing)", false, None, None),
"<p><a href=\"/testing\">example</a></p>\n"
);
}
}
#[allow(deprecated)] #[allow(deprecated)]
mod id_from_content { mod id_from_content {
use super::super::id_from_content; use super::super::id_from_content;