diff options
| author | Nathan Jaremko | 2017-12-24 13:49:19 -0500 | 
|---|---|---|
| committer | Nathan Jaremko | 2017-12-24 13:49:19 -0500 | 
| commit | af8f2907c99c0a4cf5d26c5da74efb51b576909c (patch) | |
| tree | 882a734f05474c7c324bbb9d1e2fd6c205763ee6 /src/utils.rs | |
| parent | be0bcf669e1c187ccec7ada160dac5c26089420a (diff) | |
| download | podcast-af8f2907c99c0a4cf5d26c5da74efb51b576909c.tar.bz2 | |
0.4.7
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 55 | 
1 files changed, 51 insertions, 4 deletions
| diff --git a/src/utils.rs b/src/utils.rs index 789c7da..29bd15a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -18,14 +18,16 @@ pub fn trim_extension(filename: &str) -> Option<String> {  pub fn find_extension(input: &str) -> Option<&str> {      let tmp = String::from(input); -    if tmp.contains(".mp3") { +    if tmp.ends_with(".mp3") {          Some(".mp3") -    } else if tmp.contains(".m4a") { +    } else if tmp.ends_with(".m4a") {          Some(".m4a") -    } else if tmp.contains(".wav") { +    } else if tmp.ends_with(".wav") {          Some(".wav") -    } else if tmp.contains(".ogg") { +    } else if tmp.ends_with(".ogg") {          Some(".ogg") +    } else if tmp.ends_with(".opus") { +        Some(".opus")      } else {          None      } @@ -135,3 +137,48 @@ pub fn parse_download_episodes(e_search: &str) -> Result<Vec<usize>, ParseIntErr      elements.dedup();      Ok(elements)  } + +#[cfg(test)] +mod tests { +    use super::*; + +    #[test] +    fn test_find_extension_mp3() { +        assert_eq!(find_extension("test.mp3"), Some(".mp3")) +    } + +    #[test] +    fn test_find_extension_m4a() { +        assert_eq!(find_extension("test.m4a"), Some(".m4a")) +    } + +    #[test] +    fn test_find_extension_wav() { +        assert_eq!(find_extension("test.wav"), Some(".wav")) +    } + +    #[test] +    fn test_find_extension_ogg() { +        assert_eq!(find_extension("test.ogg"), Some(".ogg")) +    } + +    #[test] +    fn test_find_extension_opus() { +        assert_eq!(find_extension("test.opus"), Some(".opus")) +    } + +    #[test] +    fn test_find_extension_invalid() { +        assert_eq!(find_extension("test.taco"), None) +    } + +    #[test] +    fn test_trim_extension() { +        assert_eq!(trim_extension("test.taco"), Some(String::from("test"))) +    } + +    #[test] +    fn test_trim_extension_invalid() { +        assert_eq!(trim_extension("test"), None) +    } +} | 
