Add test cases for order of precedence

This commit is contained in:
Sophie Tauchert 2021-01-13 11:00:21 +01:00 committed by Abin Simon
parent 2a93ce3a6e
commit d4fbedd1e4

View file

@ -248,4 +248,46 @@ mod test {
DateFlag::from_environment()
);
}
#[test]
#[serial_test::serial]
fn test_parsing_order_arg() {
std::env::set_var("TIME_STYLE", "+%R");
let argv = vec!["lsd", "--date", "+%F"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
let mut config = Config::with_none();
config.date = Some("+%c".into());
assert_eq!(
DateFlag::Formatted("%F".into()),
DateFlag::configure_from(&matches, &config)
);
}
#[test]
#[serial_test::serial]
fn test_parsing_order_env() {
std::env::set_var("TIME_STYLE", "+%R");
let argv = vec!["lsd"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
let mut config = Config::with_none();
config.date = Some("+%c".into());
assert_eq!(
DateFlag::Formatted("%R".into()),
DateFlag::configure_from(&matches, &config)
);
}
#[test]
#[serial_test::serial]
fn test_parsing_order_config() {
std::env::set_var("TIME_STYLE", "");
let argv = vec!["lsd"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
let mut config = Config::with_none();
config.date = Some("+%c".into());
assert_eq!(
DateFlag::Formatted("%c".into()),
DateFlag::configure_from(&matches, &config)
);
}
}