use clap::Parser;
use judo::cli::args::{Cli, Commands, DbCommands, ItemCommands, ListCommands};
#[test]
fn test_cli_no_command() {
let args = Cli::try_parse_from(["judo"]);
assert!(args.is_ok());
let cli = args.unwrap();
assert!(cli.command.is_none());
}
#[test]
fn test_dbs_show_command() {
let args = Cli::try_parse_from(["judo", "dbs", "show"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Dbs { command }) => match command {
Some(DbCommands::Show) => {
}
_ => panic!("Expected DbCommands::Show"),
},
_ => panic!("Expected Commands::Dbs"),
}
}
#[test]
fn test_dbs_add_command_with_name() {
let args = Cli::try_parse_from(["judo", "dbs", "add", "--name", "test_db"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Dbs { command }) => match command {
Some(DbCommands::Add { name }) => {
assert_eq!(name, "test_db");
}
_ => panic!("Expected DbCommands::Add"),
},
_ => panic!("Expected Commands::Dbs"),
}
}
#[test]
fn test_dbs_add_command_with_short_flag() {
let args = Cli::try_parse_from(["judo", "dbs", "add", "-n", "my_database"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Dbs { command }) => match command {
Some(DbCommands::Add { name }) => {
assert_eq!(name, "my_database");
}
_ => panic!("Expected DbCommands::Add"),
},
_ => panic!("Expected Commands::Dbs"),
}
}
#[test]
fn test_dbs_add_command_missing_name() {
let args = Cli::try_parse_from(["judo", "dbs", "add"]);
assert!(args.is_err());
}
#[test]
fn test_lists_show_command_no_filter() {
let args = Cli::try_parse_from(["judo", "lists", "show"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Show { name }) => {
assert!(name.is_none());
}
_ => panic!("Expected ListCommands::Show"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_show_command_with_name_filter() {
let args = Cli::try_parse_from(["judo", "lists", "show", "--name", "my_list"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Show { name }) => {
assert_eq!(name, Some("my_list".to_string()));
}
_ => panic!("Expected ListCommands::Show"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_add_command_minimal() {
let args = Cli::try_parse_from(["judo", "lists", "add", "--name", "shopping"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Add { name, db }) => {
assert_eq!(name, "shopping");
assert!(db.is_none());
}
_ => panic!("Expected ListCommands::Add"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_add_command_with_db() {
let args = Cli::try_parse_from(["judo", "lists", "add", "-n", "work", "-d", "office_db"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Add { name, db }) => {
assert_eq!(name, "work");
assert_eq!(db, Some("office_db".to_string()));
}
_ => panic!("Expected ListCommands::Add"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_delete_by_name() {
let args = Cli::try_parse_from(["judo", "lists", "delete", "--name", "old_list"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Delete { name, id, db }) => {
assert_eq!(name, Some("old_list".to_string()));
assert!(id.is_none());
assert!(db.is_none());
}
_ => panic!("Expected ListCommands::Delete"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_delete_by_id() {
let args = Cli::try_parse_from(["judo", "lists", "delete", "--id", "42"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Delete { name, id, db }) => {
assert!(name.is_none());
assert_eq!(id, Some(42));
assert!(db.is_none());
}
_ => panic!("Expected ListCommands::Delete"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_lists_delete_with_db() {
let args = Cli::try_parse_from(["judo", "lists", "delete", "-n", "temp", "-d", "test_db"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Delete { name, id, db }) => {
assert_eq!(name, Some("temp".to_string()));
assert!(id.is_none());
assert_eq!(db, Some("test_db".to_string()));
}
_ => panic!("Expected ListCommands::Delete"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_items_show_command() {
let args = Cli::try_parse_from(["judo", "items", "show"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Show) => {
}
_ => panic!("Expected ItemCommands::Show"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_add_minimal() {
let args = Cli::try_parse_from(["judo", "items", "add", "--name", "Buy milk"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add {
name,
db,
list_name,
list_id,
}) => {
assert_eq!(name, "Buy milk");
assert!(db.is_none());
assert!(list_name.is_none());
assert!(list_id.is_none());
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_add_with_list_name() {
let args = Cli::try_parse_from([
"judo",
"items",
"add",
"--name",
"Task 1",
"--list-name",
"shopping",
]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add {
name,
db,
list_name,
list_id,
}) => {
assert_eq!(name, "Task 1");
assert!(db.is_none());
assert_eq!(list_name, Some("shopping".to_string()));
assert!(list_id.is_none());
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_add_with_list_id() {
let args = Cli::try_parse_from(["judo", "items", "add", "-n", "Task 2", "-i", "5"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add {
name,
db,
list_name,
list_id,
}) => {
assert_eq!(name, "Task 2");
assert!(db.is_none());
assert!(list_name.is_none());
assert_eq!(list_id, Some(5));
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_add_with_db_and_list() {
let args = Cli::try_parse_from([
"judo",
"items",
"add",
"--name",
"Important task",
"--db",
"work_db",
"--list-name",
"projects",
]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add {
name,
db,
list_name,
list_id,
}) => {
assert_eq!(name, "Important task");
assert_eq!(db, Some("work_db".to_string()));
assert_eq!(list_name, Some("projects".to_string()));
assert!(list_id.is_none());
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_delete_command() {
let args = Cli::try_parse_from(["judo", "items", "delete", "--id", "10"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Delete { id, db }) => {
assert_eq!(id, 10);
assert!(db.is_none());
}
_ => panic!("Expected ItemCommands::Delete"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_delete_with_db() {
let args = Cli::try_parse_from(["judo", "items", "delete", "-i", "15", "-d", "archive_db"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Delete { id, db }) => {
assert_eq!(id, 15);
assert_eq!(db, Some("archive_db".to_string()));
}
_ => panic!("Expected ItemCommands::Delete"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_delete_missing_id() {
let args = Cli::try_parse_from(["judo", "items", "delete"]);
assert!(args.is_err());
}
#[test]
fn test_items_toggle_done_command() {
let args = Cli::try_parse_from(["judo", "items", "toggle-done", "--id", "7"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::ToggleDone { id, db }) => {
assert_eq!(id, 7);
assert!(db.is_none());
}
_ => panic!("Expected ItemCommands::ToggleDone"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_items_toggle_done_with_db() {
let args = Cli::try_parse_from([
"judo",
"items",
"toggle-done",
"-i",
"3",
"-d",
"personal_db",
]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::ToggleDone { id, db }) => {
assert_eq!(id, 3);
assert_eq!(db, Some("personal_db".to_string()));
}
_ => panic!("Expected ItemCommands::ToggleDone"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_cli_with_special_characters() {
let args = Cli::try_parse_from([
"judo",
"lists",
"add",
"--name",
"My List! @#$%",
"--db",
"test_db-123",
]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Add { name, db }) => {
assert_eq!(name, "My List! @#$%");
assert_eq!(db, Some("test_db-123".to_string()));
}
_ => panic!("Expected ListCommands::Add"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_cli_with_empty_string_name() {
let args = Cli::try_parse_from(["judo", "items", "add", "--name", ""]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add { name, .. }) => {
assert_eq!(name, "");
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_cli_with_unicode_characters() {
let args = Cli::try_parse_from(["judo", "items", "add", "--name", "🚀 Rocket task 测试"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Items { command }) => match command {
Some(ItemCommands::Add { name, .. }) => {
assert_eq!(name, "🚀 Rocket task 测试");
}
_ => panic!("Expected ItemCommands::Add"),
},
_ => panic!("Expected Commands::Items"),
}
}
#[test]
fn test_cli_with_very_long_name() {
let long_name = "A".repeat(1000);
let args = Cli::try_parse_from(["judo", "lists", "add", "--name", &long_name]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Add { name, .. }) => {
assert_eq!(name, long_name);
}
_ => panic!("Expected ListCommands::Add"),
},
_ => panic!("Expected Commands::Lists"),
}
}
#[test]
fn test_cli_with_negative_id() {
let args = Cli::try_parse_from(["judo", "items", "delete", "--id", "-5"]);
assert!(args.is_err()); }
#[test]
fn test_cli_with_zero_id() {
let args = Cli::try_parse_from(["judo", "lists", "delete", "--id", "0"]);
assert!(args.is_ok());
let cli = args.unwrap();
match cli.command {
Some(Commands::Lists { command }) => match command {
Some(ListCommands::Delete { id, .. }) => {
assert_eq!(id, Some(0));
}
_ => panic!("Expected ListCommands::Delete"),
},
_ => panic!("Expected Commands::Lists"),
}
}