Unit tests common to artists and albums
This commit is contained in:
parent
7cf77c74cc
commit
3f6364e376
@ -301,7 +301,7 @@ impl Display for ArtistId {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::core::testmod::FULL_COLLECTION;
|
||||
use crate::{collection::album::AlbumId, core::testmod::FULL_COLLECTION};
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -571,4 +571,59 @@ mod tests {
|
||||
let merged = left.clone().merge(right);
|
||||
assert_eq!(expected, merged);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "multiple secondaries unsupported")]
|
||||
fn merge_two_db_albums_to_one_lib_album() {
|
||||
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||
let mut right = left.clone();
|
||||
|
||||
let album = Album::new(AlbumId::new("Album"));
|
||||
|
||||
left.albums.push(album.clone());
|
||||
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||
|
||||
right.albums.push(album.clone());
|
||||
right.albums.push(album.clone());
|
||||
|
||||
left.merge(right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "multiple primaries unsupported")]
|
||||
fn merge_one_db_album_to_two_lib_albums() {
|
||||
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||
let mut right = left.clone();
|
||||
|
||||
let album = Album::new(AlbumId::new("Album"));
|
||||
|
||||
left.albums.push(album.clone());
|
||||
left.albums.push(album.clone());
|
||||
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||
left.albums[1].meta.id.lib_id = AlbumLibId::Value(2);
|
||||
|
||||
right.albums.push(album.clone());
|
||||
|
||||
left.merge(right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_normalized_album_titles() {
|
||||
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||
let mut right = left.clone();
|
||||
|
||||
left.albums.push(Album::new(AlbumId::new("Album‐Title ‘Title’")));
|
||||
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||
|
||||
right.albums.push(Album::new(AlbumId::new("alBum—tiTle 'title’")));
|
||||
right.albums.push(Album::new(AlbumId::new("Album‐Title “Title”")));
|
||||
|
||||
// The first album will be merged, the second will be added.
|
||||
let mut expected = left.clone();
|
||||
expected.albums.push(right.albums.last().unwrap().clone());
|
||||
expected.albums.sort_unstable();
|
||||
|
||||
let merged = left.merge(right);
|
||||
assert_eq!(expected, merged);
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ impl MergeCollections {
|
||||
Some(mut primary_items) => {
|
||||
// We do not support merging multiple items with same name yet. Support will be
|
||||
// added once encountered in the wild.
|
||||
assert_eq!(primary_items.len(), 1);
|
||||
assert_eq!(secondary_items.len(), 1);
|
||||
assert_eq!(primary_items.len(), 1, "multiple primaries unsupported");
|
||||
assert_eq!(secondary_items.len(), 1, "multiple secondaries unsupported");
|
||||
let mut primary_item = primary_items.pop().unwrap();
|
||||
primary_item.merge_in_place(secondary_items.pop().unwrap());
|
||||
merged.push(primary_item);
|
||||
|
@ -223,4 +223,72 @@ mod tests {
|
||||
mh.collection = mh.merge_collections();
|
||||
assert_eq!(expected, mh.collection);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "multiple secondaries unsupported")]
|
||||
fn merge_two_db_artists_to_one_lib_artist() {
|
||||
let mut left = Collection::new();
|
||||
let mut right = Collection::new();
|
||||
|
||||
let artist = Artist::new(ArtistId::new("Artist"));
|
||||
|
||||
left.push(artist.clone());
|
||||
right.push(artist.clone());
|
||||
right.push(artist.clone());
|
||||
|
||||
let mut mh = MusicHoard {
|
||||
library_cache: left.clone(),
|
||||
database_cache: right.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
mh.collection = mh.merge_collections();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "multiple primaries unsupported")]
|
||||
fn merge_one_db_artist_to_two_lib_artists() {
|
||||
let mut left = Collection::new();
|
||||
let mut right = Collection::new();
|
||||
|
||||
let artist = Artist::new(ArtistId::new("Artist"));
|
||||
|
||||
left.push(artist.clone());
|
||||
left.push(artist.clone());
|
||||
right.push(artist.clone());
|
||||
|
||||
let mut mh = MusicHoard {
|
||||
library_cache: left.clone(),
|
||||
database_cache: right.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
mh.collection = mh.merge_collections();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_normalized_artist_names() {
|
||||
let mut left = Collection::new();
|
||||
let mut right = Collection::new();
|
||||
|
||||
left.push(Artist::new(ArtistId::new("Artist‐Name ‘Name’")));
|
||||
|
||||
right.push(Artist::new(ArtistId::new("arTist—naMe 'name’")));
|
||||
right.push(Artist::new(ArtistId::new("Artist‐Name “Name”")));
|
||||
|
||||
// The first artist will be merged, the second will be added.
|
||||
let mut expected = left.clone();
|
||||
expected.push(right.last().unwrap().clone());
|
||||
expected.sort_unstable();
|
||||
|
||||
let mut mh = MusicHoard {
|
||||
library_cache: left.clone(),
|
||||
database_cache: right.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
mh.collection = mh.merge_collections();
|
||||
assert_eq!(expected, mh.collection);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user