Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Apr 12, 2024
1 parent 66a53f5 commit add54f6
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions lychee-bin/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,25 @@ async fn handle(
// - Skip caching excluded links; they might not be excluded in the next run.
// - Skip caching links for which the status code has been explicitly excluded from the cache.
let status = response.status();
if ignore_cache(&uri, status, cache_exclude_status) {
if ignore_cache(&uri, status, &cache_exclude_status) {
return response;
}

cache.insert(uri, status.into());
response
}

fn ignore_cache(uri: &Uri, status: &Status, cache_exclude_status: HashSet<u16>) -> bool {
fn ignore_cache(uri: &Uri, status: &Status, cache_exclude_status: &HashSet<u16>) -> bool {
let status_code = match status.code() {
None => 0,
Some(code) => code.as_u16(),
};

return uri.is_file()
uri.is_file()
|| status.is_excluded()
|| status.is_unsupported()
|| status.is_unknown()
|| cache_exclude_status.contains(&status_code);
|| cache_exclude_status.contains(&status_code)
}

fn show_progress(
Expand Down Expand Up @@ -399,54 +399,39 @@ mod tests {
let mut exclude = HashSet::new();

// Cache is not ignored
assert_eq!(
false,
ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Ok(StatusCode::OK),
exclude.clone()
)
);
assert!(!ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Ok(StatusCode::OK),
&exclude
));

// Cache is ignored for file URLs
assert_eq!(
true,
ignore_cache(
&Uri::try_from("file:///home").unwrap(),
&Status::Ok(StatusCode::OK),
exclude.clone()
)
);
assert!(ignore_cache(
&Uri::try_from("file:///home").unwrap(),
&Status::Ok(StatusCode::OK),
&exclude
));

// Cache is ignored for unsupported status
assert_eq!(
true,
ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Unsupported(ErrorKind::EmptyUrl),
exclude.clone()
)
);
assert!(ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Unsupported(ErrorKind::EmptyUrl),
&exclude
));

// Cache is ignored for unknown status
assert_eq!(
true,
ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::UnknownStatusCode(StatusCode::IM_A_TEAPOT),
exclude.clone()
)
);
assert!(ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::UnknownStatusCode(StatusCode::IM_A_TEAPOT),
&exclude
));

// Cache is ignored for excluded status codes
exclude.insert(200);
assert_eq!(
true,
ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Ok(StatusCode::OK),
exclude.clone()
)
);
assert!(ignore_cache(
&Uri::try_from("https://[::1]").unwrap(),
&Status::Ok(StatusCode::OK),
&exclude
));
}
}

0 comments on commit add54f6

Please sign in to comment.