use super::*;
use std::os::unix::ffi::OsStringExt as _;
fn args(parts: &[&str]) -> Vec<String> {
parts.iter().map(|s| (*s).to_string()).collect()
}
#[test]
fn parse_accepts_a_verb_and_maps_help_and_errors_to_exit_codes() {
let cli = parse(&args(&["new", "/tmp/ws"])).unwrap();
assert!(matches!(cli.command, cmd::Command::New(_)));
assert_eq!(parse(&args(&["--help"])).unwrap_err(), 0);
assert_eq!(parse(&args(&["no-such-verb"])).unwrap_err(), 2);
assert_eq!(parse(&[]).unwrap_err(), 2);
}
#[test]
fn edit_with_maps_the_editor_exit_to_the_edit_result() {
let dir = tempfile::TempDir::new().unwrap();
let ok = edit_with("test -d", dir.path());
assert!(ok.is_ok());
let err = edit_with("false", dir.path()).unwrap_err();
assert!(err.to_string().contains("editor exited"));
}
#[test]
fn conclude_performs_success_and_prints_the_uniform_failure() {
assert_eq!(conclude(Ok(Outcome::Quiet)), 0);
assert_eq!(conclude(Err(cmd::Error::new("prompt", "boom"))), 1);
}
#[test]
fn perform_maps_each_outcome_to_its_exit() {
assert_eq!(perform(Outcome::Line("a-branch".to_owned())), 0);
assert_eq!(perform(Outcome::Quiet), 0);
assert_eq!(perform(Outcome::Code(7)), 7);
let mut cmd = crate::git_env::command(Path::new("/nonexistent/yog-successor"));
cmd.arg(std::ffi::OsString::from_vec(b"a\0b".to_vec()));
assert_eq!(perform(Outcome::Exec(cmd)), 1);
}
#[test]
fn driving_names_an_agent_only_for_the_driver_verb() {
let advance = parse(&args(&["advance", "/w/home", "dulcet-mongoose"])).unwrap();
assert_eq!(
driving(&advance.command),
Some(("home".to_owned(), "dulcet-mongoose".to_owned()))
);
let prompt = parse(&args(&["prompt", "/w/home", "hello"])).unwrap();
assert_eq!(driving(&prompt.command), None);
}