From 25a13601fd7f05a342fac00cd2a248caa02b28c3 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 13 Jan 2024 14:41:27 +0100 Subject: [PATCH] Fix old unit tests --- src/database/json/mod.rs | 34 ++- src/lib.rs | 56 ++--- src/library/beets/mod.rs | 6 +- src/tui/ui.rs | 15 +- tests/files/database/database.json | 2 +- tests/files/library/library.db | Bin 69632 -> 69632 bytes tests/library/beets.rs | 6 +- tests/testlib.rs | 372 +++++++++++++++-------------- 8 files changed, 251 insertions(+), 240 deletions(-) diff --git a/src/database/json/mod.rs b/src/database/json/mod.rs index 08b8441..477d08d 100644 --- a/src/database/json/mod.rs +++ b/src/database/json/mod.rs @@ -65,26 +65,28 @@ mod tests { use super::*; - use crate::{tests::COLLECTION, Artist, ArtistId, Collection, Format, IUrl}; + use crate::{tests::COLLECTION, Artist, ArtistId, Collection, Format}; - fn opt_to_url(opt: &Option) -> String { + fn opt_to_str>(opt: &Option) -> String { match opt { - Some(mb) => format!("\"{}\"", mb.url()), + Some(val) => format!("\"{}\"", val.as_ref()), None => String::from("null"), } } - fn vec_to_urls(vec: &[U]) -> String { + fn vec_to_str>(vec: &[S]) -> String { let mut urls: Vec = vec![]; for item in vec.iter() { - urls.push(format!("\"{}\"", item.url())); + urls.push(format!("\"{}\"", item.as_ref())); } format!("[{}]", urls.join(",")) } - fn artist_to_json(artist: &Artist) -> String { - let album_artist = &artist.id.name; + fn artist_id_to_str(id: &ArtistId) -> String { + format!("{{\"name\":\"{}\"}}", id.name) + } + fn artist_to_json(artist: &Artist) -> String { let mut albums: Vec = vec![]; for album in artist.albums.iter() { let album_year = album.id.year; @@ -127,10 +129,10 @@ mod tests { } let albums = albums.join(","); - let musicbrainz = opt_to_url(&artist.properties.musicbrainz); - let musicbutler = vec_to_urls(&artist.properties.musicbutler); - let bandcamp = vec_to_urls(&artist.properties.bandcamp); - let qobuz = opt_to_url(&artist.properties.qobuz); + let musicbrainz = opt_to_str(&artist.properties.musicbrainz); + let musicbutler = vec_to_str(&artist.properties.musicbutler); + let bandcamp = vec_to_str(&artist.properties.bandcamp); + let qobuz = opt_to_str(&artist.properties.qobuz); let properties = format!( "{{\ @@ -141,9 +143,17 @@ mod tests { }}" ); + let album_artist = artist_id_to_str(&artist.id); + let album_artist_sort = artist + .sort + .as_ref() + .map(artist_id_to_str) + .unwrap_or_else(|| "null".to_string()); + format!( "{{\ - \"id\":{{\"name\":\"{album_artist}\"}},\ + \"id\":{album_artist},\ + \"sort\":{album_artist_sort},\ \"properties\":{properties},\ \"albums\":[{albums}]\ }}" diff --git a/src/lib.rs b/src/lib.rs index 6cf7fef..4d3e27b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,11 +18,6 @@ use serde::{Deserialize, Serialize}; use url::Url; use uuid::Uuid; -/// An object with the [`IUrl`] trait contains a valid URL. -pub trait IUrl { - fn url(&self) -> &str; -} - /// An object with the [`IMbid`] trait contains a [MusicBrainz /// Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID). pub trait IMbid { @@ -83,6 +78,12 @@ impl MusicBrainz { } } +impl AsRef for MusicBrainz { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl TryFrom<&str> for MusicBrainz { type Error = Error; @@ -97,12 +98,6 @@ impl Display for MusicBrainz { } } -impl IUrl for MusicBrainz { - fn url(&self) -> &str { - self.0.as_str() - } -} - impl IMbid for MusicBrainz { fn mbid(&self) -> &str { // The URL is assumed to have been validated. @@ -142,6 +137,12 @@ impl MusicButler { } } +impl AsRef for MusicButler { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl TryFrom<&str> for MusicButler { type Error = Error; @@ -150,12 +151,6 @@ impl TryFrom<&str> for MusicButler { } } -impl IUrl for MusicButler { - fn url(&self) -> &str { - self.0.as_str() - } -} - /// Bandcamp reference. #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] pub struct Bandcamp(Url); @@ -188,6 +183,12 @@ impl Bandcamp { } } +impl AsRef for Bandcamp { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl TryFrom<&str> for Bandcamp { type Error = Error; @@ -196,12 +197,6 @@ impl TryFrom<&str> for Bandcamp { } } -impl IUrl for Bandcamp { - fn url(&self) -> &str { - self.0.as_str() - } -} - /// Qobuz reference. #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] pub struct Qobuz(Url); @@ -230,6 +225,12 @@ impl Qobuz { } } +impl AsRef for Qobuz { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl TryFrom<&str> for Qobuz { type Error = Error; @@ -244,12 +245,6 @@ impl Display for Qobuz { } } -impl IUrl for Qobuz { - fn url(&self) -> &str { - self.0.as_str() - } -} - /// The track file format. #[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] pub enum Format { @@ -582,6 +577,7 @@ impl Ord for Artist { impl Merge for Artist { fn merge(mut self, other: Self) -> Self { assert_eq!(self.id, other.id); + self.sort = Self::merge_opts(self.sort, other.sort); self.properties = self.properties.merge(other.properties); self.albums = MergeSorted::new(self.albums.into_iter(), other.albums.into_iter()).collect(); self @@ -1126,7 +1122,7 @@ mod tests { let uuid = "d368baa8-21ca-4759-9731-0b2753071ad8"; let url = format!("https://musicbrainz.org/artist/{uuid}"); let mb = MusicBrainz::new(&url).unwrap(); - assert_eq!(url, mb.url()); + assert_eq!(url, mb.as_ref()); assert_eq!(uuid, mb.mbid()); let url = "not a url at all".to_string(); diff --git a/src/library/beets/mod.rs b/src/library/beets/mod.rs index 699c630..3100119 100644 --- a/src/library/beets/mod.rs +++ b/src/library/beets/mod.rs @@ -126,7 +126,7 @@ impl ILibraryPrivate for BeetsLibrary { } let split: Vec<&str> = line.split(LIST_FORMAT_SEPARATOR).collect(); - if split.len() != 8 { + if split.len() != 9 { return Err(Error::Invalid(line.to_string())); } @@ -363,8 +363,8 @@ mod tests { .split(LIST_FORMAT_SEPARATOR) .map(|s| s.to_owned()) .collect::>(); - invalid_string[6].clear(); - invalid_string[6].push_str("invalid format"); + invalid_string[7].clear(); + invalid_string[7].push_str("invalid format"); let invalid_string = invalid_string.join(LIST_FORMAT_SEPARATOR); output[2] = invalid_string.clone(); let result = Ok(output); diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 8ca4b23..f9f0382 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -1,6 +1,6 @@ use std::fmt; -use musichoard::{Album, Artist, Collection, Format, IUrl, Track}; +use musichoard::{Album, Artist, Collection, Format, Track}; use ratatui::{ backend::Backend, layout::{Alignment, Rect}, @@ -409,20 +409,23 @@ struct ArtistOverlay<'a> { } impl<'a> ArtistOverlay<'a> { - fn opt_opt_to_str(opt: Option>) -> &str { - opt.flatten().map(|item| item.url()).unwrap_or("") + fn opt_opt_to_str>(opt: Option>) -> &str { + opt.flatten().map(|item| item.as_ref()).unwrap_or("") } - fn opt_vec_to_string(opt_vec: Option<&Vec>, indent: &str) -> String { + fn opt_vec_to_string>(opt_vec: Option<&Vec>, indent: &str) -> String { opt_vec .map(|vec| { if vec.len() < 2 { - vec.first().map(|item| item.url()).unwrap_or("").to_string() + vec.first() + .map(|item| item.as_ref()) + .unwrap_or("") + .to_string() } else { let indent = format!("\n{indent}"); let list = vec .iter() - .map(|item| item.url()) + .map(|item| item.as_ref()) .collect::>() .join(&indent); format!("{indent}{list}") diff --git a/tests/files/database/database.json b/tests/files/database/database.json index 7647746..9c51a67 100644 --- a/tests/files/database/database.json +++ b/tests/files/database/database.json @@ -1 +1 @@ -[{"id":{"name":"Аркона"},"sort":{"name":"Arkona"},"properties":{"musicbrainz":"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212","musicbutler":["https://www.musicbutler.io/artist-page/283448581"],"bandcamp":["https://arkonamoscow.bandcamp.com/"],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"},"albums":[{"id":{"year":2011,"title":"Slovo"},"tracks":[{"id":{"number":1,"title":"Az’"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":992}},{"id":{"number":2,"title":"Arkaim"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1061}},{"id":{"number":3,"title":"Bol’no mne"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1004}},{"id":{"number":4,"title":"Leshiy"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1077}},{"id":{"number":5,"title":"Zakliatie"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1041}},{"id":{"number":6,"title":"Predok"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":756}},{"id":{"number":7,"title":"Nikogda"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1059}},{"id":{"number":8,"title":"Tam za tumanami"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1023}},{"id":{"number":9,"title":"Potomok"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":838}},{"id":{"number":10,"title":"Slovo"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1028}},{"id":{"number":11,"title":"Odna"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":991}},{"id":{"number":12,"title":"Vo moiom sadochke…"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":919}},{"id":{"number":13,"title":"Stenka na stenku"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1039}},{"id":{"number":14,"title":"Zimushka"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":974}}]}]},{"id":{"name":"Eluveitie"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38","musicbutler":["https://www.musicbutler.io/artist-page/269358403"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"},"albums":[{"id":{"year":2004,"title":"Vên [re‐recorded]"},"tracks":[{"id":{"number":1,"title":"Verja Urit an Bitus"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":961}},{"id":{"number":2,"title":"Uis Elveti"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1067}},{"id":{"number":3,"title":"Ôrô"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":933}},{"id":{"number":4,"title":"Lament"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1083}},{"id":{"number":5,"title":"Druid"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1073}},{"id":{"number":6,"title":"Jêzaïg"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1002}}]},{"id":{"year":2008,"title":"Slania"},"tracks":[{"id":{"number":1,"title":"Samon"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":953}},{"id":{"number":2,"title":"Primordial Breath"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1103}},{"id":{"number":3,"title":"Inis Mona"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1117}},{"id":{"number":4,"title":"Gray Sublime Archon"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1092}},{"id":{"number":5,"title":"Anagantios"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":923}},{"id":{"number":6,"title":"Bloodstained Ground"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"id":{"number":7,"title":"The Somber Lay"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1068}},{"id":{"number":8,"title":"Slanias Song"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"id":{"number":9,"title":"Giamonios"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":825}},{"id":{"number":10,"title":"Tarvos"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1115}},{"id":{"number":11,"title":"Calling the Rain"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1096}},{"id":{"number":12,"title":"Elembivos"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1059}}]}]},{"id":{"name":"Frontside"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490","musicbutler":["https://www.musicbutler.io/artist-page/826588800"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"},"albums":[{"id":{"year":2001,"title":"…nasze jest królestwo, potęga i chwała na wieki…"},"tracks":[{"id":{"number":1,"title":"Intro = Chaos"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1024}},{"id":{"number":2,"title":"Modlitwa"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1073}},{"id":{"number":3,"title":"Długa droga z piekła"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1058}},{"id":{"number":4,"title":"Synowie ognia"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1066}},{"id":{"number":5,"title":"1902"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1074}},{"id":{"number":6,"title":"Krew za krew"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1080}},{"id":{"number":7,"title":"Kulminacja"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":992}},{"id":{"number":8,"title":"Judasz"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1018}},{"id":{"number":9,"title":"Więzy"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1077}},{"id":{"number":10,"title":"Zagubione dusze"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1033}},{"id":{"number":11,"title":"Linia życia"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":987}}]}]},{"id":{"name":"Heaven’s Basement"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc","musicbutler":["https://www.musicbutler.io/artist-page/291158685"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"},"albums":[{"id":{"year":2011,"title":"Paper Plague"},"tracks":[{"id":{"number":0,"title":"Paper Plague"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":320}}]},{"id":{"year":2011,"title":"Unbreakable"},"tracks":[{"id":{"number":1,"title":"Unbreakable"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":208}},{"id":{"number":2,"title":"Guilt Trips and Sins"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":205}},{"id":{"number":3,"title":"The Long Goodbye"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":227}},{"id":{"number":4,"title":"Close Encounters"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":213}},{"id":{"number":5,"title":"Paranoia"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":218}},{"id":{"number":6,"title":"Let Me Out of Here"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":207}},{"id":{"number":7,"title":"Leeches"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":225}}]}]},{"id":{"name":"Metallica"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab","musicbutler":["https://www.musicbutler.io/artist-page/3996865"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"},"albums":[{"id":{"year":1984,"title":"Ride the Lightning"},"tracks":[{"id":{"number":1,"title":"Fight Fire with Fire"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":954}},{"id":{"number":2,"title":"Ride the Lightning"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":951}},{"id":{"number":3,"title":"For Whom the Bell Tolls"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":889}},{"id":{"number":4,"title":"Fade to Black"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":939}},{"id":{"number":5,"title":"Trapped under Ice"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":955}},{"id":{"number":6,"title":"Escape"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":941}},{"id":{"number":7,"title":"Creeping Death"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":958}},{"id":{"number":8,"title":"The Call of Ktulu"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":888}}]},{"id":{"year":1999,"title":"S&M"},"tracks":[{"id":{"number":1,"title":"The Ecstasy of Gold"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"id":{"number":2,"title":"The Call of Ktulu"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1030}},{"id":{"number":3,"title":"Master of Puppets"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"id":{"number":4,"title":"Of Wolf and Man"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1115}},{"id":{"number":5,"title":"The Thing That Should Not Be"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"id":{"number":6,"title":"Fuel"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1057}},{"id":{"number":7,"title":"The Memory Remains"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1080}},{"id":{"number":8,"title":"No Leaf Clover"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1004}},{"id":{"number":9,"title":"Hero of the Day"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":962}},{"id":{"number":10,"title":"Devil’s Dance"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1076}},{"id":{"number":11,"title":"Bleeding Me"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"id":{"number":12,"title":"Nothing Else Matters"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"id":{"number":13,"title":"Until It Sleeps"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1038}},{"id":{"number":14,"title":"For Whom the Bell Tolls"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1072}},{"id":{"number":15,"title":"−Human"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"id":{"number":16,"title":"Wherever I May Roam"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1035}},{"id":{"number":17,"title":"Outlaw Torn"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1042}},{"id":{"number":18,"title":"Sad but True"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"id":{"number":19,"title":"One"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1017}},{"id":{"number":20,"title":"Enter Sandman"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"id":{"number":21,"title":"Battery"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":967}}]}]}] \ No newline at end of file +[{"id":{"name":"Аркона"},"sort":{"name":"Arkona"},"properties":{"musicbrainz":"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212","musicbutler":["https://www.musicbutler.io/artist-page/283448581"],"bandcamp":["https://arkonamoscow.bandcamp.com/"],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"},"albums":[{"id":{"year":2011,"title":"Slovo"},"tracks":[{"id":{"number":1,"title":"Az’"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":992}},{"id":{"number":2,"title":"Arkaim"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1061}},{"id":{"number":3,"title":"Bol’no mne"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1004}},{"id":{"number":4,"title":"Leshiy"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1077}},{"id":{"number":5,"title":"Zakliatie"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1041}},{"id":{"number":6,"title":"Predok"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":756}},{"id":{"number":7,"title":"Nikogda"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1059}},{"id":{"number":8,"title":"Tam za tumanami"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1023}},{"id":{"number":9,"title":"Potomok"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":838}},{"id":{"number":10,"title":"Slovo"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1028}},{"id":{"number":11,"title":"Odna"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":991}},{"id":{"number":12,"title":"Vo moiom sadochke…"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":919}},{"id":{"number":13,"title":"Stenka na stenku"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":1039}},{"id":{"number":14,"title":"Zimushka"},"artist":["Аркона"],"quality":{"format":"Flac","bitrate":974}}]}]},{"id":{"name":"Eluveitie"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38","musicbutler":["https://www.musicbutler.io/artist-page/269358403"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"},"albums":[{"id":{"year":2004,"title":"Vên [re‐recorded]"},"tracks":[{"id":{"number":1,"title":"Verja Urit an Bitus"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":961}},{"id":{"number":2,"title":"Uis Elveti"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1067}},{"id":{"number":3,"title":"Ôrô"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":933}},{"id":{"number":4,"title":"Lament"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1083}},{"id":{"number":5,"title":"Druid"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1073}},{"id":{"number":6,"title":"Jêzaïg"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1002}}]},{"id":{"year":2008,"title":"Slania"},"tracks":[{"id":{"number":1,"title":"Samon"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":953}},{"id":{"number":2,"title":"Primordial Breath"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1103}},{"id":{"number":3,"title":"Inis Mona"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1117}},{"id":{"number":4,"title":"Gray Sublime Archon"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1092}},{"id":{"number":5,"title":"Anagantios"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":923}},{"id":{"number":6,"title":"Bloodstained Ground"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"id":{"number":7,"title":"The Somber Lay"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1068}},{"id":{"number":8,"title":"Slanias Song"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"id":{"number":9,"title":"Giamonios"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":825}},{"id":{"number":10,"title":"Tarvos"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1115}},{"id":{"number":11,"title":"Calling the Rain"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1096}},{"id":{"number":12,"title":"Elembivos"},"artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1059}}]}]},{"id":{"name":"Frontside"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490","musicbutler":["https://www.musicbutler.io/artist-page/826588800"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"},"albums":[{"id":{"year":2001,"title":"…nasze jest królestwo, potęga i chwała na wieki…"},"tracks":[{"id":{"number":1,"title":"Intro = Chaos"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1024}},{"id":{"number":2,"title":"Modlitwa"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1073}},{"id":{"number":3,"title":"Długa droga z piekła"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1058}},{"id":{"number":4,"title":"Synowie ognia"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1066}},{"id":{"number":5,"title":"1902"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1074}},{"id":{"number":6,"title":"Krew za krew"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1080}},{"id":{"number":7,"title":"Kulminacja"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":992}},{"id":{"number":8,"title":"Judasz"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1018}},{"id":{"number":9,"title":"Więzy"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1077}},{"id":{"number":10,"title":"Zagubione dusze"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":1033}},{"id":{"number":11,"title":"Linia życia"},"artist":["Frontside"],"quality":{"format":"Flac","bitrate":987}}]}]},{"id":{"name":"Heaven’s Basement"},"sort":{"name":"Heaven’s Basement"},"properties":{"musicbrainz":"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc","musicbutler":["https://www.musicbutler.io/artist-page/291158685"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"},"albums":[{"id":{"year":2011,"title":"Paper Plague"},"tracks":[{"id":{"number":0,"title":"Paper Plague"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":320}}]},{"id":{"year":2011,"title":"Unbreakable"},"tracks":[{"id":{"number":1,"title":"Unbreakable"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":208}},{"id":{"number":2,"title":"Guilt Trips and Sins"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":205}},{"id":{"number":3,"title":"The Long Goodbye"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":227}},{"id":{"number":4,"title":"Close Encounters"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":213}},{"id":{"number":5,"title":"Paranoia"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":218}},{"id":{"number":6,"title":"Let Me Out of Here"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":207}},{"id":{"number":7,"title":"Leeches"},"artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":225}}]}]},{"id":{"name":"Metallica"},"sort":null,"properties":{"musicbrainz":"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab","musicbutler":["https://www.musicbutler.io/artist-page/3996865"],"bandcamp":[],"qobuz":"https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"},"albums":[{"id":{"year":1984,"title":"Ride the Lightning"},"tracks":[{"id":{"number":1,"title":"Fight Fire with Fire"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":954}},{"id":{"number":2,"title":"Ride the Lightning"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":951}},{"id":{"number":3,"title":"For Whom the Bell Tolls"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":889}},{"id":{"number":4,"title":"Fade to Black"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":939}},{"id":{"number":5,"title":"Trapped under Ice"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":955}},{"id":{"number":6,"title":"Escape"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":941}},{"id":{"number":7,"title":"Creeping Death"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":958}},{"id":{"number":8,"title":"The Call of Ktulu"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":888}}]},{"id":{"year":1999,"title":"S&M"},"tracks":[{"id":{"number":1,"title":"The Ecstasy of Gold"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"id":{"number":2,"title":"The Call of Ktulu"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1030}},{"id":{"number":3,"title":"Master of Puppets"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"id":{"number":4,"title":"Of Wolf and Man"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1115}},{"id":{"number":5,"title":"The Thing That Should Not Be"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"id":{"number":6,"title":"Fuel"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1057}},{"id":{"number":7,"title":"The Memory Remains"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1080}},{"id":{"number":8,"title":"No Leaf Clover"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1004}},{"id":{"number":9,"title":"Hero of the Day"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":962}},{"id":{"number":10,"title":"Devil’s Dance"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1076}},{"id":{"number":11,"title":"Bleeding Me"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"id":{"number":12,"title":"Nothing Else Matters"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"id":{"number":13,"title":"Until It Sleeps"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1038}},{"id":{"number":14,"title":"For Whom the Bell Tolls"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1072}},{"id":{"number":15,"title":"−Human"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"id":{"number":16,"title":"Wherever I May Roam"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1035}},{"id":{"number":17,"title":"Outlaw Torn"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1042}},{"id":{"number":18,"title":"Sad but True"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"id":{"number":19,"title":"One"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":1017}},{"id":{"number":20,"title":"Enter Sandman"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"id":{"number":21,"title":"Battery"},"artist":["Metallica"],"quality":{"format":"Flac","bitrate":967}}]}]}] \ No newline at end of file diff --git a/tests/files/library/library.db b/tests/files/library/library.db index c24c5414e8707ec85b8542e7f51d710b5bf9f14e..54665c5853dd46116d96483adc1a946fe6ee2983 100644 GIT binary patch delta 122 zcmV-=0EPd6pag)R1dtm650M;00S~cYroR|w01jdd+5u(@j0#Bz^ar~Jas@vG1Omgc zfk*)lf?6d{0D)=%B{MTKB{MUVo6A7~2$P|yJ(KXx6q7E@gOl&E6O*yb9T7p0EGX5pag)R1dtm64v`!~0S>WXroS3>01jdd+6#;dJ_!2VBm?mRwgGhk zC9#1B0h55RO$mZNEl&V}dI2w!4aBIkbi-x|4}wc2PXK{x03|asGbJ+(lXbyClO3^A dlL*3tlb*sI3}u;Jq(RwcSoTtyo3q-?CPS>sEFAy< diff --git a/tests/library/beets.rs b/tests/library/beets.rs index e216b75..656485b 100644 --- a/tests/library/beets.rs +++ b/tests/library/beets.rs @@ -108,7 +108,7 @@ fn test_album_artist_query() { .list(Query::new().include(Field::AlbumArtist(String::from("Аркона")))) .unwrap(); - let expected: Vec = artists_to_items(&COLLECTION[4..5]); + let expected: Vec = artists_to_items(&COLLECTION[0..1]); assert_eq!(output, expected); } @@ -121,7 +121,7 @@ fn test_album_title_query() { .list(Query::new().include(Field::AlbumTitle(String::from("Slovo")))) .unwrap(); - let expected: Vec = artists_to_items(&COLLECTION[4..5]); + let expected: Vec = artists_to_items(&COLLECTION[0..1]); assert_eq!(output, expected); } @@ -133,7 +133,7 @@ fn test_exclude_query() { let output = beets .list(Query::new().exclude(Field::AlbumArtist(String::from("Аркона")))) .unwrap(); - let expected: Vec = artists_to_items(&COLLECTION[..4]); + let expected: Vec = artists_to_items(&COLLECTION[1..]); let output: HashSet<_> = output.iter().collect(); let expected: HashSet<_> = expected.iter().collect(); diff --git a/tests/testlib.rs b/tests/testlib.rs index 1a1036f..8df1677 100644 --- a/tests/testlib.rs +++ b/tests/testlib.rs @@ -6,6 +6,190 @@ use once_cell::sync::Lazy; pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { vec![ + Artist { + id: ArtistId { + name: String::from("Аркона"), + }, + sort: Some(ArtistId{ + name: String::from("Arkona") + }), + properties: ArtistProperties { + musicbrainz: Some(MusicBrainz::new( + "https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212", + ).unwrap()), + musicbutler: vec![ + MusicButler::new("https://www.musicbutler.io/artist-page/283448581").unwrap(), + ], + bandcamp: vec![ + Bandcamp::new("https://arkonamoscow.bandcamp.com/").unwrap(), + ], + qobuz: Some(Qobuz::new( + "https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums", + ).unwrap()), + }, + albums: vec![Album { + id: AlbumId { + year: 2011, + title: String::from("Slovo"), + }, + tracks: vec![ + Track { + id: TrackId { + number: 1, + title: String::from("Az’"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 992, + }, + }, + Track { + id: TrackId { + number: 2, + title: String::from("Arkaim"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1061, + }, + }, + Track { + id: TrackId { + number: 3, + title: String::from("Bol’no mne"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1004, + }, + }, + Track { + id: TrackId { + number: 4, + title: String::from("Leshiy"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1077, + }, + }, + Track { + id: TrackId { + number: 5, + title: String::from("Zakliatie"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1041, + }, + }, + Track { + id: TrackId { + number: 6, + title: String::from("Predok"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 756, + }, + }, + Track { + id: TrackId { + number: 7, + title: String::from("Nikogda"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1059, + }, + }, + Track { + id: TrackId { + number: 8, + title: String::from("Tam za tumanami"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1023, + }, + }, + Track { + id: TrackId { + number: 9, + title: String::from("Potomok"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 838, + }, + }, + Track { + id: TrackId { + number: 10, + title: String::from("Slovo"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1028, + }, + }, + Track { + id: TrackId { + number: 11, + title: String::from("Odna"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 991, + }, + }, + Track { + id: TrackId { + number: 12, + title: String::from("Vo moiom sadochke…"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 919, + }, + }, + Track { + id: TrackId { + number: 13, + title: String::from("Stenka na stenku"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 1039, + }, + }, + Track { + id: TrackId { + number: 14, + title: String::from("Zimushka"), + }, + artist: vec![String::from("Аркона")], + quality: Quality { + format: Format::Flac, + bitrate: 974, + }, + }, + ], + }], + }, Artist { id: ArtistId { name: String::from("Eluveitie"), @@ -391,7 +575,9 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: ArtistId { name: String::from("Heaven’s Basement"), }, - sort: None, + sort: Some(ArtistId { + name: String::from("Heaven’s Basement"), + }), properties: ArtistProperties { musicbrainz: Some(MusicBrainz::new( "https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc", @@ -863,189 +1049,5 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { }, ], }, - Artist { - id: ArtistId { - name: String::from("Аркона"), - }, - sort: Some(ArtistId{ - name: String::from("Arkona") - }), - properties: ArtistProperties { - musicbrainz: Some(MusicBrainz::new( - "https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212", - ).unwrap()), - musicbutler: vec![ - MusicButler::new("https://www.musicbutler.io/artist-page/283448581").unwrap(), - ], - bandcamp: vec![ - Bandcamp::new("https://arkonamoscow.bandcamp.com/").unwrap(), - ], - qobuz: Some(Qobuz::new( - "https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums", - ).unwrap()), - }, - albums: vec![Album { - id: AlbumId { - year: 2011, - title: String::from("Slovo"), - }, - tracks: vec![ - Track { - id: TrackId { - number: 1, - title: String::from("Az’"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 992, - }, - }, - Track { - id: TrackId { - number: 2, - title: String::from("Arkaim"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1061, - }, - }, - Track { - id: TrackId { - number: 3, - title: String::from("Bol’no mne"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1004, - }, - }, - Track { - id: TrackId { - number: 4, - title: String::from("Leshiy"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1077, - }, - }, - Track { - id: TrackId { - number: 5, - title: String::from("Zakliatie"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1041, - }, - }, - Track { - id: TrackId { - number: 6, - title: String::from("Predok"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 756, - }, - }, - Track { - id: TrackId { - number: 7, - title: String::from("Nikogda"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1059, - }, - }, - Track { - id: TrackId { - number: 8, - title: String::from("Tam za tumanami"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1023, - }, - }, - Track { - id: TrackId { - number: 9, - title: String::from("Potomok"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 838, - }, - }, - Track { - id: TrackId { - number: 10, - title: String::from("Slovo"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1028, - }, - }, - Track { - id: TrackId { - number: 11, - title: String::from("Odna"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 991, - }, - }, - Track { - id: TrackId { - number: 12, - title: String::from("Vo moiom sadochke…"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 919, - }, - }, - Track { - id: TrackId { - number: 13, - title: String::from("Stenka na stenku"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 1039, - }, - }, - Track { - id: TrackId { - number: 14, - title: String::from("Zimushka"), - }, - artist: vec![String::from("Аркона")], - quality: Quality { - format: Format::Flac, - bitrate: 974, - }, - }, - ], - }], - }, ] });