fix: French album types, add map_album type test
This commit is contained in:
parent
57abab112f
commit
6e2ba71f33
4 changed files with 38 additions and 7 deletions
|
|
@ -630,7 +630,29 @@ pub(crate) fn map_artists(artists_p: Option<TextComponents>) -> (Vec<ArtistId>,
|
|||
pub(crate) fn map_album_type(txt: &str, lang: Language) -> AlbumType {
|
||||
dictionary::entry(lang)
|
||||
.album_types
|
||||
.get(&txt.to_lowercase())
|
||||
.get(txt.to_lowercase().trim())
|
||||
.copied()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map_album_type_samples() {
|
||||
let json_path = Path::new("testfiles/dict/album_type_samples.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let atype_samples: BTreeMap<Language, BTreeMap<AlbumType, String>> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
||||
atype_samples.iter().for_each(|(lang, entry)| {
|
||||
entry.iter().for_each(|(album_type, txt)| {
|
||||
let res = map_album_type(txt, *lang);
|
||||
assert_eq!(res, *album_type, "lang: {}, txt: {}", lang, txt);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1886,15 +1886,18 @@ pub(crate) fn entry(lang: Language) -> Entry {
|
|||
],
|
||||
},
|
||||
album_types: ::phf::Map {
|
||||
key: 2980949210194914378,
|
||||
key: 12913932095322966823,
|
||||
disps: &[
|
||||
(2, 0),
|
||||
(0, 0),
|
||||
(5, 0),
|
||||
],
|
||||
entries: &[
|
||||
("microalbum", AlbumType::Ep),
|
||||
("album", AlbumType::Album),
|
||||
("émission", AlbumType::Show),
|
||||
("ep", AlbumType::Ep),
|
||||
("livre audio", AlbumType::Audiobook),
|
||||
("émission", AlbumType::Show),
|
||||
("simple", AlbumType::Single),
|
||||
("ep", AlbumType::Ep),
|
||||
("single", AlbumType::Single),
|
||||
],
|
||||
},
|
||||
|
|
|
|||
Reference in a new issue