From f87fc2205bc7b2027abbfd7d8cff0f0c5e8017df Mon Sep 17 00:00:00 2001 From: anderejd Date: Fri, 1 Dec 2017 22:57:59 +0100 Subject: [PATCH] PR review fixes, docopt already provides case-insensitive deserialization. --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 26 ++++++++++++++++++++++++++ src/types.rs | 25 ------------------------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ceab0ff3..b22158448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,7 +451,6 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 828786591..f854e14dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ flate2 = "0.2.20" log = "0.3.8" serde = "1.0.21" serde_derive = "1.0.21" -serde_json = "1.0.6" tar = "0.4.14" time = "0.1.38" walkdir = "2.0.1" diff --git a/src/main.rs b/src/main.rs index fa2d9b823..30b75c4e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -256,3 +256,29 @@ fn main() { process::exit(1); } } + +#[cfg(test)] +mod test { + use Args; + use OsType; + use USAGE; + use docopt::Docopt; + use docopt::Error; + + fn test_helper(argv: &[&str]) -> Result { + Docopt::new(USAGE).and_then(|d| d.argv(argv.iter()).deserialize()) + } + + #[test] + fn test_docopt_os_case_insensitive() { + let argv = vec!["cp", "--os", "LiNuX"]; + let os = test_helper(&argv).unwrap().flag_os.unwrap(); + assert_eq!(OsType::Linux, os); + } + + #[test] + fn test_docopt_expect_error() { + let argv = vec!["cp", "--os", "lindows"]; + assert!(!test_helper(&argv).is_ok()); + } +} diff --git a/src/types.rs b/src/types.rs index 35e0ea77c..5e597b459 100644 --- a/src/types.rs +++ b/src/types.rs @@ -54,32 +54,7 @@ impl LineType { #[cfg(test)] mod test { - extern crate serde_json; - - use super::OsType::{self, Linux, OsX, SunOs, Other}; use super::LineType; - use self::serde_json::from_str; - - #[test] - fn test_os_type_decoding_regular() { - assert_eq!(from_str::("\"linux\"").unwrap(), Linux); - assert_eq!(from_str::("\"osx\"").unwrap(), OsX); - assert_eq!(from_str::("\"sunos\"").unwrap(), SunOs); - assert_eq!(from_str::("\"other\"").unwrap(), Other); - } - - // REVIEW: Not sure how to do case-insensitive deserialization with serde - // json. Ok to ditch support for this? - //#[test] - //fn test_os_type_decoding_uppercase() { - // assert_eq!(from_str::("\"Linux\"").unwrap(), Linux); - // assert_eq!(from_str::("\"LINUX\"").unwrap(), Linux); - //} - - #[test] - fn test_os_type_decoding_unknown() { - assert!(from_str::("\"lindows\"").is_err()); - } #[test] fn test_linetype_from_str() {