mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-26 22:23:58 +00:00
Add tests for extract
This commit is contained in:
parent
12e978224d
commit
fb517dab03
1 changed files with 45 additions and 0 deletions
|
|
@ -18,3 +18,48 @@ pub(crate) fn extract_links(md: &str) -> HashSet<Url> {
|
|||
|
||||
links
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
#[test]
|
||||
fn test_extract_markdown_links() {
|
||||
let md = "This is [a test](https://endler.dev).";
|
||||
let links = extract_links(md);
|
||||
assert_eq!(
|
||||
links,
|
||||
HashSet::from_iter([Url::parse("https://endler.dev").unwrap()].iter().cloned())
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_markdown_anchors() {
|
||||
let md = "This is [a test](#lol).";
|
||||
let links = extract_links(md);
|
||||
assert_eq!(links, HashSet::new())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_markdown_iternal_urls() {
|
||||
let md = "This is [a test](./internal).";
|
||||
let links = extract_links(md);
|
||||
assert_eq!(links, HashSet::new())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_markdown_links() {
|
||||
let md = "https://endler.dev and https://hello-rust.show/foo/bar?lol=1";
|
||||
let links = extract_links(md);
|
||||
let expected = HashSet::from_iter(
|
||||
[
|
||||
Url::parse("https://endler.dev").unwrap(),
|
||||
Url::parse("https://hello-rust.show/foo/bar?lol=1").unwrap(),
|
||||
]
|
||||
.iter()
|
||||
.cloned(),
|
||||
);
|
||||
assert_eq!(links, expected)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue