mirror of
https://github.com/agersant/polaris
synced 2024-12-02 17:49:10 +00:00
Added unit tests to utils
This commit is contained in:
parent
2735ed9a03
commit
a16595a2e1
1 changed files with 19 additions and 0 deletions
19
src/utils.rs
19
src/utils.rs
|
@ -26,6 +26,7 @@ pub fn get_cache_root() -> Result<PathBuf, PError> {
|
||||||
Err(PError::CacheDirectoryError)
|
Err(PError::CacheDirectoryError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AudioFormat {
|
pub enum AudioFormat {
|
||||||
FLAC,
|
FLAC,
|
||||||
MP3,
|
MP3,
|
||||||
|
@ -53,10 +54,22 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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 {
|
pub fn is_song(path: &Path) -> bool {
|
||||||
get_audio_format(path).is_some()
|
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 {
|
pub fn is_image(path: &Path) -> bool {
|
||||||
let extension = match path.extension() {
|
let extension = match path.extension() {
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
|
@ -75,3 +88,9 @@ pub fn is_image(path: &Path) -> bool {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_image() {
|
||||||
|
assert!(!is_image(Path::new("animals/🐷/my🐖file.mp3")));
|
||||||
|
assert!(is_image(Path::new("animals/🐷/my🐖file.jpg")));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue