diff --git a/src/lib.rs b/src/lib.rs index a782173..3f4f20c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1975,6 +1975,34 @@ mod tests { 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 = 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::::merge(left.clone(), right); + assert_eq!(expected.len(), merged.len()); + assert_eq!(expected, merged); + } + #[test] fn rescan_library_ordered() { let mut library = MockILibrary::new();