test: improve tests and fmt all

This commit is contained in:
Paul Delafosse 2022-05-13 08:01:21 +02:00
parent 73702f6049
commit b7c9865412
2 changed files with 47 additions and 29 deletions

View file

@ -3,12 +3,9 @@ use freedesktop_icons::lookup;
use gtk4::{IconLookupFlags, IconTheme, TextDirection}; use gtk4::{IconLookupFlags, IconTheme, TextDirection};
pub fn simple_bench(c: &mut Criterion) { pub fn simple_bench(c: &mut Criterion) {
c.bench_function("firefox lookup", |b| b.iter(|| c.bench_function("firefox lookup", |b| {
lookup("firefox") b.iter(|| lookup("firefox").with_theme("Papirus").with_cache().find())
.with_theme("Papirus") });
.with_cache()
.find()
));
} }
pub fn bench_lookups(c: &mut Criterion) { pub fn bench_lookups(c: &mut Criterion) {
@ -23,23 +20,20 @@ pub fn bench_lookups(c: &mut Criterion) {
]; ];
for arg in args { for arg in args {
group.bench_with_input(BenchmarkId::new("freedesktop-icons lookup", arg), arg, |b, arg| { group.bench_with_input(
b.iter(|| lookup(arg) BenchmarkId::new("freedesktop-icons lookup", arg),
.with_theme("Arc") arg,
.find()); |b, arg| {
}); b.iter(|| lookup(arg).with_theme("Arc").find());
},
);
group.bench_with_input(BenchmarkId::new("lookup with cache", arg), arg, |b, arg| { group.bench_with_input(BenchmarkId::new("lookup with cache", arg), arg, |b, arg| {
b.iter(|| lookup(arg) b.iter(|| lookup(arg).with_theme("Arc").with_cache().find());
.with_theme("Arc")
.with_cache()
.find());
}); });
group.bench_with_input(BenchmarkId::new("lookup linicon", arg), arg, |b, arg| { group.bench_with_input(BenchmarkId::new("lookup linicon", arg), arg, |b, arg| {
b.iter(|| linicon::lookup_icon(arg) b.iter(|| linicon::lookup_icon(arg).from_theme("Arc").next());
.from_theme("Arc")
.next());
}); });
group.bench_with_input(BenchmarkId::new("lookup gtk", arg), arg, |b, arg| { group.bench_with_input(BenchmarkId::new("lookup gtk", arg), arg, |b, arg| {

View file

@ -256,7 +256,27 @@ mod test {
#[test] #[test]
fn simple_lookup() { fn simple_lookup() {
let firefox = lookup("firefox").find(); 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] #[test]
@ -273,18 +293,22 @@ mod test {
.with_theme("Papirus") .with_theme("Papirus")
.find(); .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] #[test]
fn compare_to_linicon_in_pixmap() { fn should_fallback_to_pixmaps_utlimately() {
let archlinux_logo = lookup("archlinux-logo") let archlinux_logo = lookup("archlinux-logo")
.with_size(16) .with_size(16)
.with_scale(1) .with_scale(1)
.with_theme("Papirus") .with_theme("Papirus")
.find(); .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_some()
.is_equal_to(PathBuf::from("/usr/share/pixmaps/archlinux-logo.png")); .is_equal_to(PathBuf::from("/usr/share/pixmaps/archlinux-logo.png"));
} }