Split lib.rs into smaller files #115
@ -101,6 +101,13 @@ macro_rules! music_hoard_multi_url_dispatch {
|
||||
};
|
||||
}
|
||||
|
||||
impl Default for MusicHoard<NoLibrary, NoDatabase> {
|
||||
/// Create a new [`MusicHoard`] without any library or database.
|
||||
fn default() -> Self {
|
||||
MusicHoard::new(NoLibrary, NoDatabase)
|
||||
}
|
||||
}
|
||||
|
||||
impl<LIB, DB> MusicHoard<LIB, DB> {
|
||||
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and [`IDatabase`].
|
||||
pub fn new(library: LIB, database: DB) -> Self {
|
||||
@ -335,7 +342,6 @@ mod tests {
|
||||
track::Format,
|
||||
Merge,
|
||||
};
|
||||
use crate::core::musichoard::musichoard_builder::MusicHoardBuilder;
|
||||
use crate::core::musichoard::testmod::{FULL_COLLECTION, LIBRARY_COLLECTION};
|
||||
use crate::database::{self, MockIDatabase};
|
||||
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
||||
@ -379,7 +385,7 @@ mod tests {
|
||||
fn artist_new_delete() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
let mut expected: Vec<Artist> = vec![];
|
||||
|
||||
@ -400,7 +406,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn artist_sort_set_clear() {
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
let artist_1_id = ArtistId::new("the artist");
|
||||
let artist_1_sort = ArtistId::new("artist, the");
|
||||
@ -448,7 +454,7 @@ mod tests {
|
||||
#[test]
|
||||
fn collection_error() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
let actual_err = music_hoard
|
||||
.add_musicbrainz_url(&artist_id, QOBUZ)
|
||||
@ -463,7 +469,7 @@ mod tests {
|
||||
fn add_remove_musicbrainz_url() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -534,7 +540,7 @@ mod tests {
|
||||
fn set_clear_musicbrainz_url() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -589,7 +595,7 @@ mod tests {
|
||||
fn add_remove_musicbutler_urls() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -719,7 +725,7 @@ mod tests {
|
||||
fn set_clear_musicbutler_urls() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -782,7 +788,7 @@ mod tests {
|
||||
fn add_remove_bandcamp_urls() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -912,7 +918,7 @@ mod tests {
|
||||
fn set_clear_bandcamp_urls() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -975,7 +981,7 @@ mod tests {
|
||||
fn add_remove_qobuz_url() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -1026,7 +1032,7 @@ mod tests {
|
||||
fn set_clear_qobuz_url() {
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoardBuilder::default().build();
|
||||
let mut music_hoard = MusicHoard::default();
|
||||
|
||||
music_hoard.add_artist(artist_id.clone());
|
||||
|
||||
@ -1233,8 +1239,8 @@ mod tests {
|
||||
// sorted consistently. If the merge assumes they are sorted consistently this will lead to
|
||||
// the same artist appearing twice in the final list. This should not be the case.
|
||||
|
||||
// We will mimic this situation by taking the last artist from FULL_COLLECTION and giving it a
|
||||
// sorting name that would place it in the beginning.
|
||||
// We will mimic this situation by taking the last artist from FULL_COLLECTION and giving it
|
||||
// a sorting name that would place it in the beginning.
|
||||
let left = FULL_COLLECTION.to_owned();
|
||||
let mut right: Vec<Artist> = vec![left.last().unwrap().clone()];
|
||||
|
||||
@ -1286,10 +1292,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
music_hoard.rescan_library().unwrap();
|
||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||
@ -1313,10 +1316,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
music_hoard.rescan_library().unwrap();
|
||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||
@ -1350,10 +1350,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
music_hoard.rescan_library().unwrap();
|
||||
assert_eq!(music_hoard.get_collection(), &expected);
|
||||
@ -1386,10 +1383,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
assert!(music_hoard.rescan_library().is_err());
|
||||
}
|
||||
@ -1404,10 +1398,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|| Ok(FULL_COLLECTION.to_owned()));
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
music_hoard.load_from_database().unwrap();
|
||||
assert_eq!(music_hoard.get_collection(), &*FULL_COLLECTION);
|
||||
@ -1436,10 +1427,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_: &Collection| database_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
music_hoard.rescan_library().unwrap();
|
||||
assert_eq!(music_hoard.get_collection(), &*LIBRARY_COLLECTION);
|
||||
@ -1458,10 +1446,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
let actual_err = music_hoard.rescan_library().unwrap_err();
|
||||
let expected_err =
|
||||
@ -1483,10 +1468,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|| database_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
let actual_err = music_hoard.load_from_database().unwrap_err();
|
||||
let expected_err = Error::DatabaseError(
|
||||
@ -1509,10 +1491,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_: &Collection| database_result);
|
||||
|
||||
let mut music_hoard = MusicHoardBuilder::default()
|
||||
.set_library(library)
|
||||
.set_database(database)
|
||||
.build();
|
||||
let mut music_hoard = MusicHoard::new(library, database);
|
||||
|
||||
let actual_err = music_hoard.save_to_database().unwrap_err();
|
||||
let expected_err = Error::DatabaseError(
|
||||
|
@ -48,3 +48,44 @@ impl<LIB, DB> MusicHoardBuilder<LIB, DB> {
|
||||
MusicHoard::new(self.library, self.database)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::database::NullDatabase;
|
||||
use crate::library::NullLibrary;
|
||||
|
||||
#[test]
|
||||
fn no_library_no_database() {
|
||||
MusicHoardBuilder::default();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_library_no_database() {
|
||||
let mut mh = MusicHoardBuilder::default()
|
||||
.set_library(NullLibrary)
|
||||
.build();
|
||||
assert!(mh.rescan_library().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_library_with_database() {
|
||||
let mut mh = MusicHoardBuilder::default()
|
||||
.set_database(NullDatabase)
|
||||
.build();
|
||||
assert!(mh.load_from_database().is_ok());
|
||||
assert!(mh.save_to_database().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_library_with_database() {
|
||||
let mut mh = MusicHoardBuilder::default()
|
||||
.set_library(NullLibrary)
|
||||
.set_database(NullDatabase)
|
||||
.build();
|
||||
assert!(mh.rescan_library().is_ok());
|
||||
assert!(mh.load_from_database().is_ok());
|
||||
assert!(mh.save_to_database().is_ok());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user