use unicode_normalization::UnicodeNormalization as _;
pub(crate) fn canonical_path_key(path: &str) -> String {
path.nfc().flat_map(char::to_lowercase).collect()
}
pub(crate) fn same_fs_path(a: &str, b: &str) -> bool {
canonical_path_key(a) == canonical_path_key(b)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn case_only_difference_is_the_same_key() {
assert_eq!(
canonical_path_key("Creator/Song.flac"),
canonical_path_key("creator/song.flac")
);
assert!(same_fs_path("Creator/Song.flac", "creator/song.flac"));
}
#[test]
fn nfc_and_nfd_encodings_share_a_key() {
assert!(same_fs_path("\u{00e9}toile.mp3", "e\u{0301}toile.mp3"));
}
#[test]
fn distinct_paths_do_not_alias() {
assert!(!same_fs_path("Creator/Alpha.flac", "Creator/Beta.flac"));
}
#[test]
fn empty_paths_are_equal_and_do_not_panic() {
assert!(same_fs_path("", ""));
assert_eq!(canonical_path_key(""), "");
}
}