diff --git a/src/utils.rs b/src/utils.rs index 84cab96..7e81b37 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -26,6 +26,7 @@ pub fn get_cache_root() -> Result { Err(PError::CacheDirectoryError) } +#[derive(Debug, PartialEq)] pub enum AudioFormat { FLAC, MP3, @@ -53,10 +54,22 @@ pub fn get_audio_format(path: &Path) -> Option { } } +#[test] +fn test_get_audio_format() { + assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")), None); + assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.flac")), Some(AudioFormat::FLAC)); +} + pub fn is_song(path: &Path) -> bool { get_audio_format(path).is_some() } +#[test] +fn test_is_song() { + assert!(is_song(Path::new("animals/🐷/my🐖file.mp3"))); + assert!(!is_song(Path::new("animals/🐷/my🐖file.jpg"))); +} + pub fn is_image(path: &Path) -> bool { let extension = match path.extension() { Some(e) => e, @@ -75,3 +88,9 @@ pub fn is_image(path: &Path) -> bool { _ => false, } } + +#[test] +fn test_is_image() { + assert!(!is_image(Path::new("animals/🐷/my🐖file.mp3"))); + assert!(is_image(Path::new("animals/🐷/my🐖file.jpg"))); +}