From e136103eade0b55d9da22d3220968ab213f3ea00 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 4 Jan 2025 22:23:34 +0100 Subject: [PATCH] Complete coverage --- src/core/musichoard/base.rs | 34 +++++++++++++++++++++++++++++++++- src/core/musichoard/filter.rs | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/core/musichoard/base.rs b/src/core/musichoard/base.rs index db8f910..1ec0534 100644 --- a/src/core/musichoard/base.rs +++ b/src/core/musichoard/base.rs @@ -148,7 +148,14 @@ impl IMusicHoardBasePrivate for MusicHoard #[cfg(test)] mod tests { - use crate::core::testmod::FULL_COLLECTION; + use crate::{ + collection::{ + album::{AlbumMeta, AlbumPrimaryType}, + artist::ArtistMeta, + }, + core::testmod::FULL_COLLECTION, + filter::AlbumField, + }; use super::*; @@ -321,4 +328,29 @@ mod tests { mh.collection = mh.merge_collections(); assert_eq!(expected, mh.collection); } + + #[test] + fn filtered() { + let mut mh = MusicHoard::default(); + mh.collection = vec![Artist { + meta: ArtistMeta::new(ArtistId::new("Artist")), + albums: vec![ + Album::new(AlbumId::new("Album 1")), + Album::new(AlbumId::new("Album 2")), + ], + }]; + mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Ep); + mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Album); + + mh.set_filter(CollectionFilter { + include: vec![vec![AlbumField::PrimaryType(Some(AlbumPrimaryType::Album))]], + except: vec![], + }); + + assert_eq!(mh.get_collection().len(), 1); + assert_eq!(mh.get_filtered().len(), 1); + + assert_eq!(mh.get_collection()[0].albums.len(), 2); + assert_eq!(mh.get_filtered()[0].albums.len(), 1); + } } diff --git a/src/core/musichoard/filter.rs b/src/core/musichoard/filter.rs index 5452d58..8e9f21e 100644 --- a/src/core/musichoard/filter.rs +++ b/src/core/musichoard/filter.rs @@ -58,7 +58,7 @@ mod tests { use super::*; - fn test_filter() -> CollectionFilter { + pub fn test_filter() -> CollectionFilter { CollectionFilter { include: vec![vec![ AlbumField::PrimaryType(None),