use super::*;
const CLASSES: [ChildClass; 2] = [ChildClass::Plumbing, ChildClass::Object];
const BULK_STEPS: [&str; 10] =
["pack-objects", "index-pack", "add", "hash-object", "maintenance", "reset", "update-index", "ls-files", "diff", "show"];
fn arguments(words: &[&str]) -> Vec<OsString> {
return words.iter().map(OsString::from).collect();
}
#[test]
fn query_subcommands_are_classed_as_plumbing_after_any_global_options() {
for name in PLUMBING_SUBCOMMANDS {
assert_eq!(class_of(&arguments(&[name, "--quiet"])), ChildClass::Plumbing, "{name}");
assert_eq!(
class_of(&arguments(&["--git-dir=/shadow", "-c", "core.hooksPath=/none", "-C", "/repo", name])),
ChildClass::Plumbing,
"{name} behind global options"
);
}
}
#[test]
fn steps_that_move_bytes_or_compare_the_index_are_bulk_work() {
for name in BULK_STEPS {
assert_eq!(class_of(&arguments(&["-c", "core.fsync=none", name, "--quiet", "--detach"])), ChildClass::Object, "{name}");
}
}
#[test]
fn no_bulk_step_is_in_the_query_list() {
for name in BULK_STEPS {
assert!(!PLUMBING_SUBCOMMANDS.contains(&name), "{name}");
}
}
#[test]
fn an_unknown_step_gets_the_longer_bound() {
assert_eq!(class_of(&arguments(&["frobnicate", "--now"])), ChildClass::Object);
assert_eq!(class_of(&arguments(&["--version"])), ChildClass::Object);
assert_eq!(class_of(&[]), ChildClass::Object);
}
#[test]
fn the_variable_sets_every_class_to_the_same_bound() {
let seconds: u64 = OBJECT_QUIET_WINDOW.as_secs() + PLUMBING_QUIET_WINDOW.as_secs() + 1;
let text: String = seconds.to_string();
for class in CLASSES {
assert_eq!(class.limit_from(Some(OsStr::new(text.as_str()))), Duration::from_secs(seconds), "{class:?}");
}
}
#[test]
fn an_unusable_value_falls_back_to_the_class_default() {
for class in CLASSES {
assert_eq!(class.limit_from(None), class.default_limit(), "{class:?}");
for value in ["0", "", "-1", "1.5", "soon"] {
assert_eq!(class.limit_from(Some(OsStr::new(value))), class.default_limit(), "{class:?} {value:?}");
}
}
}
#[test]
fn the_object_class_is_the_more_patient_one_and_every_notice_precedes_its_bound() {
assert!(OBJECT_QUIET_WINDOW > PLUMBING_QUIET_WINDOW);
assert!(OBJECT_NOTICE_GRACE >= PLUMBING_NOTICE_GRACE);
for class in CLASSES {
assert!(class.notice_grace() < class.default_limit(), "{class:?}");
}
}
#[test]
fn the_classes_have_different_labels() {
assert_ne!(ChildClass::Plumbing.label(), ChildClass::Object.label());
}