Skip to content

Commit

Permalink
PR review fixes, docopt already provides case-insensitive deserializa…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
anderejd committed Dec 1, 2017
1 parent 4d557c2 commit f87fc22
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Args, Error> {
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());
}
}
25 changes: 0 additions & 25 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<OsType>("\"linux\"").unwrap(), Linux);
assert_eq!(from_str::<OsType>("\"osx\"").unwrap(), OsX);
assert_eq!(from_str::<OsType>("\"sunos\"").unwrap(), SunOs);
assert_eq!(from_str::<OsType>("\"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::<OsType>("\"Linux\"").unwrap(), Linux);
// assert_eq!(from_str::<OsType>("\"LINUX\"").unwrap(), Linux);
//}

#[test]
fn test_os_type_decoding_unknown() {
assert!(from_str::<OsType>("\"lindows\"").is_err());
}

#[test]
fn test_linetype_from_str() {
Expand Down

0 comments on commit f87fc22

Please sign in to comment.