Skip to content

Commit

Permalink
Add pretty assertions to lychee-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Aug 15, 2023
1 parent 0732b09 commit 2fb3466
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lychee-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ features = ["runtime-tokio"]

[dev-dependencies]
doc-comment = "0.3.3"
pretty_assertions = "1.4.0"
tempfile = "3.7.1"
wiremock = "0.5.19"
serde_json = "1.0.104"
Expand Down
20 changes: 17 additions & 3 deletions lychee-lib/src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Extractor {

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use reqwest::Url;
use std::{collections::HashSet, path::Path};

Expand All @@ -72,20 +73,33 @@ mod tests {
let input_content = InputContent::from_string(input, file_type);

let extractor = Extractor::new(false, false);
let uris_html5gum = extractor
let uris_html5gum: HashSet<Uri> = extractor
.extract(&input_content)
.into_iter()
.filter_map(|raw_uri| Uri::try_from(raw_uri).ok())
.collect();
let uris_html5gum_sorted: Vec<Uri> = {
let mut uris = uris_html5gum.clone().into_iter().collect::<Vec<_>>();
uris.sort();
uris
};

let extractor = Extractor::new(true, false);
let uris_html5ever = extractor
let uris_html5ever: HashSet<Uri> = extractor
.extract(&input_content)
.into_iter()
.filter_map(|raw_uri| Uri::try_from(raw_uri).ok())
.collect();
let uris_html5ever_sorted: Vec<Uri> = {
let mut uris = uris_html5ever.into_iter().collect::<Vec<_>>();
uris.sort();
uris
};

assert_eq!(uris_html5gum, uris_html5ever);
assert_eq!(
uris_html5gum_sorted, uris_html5ever_sorted,
"Mismatch between html5gum and html5ever"
);
uris_html5gum
}

Expand Down

0 comments on commit 2fb3466

Please sign in to comment.