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 | |
| parent | be0bcf669e1c187ccec7ada160dac5c26089420a (diff) | |
| download | podcast-af8f2907c99c0a4cf5d26c5da74efb51b576909c.tar.bz2 | |
0.4.7
| -rw-r--r-- | CHANGELOG | 4 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/structs.rs | 13 | ||||
| -rw-r--r-- | src/utils.rs | 55 | ||||
| -rw-r--r-- | tests/tests.rs | 5 | 
6 files changed, 62 insertions, 21 deletions
| @@ -1,3 +1,7 @@ +0.4.7 +- Add some tests +- Improve handling of file extensions +  0.4.6  - Add travis-ci support  - Add category to cargo.toml @@ -1,6 +1,6 @@  [package]  name = "podcast" -version = "0.4.6" +version = "0.4.7"  authors = ["Nathan Jaremko <njaremko@gmail.com>"]  description = "A command line podcast manager"  license = "GPL-3.0" diff --git a/src/main.rs b/src/main.rs index 539b0ed..61d4258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use structs::*;  use clap::{App, Arg, SubCommand}; -const VERSION: &str = "0.4.5"; +const VERSION: &str = "0.4.7";  fn main() {      if let Err(err) = create_directories() { @@ -178,4 +178,4 @@ fn main() {      if let Err(err) = state.save() {          eprintln!("{}", err);      } -} +}
\ No newline at end of file diff --git a/src/structs.rs b/src/structs.rs index 817a0d1..b6a1d38 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -14,14 +14,12 @@ use yaml_rust::YamlLoader;  pub struct Config {      pub auto_download_limit: i64, -    pub auto_delete_limit: i64,  }  impl Config {      pub fn new() -> Config {          let mut path = get_podcast_dir();          let mut download_limit = 1; -        let mut delete_limit = 0;          path.push(".config");          if path.exists() {              let mut s = String::new(); @@ -32,9 +30,6 @@ impl Config {                  if let Some(val) = doc["auto_download_limit"].as_i64() {                      download_limit = val;                  } -                if let Some(val) = doc["auto_delete_limit"].as_i64() { -                    delete_limit = val; -                }              }          } else {              let mut file = File::create(&path).unwrap(); @@ -42,7 +37,6 @@ impl Config {          }          Config {              auto_download_limit: download_limit, -            auto_delete_limit: delete_limit,          }      }  } @@ -92,10 +86,9 @@ impl State {              };              state.version = String::from(version);              // Check if a day has passed (86400 seconds) since last launch -            if state -                .last_run_time -                .signed_duration_since(Utc::now()) -                .num_seconds() < -86400 +            if Utc::now() +                .signed_duration_since(state.last_run_time) +                .num_seconds() > 86400              {                  update_rss(&mut state);                  check_for_update(&state.version); 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) +    } +} diff --git a/tests/tests.rs b/tests/tests.rs index 094ed44..8b13789 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,4 +1 @@ -#[test] -fn test1() { -    assert_eq!(5, 5) -} + | 
