use clap::{CommandFactory, Parser};
#[derive(Parser)]
#[command(name = "hedl")]
#[command(author, version, about = "HEDL CLI")]
struct TestCli {
#[command(subcommand)]
command: hedl_cli::cli::Commands,
}
#[test]
fn test_core_commands_available() {
let cmd = TestCli::command();
let subcommands: Vec<_> = cmd.get_subcommands().map(clap::Command::get_name).collect();
assert!(subcommands.contains(&"validate"));
assert!(subcommands.contains(&"format"));
assert!(subcommands.contains(&"lint"));
assert!(subcommands.contains(&"inspect"));
assert!(subcommands.contains(&"stats"));
}
#[test]
fn test_conversion_commands_available() {
let cmd = TestCli::command();
let subcommands: Vec<_> = cmd.get_subcommands().map(clap::Command::get_name).collect();
assert!(subcommands.contains(&"to-json"));
assert!(subcommands.contains(&"from-json"));
assert!(subcommands.contains(&"to-yaml"));
assert!(subcommands.contains(&"from-yaml"));
assert!(subcommands.contains(&"to-xml"));
assert!(subcommands.contains(&"from-xml"));
assert!(subcommands.contains(&"to-csv"));
assert!(subcommands.contains(&"from-csv"));
assert!(subcommands.contains(&"to-parquet"));
assert!(subcommands.contains(&"from-parquet"));
}
#[test]
fn test_batch_commands_available() {
let cmd = TestCli::command();
let subcommands: Vec<_> = cmd.get_subcommands().map(clap::Command::get_name).collect();
assert!(subcommands.contains(&"batch-validate"));
assert!(subcommands.contains(&"batch-format"));
assert!(subcommands.contains(&"batch-lint"));
}
#[test]
fn test_completion_command_available() {
let cmd = TestCli::command();
let subcommands: Vec<_> = cmd.get_subcommands().map(clap::Command::get_name).collect();
assert!(subcommands.contains(&"completion"));
}
#[test]
fn test_validate_command_args() {
let result = TestCli::try_parse_from(["hedl", "validate", "test.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "validate", "test.hedl", "--strict"]);
assert!(result.is_ok());
}
#[test]
fn test_format_command_args() {
let result = TestCli::try_parse_from(["hedl", "format", "test.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "format", "test.hedl", "--output", "out.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "format", "test.hedl", "--check"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "format", "test.hedl", "--ditto"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "format", "test.hedl", "--with-counts"]);
assert!(result.is_ok());
}
#[test]
fn test_conversion_command_args() {
let result = TestCli::try_parse_from(["hedl", "to-json", "test.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "to-json", "test.hedl", "--pretty"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "from-json", "test.json"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "to-yaml", "test.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "from-yaml", "test.yaml"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "to-xml", "test.hedl", "--pretty"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "from-xml", "test.xml"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "to-csv", "test.hedl", "--headers"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "from-csv", "test.csv", "--type-name", "Row"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from([
"hedl",
"to-parquet",
"test.hedl",
"--output",
"test.parquet",
]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "from-parquet", "test.parquet"]);
assert!(result.is_ok());
}
#[test]
fn test_batch_command_args() {
let result = TestCli::try_parse_from(["hedl", "batch-validate", "file1.hedl", "file2.hedl"]);
assert!(result.is_ok());
let result =
TestCli::try_parse_from(["hedl", "batch-validate", "*.hedl", "--strict", "--parallel"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "batch-format", "file1.hedl", "file2.hedl"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from([
"hedl",
"batch-format",
"*.hedl",
"--output-dir",
"formatted",
"--parallel",
]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "batch-lint", "file1.hedl", "file2.hedl"]);
assert!(result.is_ok());
let result =
TestCli::try_parse_from(["hedl", "batch-lint", "*.hedl", "--warn-error", "--parallel"]);
assert!(result.is_ok());
}
#[test]
fn test_completion_command_args() {
let result = TestCli::try_parse_from(["hedl", "completion", "bash"]);
assert!(result.is_ok());
let result = TestCli::try_parse_from(["hedl", "completion", "zsh", "--install"]);
assert!(result.is_ok());
}
#[test]
fn test_cli_help_generation() {
let mut cmd = TestCli::command();
let help = cmd.render_help();
let help_str = help.to_string();
assert!(help_str.contains("HEDL"));
assert!(help_str.contains("validate"));
assert!(help_str.contains("format"));
assert!(help_str.contains("to-json"));
}
#[test]
fn test_command_count() {
let cmd = TestCli::command();
let count = cmd.get_subcommands().count();
assert_eq!(count, 21, "Expected 21 commands, found {count}");
}