use crate::compsys::ported::_arguments::_arguments;
use crate::ported::params::getsparam;
const HOOK_TYPES: [&str; 14] = [
"gen-applied-string",
"gen-hg-bookmark-string",
"gen-mqguards-string",
"gen-unapplied-string",
"no-vcs",
"post-backend",
"post-quilt",
"pre-addon-quilt",
"pre-get-data",
"set-branch-format",
"set-hgrev-format",
"set-message",
"set-patch-format",
"start-up",
];
fn build_call(service: &str) -> Vec<String> {
let mut call: Vec<String> = Vec::new();
call.push(":".to_string());
if service == "vcs_info_hookdel" {
call.push("-a[remove all occurrences, not just the first]".to_string());
}
call.push(format!(":hook type:({})", HOOK_TYPES.join(" ")));
call.push("*:hook function:_vcs_info_hooks".to_string());
call
}
pub fn _vcs_info(_args: &[String]) -> i32 {
let service = getsparam("service").unwrap_or_default();
let call = build_call(&service);
_arguments(&call) }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hookadd_has_no_extra_spec() {
let call = build_call("vcs_info_hookadd");
assert_eq!(call[0], ":");
assert!(!call.iter().any(|s| s.starts_with("-a[")));
assert_eq!(call.len(), 3);
assert_eq!(call.last().unwrap(), "*:hook function:_vcs_info_hooks");
}
#[test]
fn hookdel_gets_dash_a_spec() {
let call = build_call("vcs_info_hookdel");
assert_eq!(call.len(), 4);
assert_eq!(call[1], "-a[remove all occurrences, not just the first]");
}
#[test]
fn hook_type_spec_joins_all_types_with_spaces() {
let call = build_call("");
let spec = call.iter().find(|s| s.starts_with(":hook type:")).unwrap();
assert_eq!(
spec,
":hook type:(gen-applied-string gen-hg-bookmark-string gen-mqguards-string \
gen-unapplied-string no-vcs post-backend post-quilt pre-addon-quilt pre-get-data \
set-branch-format set-hgrev-format set-message set-patch-format start-up)"
);
}
}