#[cfg(test)]
mod tests {
use std::str::FromStr;
#[test]
#[cfg(feature = "repl-file")]
fn test_file_command_parsing_basic() {
use terraphim_agent::repl::commands::ReplCommand;
let result = ReplCommand::from_str("/file search \"test query\"");
assert!(result.is_ok());
if let ReplCommand::File { subcommand: _ } = result.unwrap() {
println!("✅ File search command parsed successfully");
} else {
panic!("Expected File command");
}
}
#[test]
#[cfg(feature = "repl-file")]
fn test_file_command_help_available() {
use terraphim_agent::repl::commands::ReplCommand;
let commands = ReplCommand::available_commands();
assert!(
commands.contains(&"file"),
"file command should be in available commands"
);
let help_text = ReplCommand::get_command_help("file");
assert!(help_text.is_some(), "file command should have help text");
let help = help_text.unwrap();
assert!(
help.to_lowercase().contains("file operations"),
"help should mention file operations, got: {}",
help
);
println!("✅ File command help available: {}", help);
}
#[test]
#[cfg(feature = "repl-file")]
fn test_variations_of_file_commands() {
use terraphim_agent::repl::commands::ReplCommand;
let test_commands = vec![
"/file search \"rust async\"",
"/file list",
"/file info ./main.rs",
];
for cmd in test_commands {
let result = ReplCommand::from_str(cmd);
assert!(result.is_ok(), "Failed to parse command: {}", cmd);
match result.unwrap() {
ReplCommand::File { .. } => {
println!("✅ Successfully parsed: {}", cmd);
}
_ => panic!("Expected File command for: {}", cmd),
}
}
}
#[test]
#[cfg(feature = "repl-file")]
fn test_invalid_file_commands() {
use terraphim_agent::repl::commands::ReplCommand;
let invalid_commands = vec![
"/file", "/file search", "/file info", "/file invalid_subcommand ./src", ];
for cmd in invalid_commands {
let result = ReplCommand::from_str(cmd);
assert!(
result.is_err(),
"Expected error for invalid command: {}",
cmd
);
println!("✅ Correctly rejected invalid command: {}", cmd);
}
}
#[test]
#[cfg(feature = "repl-file")]
fn test_file_command_with_various_flags() {
use terraphim_agent::repl::commands::ReplCommand;
let complex_commands = vec![
"/file search \"async rust\"",
"/file list",
"/file info ./src/main.rs",
];
for cmd in complex_commands {
let result = ReplCommand::from_str(cmd);
assert!(result.is_ok(), "Failed to parse complex command: {}", cmd);
match result.unwrap() {
ReplCommand::File { .. } => {
println!("✅ Successfully parsed complex command: {}", cmd);
}
_ => panic!("Expected File command for: {}", cmd),
}
}
}
}