diff options
Diffstat (limited to 'argparse/src/test_path.rs')
-rw-r--r-- | argparse/src/test_path.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/argparse/src/test_path.rs b/argparse/src/test_path.rs new file mode 100644 index 0000000..868ae8c --- /dev/null +++ b/argparse/src/test_path.rs @@ -0,0 +1,30 @@ +use std::path::PathBuf; +use parser::ArgumentParser; +use super::Parse; +use test_parser::{check_ok}; + +fn parse_str(args: &[&str]) -> PathBuf { + let mut val: PathBuf = From::from(""); + { + let mut ap = ArgumentParser::new(); + ap.refer(&mut val) + .add_option(&["-s", "--set"], Parse, + "Set path value"); + check_ok(&ap, args); + } + return val; +} + +#[test] +fn test_path() { + assert_eq!(parse_str(&["./argparse_test", "-s", "/hello"]), + PathBuf::from("/hello")); + assert_eq!(parse_str(&["./argparse_test", "--set", "a///b/../c"]), + PathBuf::from("a/b/../c")); +} + +#[test] +#[should_panic] +fn test_err() { + parse_str(&["./argparse_test", "--set"]); +} |