use clap::Parser;
use crate::cli::{Cli, Command};
#[test]
fn cli_parses_f_pattern() {
let cli = Cli::try_parse_from(["trusty-mpm", "f", "api"]).unwrap();
match cli.command.unwrap() {
Command::F(a) => assert_eq!(a.pattern, vec!["api".to_string()]),
other => panic!("expected top-level f, got {other:?}"),
}
}
#[test]
fn cli_parses_f_multi_word_pattern() {
let cli = Cli::try_parse_from(["trusty-mpm", "f", "alpha", "api"]).unwrap();
match cli.command.unwrap() {
Command::F(a) => {
assert_eq!(a.pattern, vec!["alpha".to_string(), "api".to_string()])
}
other => panic!("expected top-level f, got {other:?}"),
}
}
#[test]
fn cli_parses_f_bare_is_allowed() {
let cli = Cli::try_parse_from(["trusty-mpm", "f"]).unwrap();
match cli.command.unwrap() {
Command::F(a) => assert!(a.pattern.is_empty()),
other => panic!("expected top-level f, got {other:?}"),
}
}
#[test]
fn cli_parses_f_json() {
let cli = Cli::try_parse_from(["trusty-mpm", "f", "--json", "api"]).unwrap();
match cli.command.unwrap() {
Command::F(a) => {
assert_eq!(a.pattern, vec!["api".to_string()]);
assert!(a.json);
}
other => panic!("expected top-level f --json, got {other:?}"),
}
}
#[test]
fn cli_f_source_id_and_current_conflict() {
let err = Cli::try_parse_from([
"trusty-mpm",
"f",
"--source-id",
"owner/repo",
"--current",
"api",
]);
assert!(err.is_err(), "--source-id and --current must conflict");
}
#[test]
fn cli_f_does_not_shadow_another_subcommand() {
let cli = Cli::try_parse_from(["trusty-mpm", "f", "x"]).unwrap();
assert!(matches!(cli.command, Some(Command::F(_))));
}