mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-10 14:54:43 +00:00
Update tests
This commit is contained in:
parent
9b97b29514
commit
8588d2eade
1 changed files with 17 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use linkify::{LinkFinder, LinkKind};
|
||||
use linkify::LinkFinder;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use url::Url;
|
||||
|
|
@ -11,7 +11,7 @@ pub(crate) fn extract_links(input: &str) -> HashSet<Url> {
|
|||
// Silently ignore the parse failures for now.
|
||||
// TODO: Log errors in verbose mode
|
||||
let links: HashSet<Url> = links.iter().flat_map(|l| Url::parse(l.as_str())).collect();
|
||||
debug!("Testing links: {:#?}", links);
|
||||
debug!("Found links: {:#?}", links);
|
||||
|
||||
links
|
||||
}
|
||||
|
|
@ -23,8 +23,8 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_extract_markdown_links() {
|
||||
let md = "This is [a test](https://endler.dev).";
|
||||
let links = extract_links(md);
|
||||
let input = "This is [a test](https://endler.dev).";
|
||||
let links = extract_links(input);
|
||||
assert_eq!(
|
||||
links,
|
||||
HashSet::from_iter([Url::parse("https://endler.dev").unwrap()].iter().cloned())
|
||||
|
|
@ -33,22 +33,22 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_skip_markdown_anchors() {
|
||||
let md = "This is [a test](#lol).";
|
||||
let links = extract_links(md);
|
||||
let input = "This is [a test](#lol).";
|
||||
let links = extract_links(input);
|
||||
assert_eq!(links, HashSet::new())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_markdown_iternal_urls() {
|
||||
let md = "This is [a test](./internal).";
|
||||
let links = extract_links(md);
|
||||
let input = "This is [a test](./internal).";
|
||||
let links = extract_links(input);
|
||||
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 input = "https://endler.dev and https://hello-rust.show/foo/bar?lol=1";
|
||||
let links = extract_links(input);
|
||||
let expected = HashSet::from_iter(
|
||||
[
|
||||
Url::parse("https://endler.dev").unwrap(),
|
||||
|
|
@ -59,4 +59,11 @@ mod test {
|
|||
);
|
||||
assert_eq!(links, expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_emails() {
|
||||
let input = "matthias@example.com";
|
||||
let links = extract_links(input);
|
||||
assert_eq!(links, HashSet::new())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue