mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
add pre test setup function
This commit is contained in:
parent
1e11a99991
commit
dbb329344a
@ -220,6 +220,25 @@ mod tests {
|
|||||||
args.map(OsString::from).collect()
|
args.map(OsString::from).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setup_args_scenario(arg_str: &str) -> Result<(Vec<OsString>, Flags), OofError> {
|
||||||
|
let flags_info = [
|
||||||
|
ArgFlag::long("output_file").short('o'),
|
||||||
|
Flag::long("verbose").short('v'),
|
||||||
|
Flag::long("help").short('h'),
|
||||||
|
];
|
||||||
|
|
||||||
|
let args = gen_args(arg_str);
|
||||||
|
filter_flags(args, &flags_info)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unknown_short_flag() {
|
||||||
|
let result = setup_args_scenario("ouch a.zip -s b.tar.gz c.tar").unwrap_err();
|
||||||
|
assert!(matches!(result, OofError::UnknownShortFlag('s')));
|
||||||
|
let result = setup_args_scenario("ouch a.zip --foobar b.tar.gz c.tar").unwrap_err();
|
||||||
|
// TODO: assert `UnknownLongFlag` error
|
||||||
|
}
|
||||||
|
|
||||||
// asdasdsa
|
// asdasdsa
|
||||||
#[test]
|
#[test]
|
||||||
fn test_filter_flags() {
|
fn test_filter_flags() {
|
||||||
@ -239,19 +258,6 @@ mod tests {
|
|||||||
assert!(!flags.is_present("output_file"));
|
assert!(!flags.is_present("output_file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_unknown_short_flag() {
|
|
||||||
let flags_info = [
|
|
||||||
ArgFlag::long("output_file").short('o'),
|
|
||||||
Flag::long("verbose").short('v'),
|
|
||||||
Flag::long("help").short('h'),
|
|
||||||
];
|
|
||||||
|
|
||||||
let args = gen_args("ouch a.zip -s b.tar.gz");
|
|
||||||
let result = filter_flags(args, &flags_info).unwrap_err();
|
|
||||||
assert!(matches!(result, OofError::UnknownShortFlag('s')));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pop_subcommand() {
|
fn test_pop_subcommand() {
|
||||||
let subcommands = &["commit", "add", "push", "remote"];
|
let subcommands = &["commit", "add", "push", "remote"];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user