Merge pull request #3 from mehmetcansahin/remove_feature+test
Remove feature + test
This commit is contained in:
commit
3215c904e5
2 changed files with 30 additions and 2 deletions
10
src/icons.rs
10
src/icons.rs
|
@ -52,7 +52,15 @@ impl Icons {
|
||||||
.pending_entries
|
.pending_entries
|
||||||
.get_mut(&url)
|
.get_mut(&url)
|
||||||
.map(|(kind, _)| kind)
|
.map(|(kind, _)| kind)
|
||||||
.or_else(|| entries.find_map(|icon| (icon.url == url).then_some(&mut icon.kind)))
|
.or_else(|| {
|
||||||
|
entries.find_map(|icon| {
|
||||||
|
if icon.url.eq(&url) {
|
||||||
|
Some(&mut icon.kind)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
{
|
{
|
||||||
// if the kind is more important, replace it
|
// if the kind is more important, replace it
|
||||||
if &kind > existing_kind {
|
if &kind > existing_kind {
|
||||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -1,4 +1,3 @@
|
||||||
#![feature(async_closure, bool_to_option)]
|
|
||||||
//! # site_icons
|
//! # site_icons
|
||||||
//! An efficient website icon scraper.
|
//! An efficient website icon scraper.
|
||||||
//!
|
//!
|
||||||
|
@ -47,3 +46,24 @@ static CLIENT: Lazy<Client> = Lazy::new(|| {
|
||||||
headers.insert(USER_AGENT, HeaderValue::from_str("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36").unwrap());
|
headers.insert(USER_AGENT, HeaderValue::from_str("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36").unwrap());
|
||||||
Client::builder().default_headers(headers).build().unwrap()
|
Client::builder().default_headers(headers).build().unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_icons() {
|
||||||
|
let mut icons = Icons::new();
|
||||||
|
// scrape the icons from a url
|
||||||
|
icons.load_website("https://github.com").await.unwrap();
|
||||||
|
|
||||||
|
// fetch all icons, ensuring they exist & determining size
|
||||||
|
let entries = icons.entries().await;
|
||||||
|
|
||||||
|
// entries are sorted from highest to lowest resolution
|
||||||
|
for icon in &entries {
|
||||||
|
println!("{:?}", icon)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(entries.len() > 0, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in a new issue