use super::*;
#[test]
fn hook_compose_applies_the_directive_and_converges() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
conf(&e, &["append", "close.pre", "x"]).unwrap();
assert!(landing_text(&clone, "plugins.toml").contains("\"close.pre\" = [\"x\"]"));
let sealed = commits(&clone.landing());
conf(&e, &["append", "close.pre", "x"]).unwrap();
conf(&e, &["prepend", "close.pre", "x"]).unwrap();
assert_eq!(commits(&clone.landing()), sealed);
conf(&e, &["prepend", "close.pre", "y"]).unwrap();
assert!(landing_text(&clone, "plugins.toml").contains("\"close.pre\" = [\"y\", \"x\"]"));
conf(&e, &["remove", "close.pre", "ghost"]).unwrap();
conf(&e, &["remove", "close.pre", "y"]).unwrap();
conf(&e, &["remove", "close.pre", "x"]).unwrap();
assert!(!landing_text(&clone, "plugins.toml").contains("close.pre"));
}
#[test]
fn set_on_a_hooks_key_bare_replaces_the_whole_list() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
conf(&e, &["set", "close.pre", "a", "b"]).unwrap();
assert!(landing_text(&clone, "plugins.toml").contains("\"close.pre\" = [\"a\", \"b\"]"));
conf(&e, &["set", "close.pre"]).unwrap();
assert!(!landing_text(&clone, "plugins.toml").contains("close.pre"));
}
#[test]
fn an_empty_plugin_name_is_refused_and_writes_nothing() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
let before = commits(&clone.landing());
for argv in [
vec!["set", "close.pre", ""],
vec!["set", "close.pre", "a", ""],
vec!["append", "close.pre", ""],
vec!["prepend", "close.pre", ""],
vec!["remove", "close.pre", ""],
] {
let err = conf(&e, &argv).unwrap_err().to_string();
assert!(err.contains("non-empty"), "{argv:?}: {err}");
}
assert!(!landing_text(&clone, "plugins.toml").contains("close.pre"));
assert_eq!(commits(&clone.landing()), before);
}
#[test]
fn foreign_tables_round_trip_untouched() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
fs::write(
clone.landing().join("config").join("plugins.toml"),
"[team]\nkeep = \"this\"\n\n[hooks]\n\"close.pre\" = [\"a\"]\n",
)
.unwrap();
conf(&e, &["append", "close.pre", "b"]).unwrap();
let body = landing_text(&clone, "plugins.toml");
assert!(body.contains("keep = \"this\""), "{body}");
assert!(body.contains("\"close.pre\" = [\"a\", \"b\"]"), "{body}");
}
#[test]
fn a_wired_retired_verb_hook_is_readable_and_removable_but_uncreatable() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
fs::write(
clone.landing().join("config").join("plugins.toml"),
"[hooks]\n\"drop.post\" = [\"bl-delivery\"]\n",
)
.unwrap();
conf(&e, &["drop.post"]).unwrap(); conf(&e, &["remove", "drop.post", "bl-delivery"]).unwrap(); assert!(!landing_text(&clone, "plugins.toml").contains("drop.post"));
let err = conf(&e, &["set", "drop.post", "bl-tracker"]).unwrap_err().to_string();
assert!(err.contains("unknown key"), "{err}");
}
#[test]
fn a_non_table_hooks_root_is_refused() {
let tmp = TempDir::new().unwrap();
let e = edge(&tmp);
let clone = founded(&e);
fs::write(clone.landing().join("config").join("plugins.toml"), "hooks = \"nope\"\n").unwrap();
let err = conf(&e, &["append", "close.pre", "x"]).unwrap_err().to_string();
assert!(err.contains("[hooks] is not a table"), "{err}");
}