Reproduce #108 in a unit test
This commit is contained in:
parent
3109e576e3
commit
183992ac7f
28
src/lib.rs
28
src/lib.rs
@ -1975,6 +1975,34 @@ mod tests {
|
|||||||
assert_eq!(expected, merged);
|
assert_eq!(expected, merged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_collection_incompatible_sorting() {
|
||||||
|
// It may be that the same artist in one collection has a "sort" field defined while the
|
||||||
|
// same artist in the other collection does not. This means that the two collections are not
|
||||||
|
// 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 COLLECTION and giving it a
|
||||||
|
// sorting name that would place it in the beginning.
|
||||||
|
let left = COLLECTION.to_owned();
|
||||||
|
let mut right: Vec<Artist> = vec![left.last().unwrap().clone()];
|
||||||
|
|
||||||
|
assert!(right.first().unwrap() > left.first().unwrap());
|
||||||
|
let artist_sort = Some(ArtistId::new("album_artist 0"));
|
||||||
|
right[0].sort = artist_sort.clone();
|
||||||
|
assert!(right.first().unwrap() < left.first().unwrap());
|
||||||
|
|
||||||
|
// The result of the merge should be the same list of artists, but with the last artist now
|
||||||
|
// in first place.
|
||||||
|
let mut expected = left.to_owned();
|
||||||
|
expected.last_mut().map(|a| a.sort = artist_sort.clone());
|
||||||
|
expected.rotate_right(1);
|
||||||
|
|
||||||
|
let merged = MusicHoard::<NoLibrary, NoDatabase>::merge(left.clone(), right);
|
||||||
|
assert_eq!(expected.len(), merged.len());
|
||||||
|
assert_eq!(expected, merged);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rescan_library_ordered() {
|
fn rescan_library_ordered() {
|
||||||
let mut library = MockILibrary::new();
|
let mut library = MockILibrary::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user