use clap::{CommandFactory, Parser};
use getquotes::cli::Args;
use getquotes::cli::Shell;
#[test]
fn test_cli_arguments() {
let default_args = Args::parse_from(["getquotes"]);
assert_eq!(default_args.authors, None);
assert_eq!(default_args.theme_color, None);
assert_eq!(default_args.max_tries, None);
assert_eq!(default_args.log_file, None);
assert_eq!(default_args.rainbow_mode, None);
assert!(!default_args.init_cache);
assert!(!default_args.offline);
assert!(!default_args.version);
assert_eq!(default_args.config, None);
assert_eq!(default_args.completion, None);
let args = Args::parse_from(["getquotes", "--authors", "Author1,Author2"]);
assert_eq!(args.authors, Some("Author1,Author2".to_string()));
let args = Args::parse_from(["getquotes", "--theme-color", "#FF00FF"]);
assert_eq!(args.theme_color, Some("#FF00FF".to_string()));
let args = Args::parse_from(["getquotes", "--max-tries", "42"]);
assert_eq!(args.max_tries, Some(42));
let args = Args::parse_from(["getquotes", "--log-file", "custom.log"]);
assert_eq!(args.log_file, Some("custom.log".to_string()));
let args = Args::parse_from(["getquotes", "--rainbow-mode"]);
assert_eq!(args.rainbow_mode, Some(true));
let args = Args::parse_from(["getquotes", "--init-cache"]);
assert!(args.init_cache);
let args = Args::parse_from(["getquotes", "--offline"]);
assert!(args.offline);
let args = Args::parse_from(["getquotes", "--version"]);
assert!(args.version);
let args = Args::parse_from(["getquotes", "--config", "custom.toml"]);
assert_eq!(args.config, Some("custom.toml".to_string()));
let args = Args::parse_from(["getquotes", "--completion", "bash"]);
if let Some(shell) = args.completion {
match shell {
Shell::Bash => (), _ => panic!("Expected Shell::Bash"),
}
} else {
panic!("Expected Some(Shell::Bash)");
}
let args = Args::parse_from([
"getquotes",
"-a",
"Author1",
"-t",
"#FF0000",
"-m",
"25",
"-l",
"log.txt",
"-r",
"-i",
"-o",
"-v",
"-C",
"conf.toml",
]);
assert_eq!(args.authors, Some("Author1".to_string()));
assert_eq!(args.theme_color, Some("#FF0000".to_string()));
assert_eq!(args.max_tries, Some(25));
assert_eq!(args.log_file, Some("log.txt".to_string()));
assert_eq!(args.rainbow_mode, Some(true));
assert!(args.init_cache);
assert!(args.offline);
assert!(args.version);
assert_eq!(args.config, Some("conf.toml".to_string()));
}
#[test]
fn test_command_factory() {
let cmd = Args::command();
assert_eq!(cmd.get_name(), "getquotes");
cmd.clone().build();
}