From b7c9865412fcc153616a47f3e7fc958e2dfb5a52 Mon Sep 17 00:00:00 2001 From: Paul Delafosse Date: Fri, 13 May 2022 08:01:21 +0200 Subject: [PATCH] test: improve tests and fmt all --- benches/simple_lookup.rs | 44 +++++++++++++++++----------------------- src/lib.rs | 32 +++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/benches/simple_lookup.rs b/benches/simple_lookup.rs index 37fd78c..a5b938a 100644 --- a/benches/simple_lookup.rs +++ b/benches/simple_lookup.rs @@ -3,48 +3,42 @@ use freedesktop_icons::lookup; use gtk4::{IconLookupFlags, IconTheme, TextDirection}; pub fn simple_bench(c: &mut Criterion) { - c.bench_function("firefox lookup", |b| b.iter(|| - lookup("firefox") - .with_theme("Papirus") - .with_cache() - .find() - )); + c.bench_function("firefox lookup", |b| { + b.iter(|| lookup("firefox").with_theme("Papirus").with_cache().find()) + }); } pub fn bench_lookups(c: &mut Criterion) { let mut group = c.benchmark_group("ComparisonsLookups"); let args = [ - "user-home", // (Best case) An icon that can be found in the current theme - "video-single-display-symbolic", // An icon that can be found in the parent theme - "firefox", // An icon that can be found in the hicolor default theme - "archlinux-logo", // An icon that resides in /usr/share/pixmap - "not-found", // (Worst case) An icon that does not exist + "user-home", // (Best case) An icon that can be found in the current theme + "video-single-display-symbolic", // An icon that can be found in the parent theme + "firefox", // An icon that can be found in the hicolor default theme + "archlinux-logo", // An icon that resides in /usr/share/pixmap + "not-found", // (Worst case) An icon that does not exist ]; for arg in args { - group.bench_with_input(BenchmarkId::new("freedesktop-icons lookup", arg), arg, |b, arg| { - b.iter(|| lookup(arg) - .with_theme("Arc") - .find()); - }); + group.bench_with_input( + BenchmarkId::new("freedesktop-icons lookup", arg), + arg, + |b, arg| { + b.iter(|| lookup(arg).with_theme("Arc").find()); + }, + ); group.bench_with_input(BenchmarkId::new("lookup with cache", arg), arg, |b, arg| { - b.iter(|| lookup(arg) - .with_theme("Arc") - .with_cache() - .find()); + b.iter(|| lookup(arg).with_theme("Arc").with_cache().find()); }); group.bench_with_input(BenchmarkId::new("lookup linicon", arg), arg, |b, arg| { - b.iter(|| linicon::lookup_icon(arg) - .from_theme("Arc") - .next()); + b.iter(|| linicon::lookup_icon(arg).from_theme("Arc").next()); }); group.bench_with_input(BenchmarkId::new("lookup gtk", arg), arg, |b, arg| { - gtk4::init().unwrap(); - let theme = IconTheme::new(); + gtk4::init().unwrap(); + let theme = IconTheme::new(); b.iter(|| { theme.lookup_icon( arg, diff --git a/src/lib.rs b/src/lib.rs index 876cbfe..7fa3115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -256,7 +256,27 @@ mod test { #[test] fn simple_lookup() { let firefox = lookup("firefox").find(); - assert_that!(firefox).is_some(); + + asserting!("Lookup with no parameters should return an existing icon") + .that(&firefox) + .is_some() + .is_equal_to(PathBuf::from( + "/usr/share/icons/hicolor/22x22/apps/firefox.png", + )); + } + + #[test] + fn should_fallback() { + let icon = lookup("video-single-display-symbolic") + .with_theme("Arc") + .find(); + + asserting!("Lookup for an icon in the Arc theme should find the icon in its parent") + .that(&icon) + .is_some() + .is_equal_to(PathBuf::from( + "/usr/share/icons/Adwaita/scalable/devices/video-single-display-symbolic.svg", + )); } #[test] @@ -273,18 +293,22 @@ mod test { .with_theme("Papirus") .find(); - assert_that!(wireshark).is_some().is_equal_to(lin_wireshark) + asserting!("Given the same input parameter, lookup should ouput be the same as linincon") + .that(&wireshark) + .is_some() + .is_equal_to(lin_wireshark); } #[test] - fn compare_to_linicon_in_pixmap() { + fn should_fallback_to_pixmaps_utlimately() { let archlinux_logo = lookup("archlinux-logo") .with_size(16) .with_scale(1) .with_theme("Papirus") .find(); - assert_that!(archlinux_logo) + asserting!("When lookup fail in theme, icon should be found in '/usr/share/pixmaps'") + .that(&archlinux_logo) .is_some() .is_equal_to(PathBuf::from("/usr/share/pixmaps/archlinux-logo.png")); }