use ai_code_buddy::{
args::{Args, OutputFormat},
core::run_cli_mode,
version::{APP_NAME, APP_VERSION},
};
use tempfile::TempDir;
#[test]
fn test_run_cli_mode_with_credits() {
let args = Args {
repo_path: "/test/repo".to_string(),
source_branch: "main".to_string(),
target_branch: "feature".to_string(),
cli_mode: true,
verbose: false,
show_credits: true,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok());
}
#[test]
fn test_run_cli_mode_basic_functionality() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let args = Args {
repo_path,
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err()); }
#[test]
fn test_run_cli_mode_different_output_formats() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let output_formats = vec![
OutputFormat::Summary,
OutputFormat::Detailed,
OutputFormat::Json,
OutputFormat::Markdown,
];
for format in output_formats {
let args = Args {
repo_path: repo_path.clone(),
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: format,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err());
}
}
#[test]
fn test_run_cli_mode_with_patterns() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let args = Args {
repo_path,
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec!["*.tmp".to_string(), "*.log".to_string()],
include_patterns: vec!["*.rs".to_string(), "*.toml".to_string()],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_run_cli_mode_verbose_mode() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let args = Args {
repo_path,
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: true,
show_credits: false,
output_format: OutputFormat::Detailed,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_run_cli_mode_gpu_flags() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let args_gpu = Args {
repo_path: repo_path.clone(),
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: true,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result_gpu = run_cli_mode(args_gpu);
assert!(result_gpu.is_ok() || result_gpu.is_err());
let args_cpu = Args {
repo_path,
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: true,
parallel: false,
disable_ai: false,
};
let result_cpu = run_cli_mode(args_cpu);
assert!(result_cpu.is_ok() || result_cpu.is_err());
}
#[test]
fn test_version_constants() {
assert!(!APP_NAME.is_empty());
assert!(!APP_VERSION.is_empty());
assert!(APP_VERSION.contains('.') || APP_VERSION.chars().all(|c| c.is_numeric()));
}
#[test]
fn test_args_parsing_for_cli_mode() {
let args = Args {
repo_path: "/test/path".to_string(),
source_branch: "develop".to_string(),
target_branch: "feature-branch".to_string(),
cli_mode: true,
verbose: true,
show_credits: false,
output_format: OutputFormat::Json,
exclude_patterns: vec!["target/".to_string()],
include_patterns: vec!["src/".to_string()],
use_gpu: true,
force_cpu: false,
parallel: false,
disable_ai: false,
};
assert_eq!(args.repo_path, "/test/path");
assert_eq!(args.source_branch, "develop");
assert_eq!(args.target_branch, "feature-branch");
assert!(args.cli_mode);
assert!(args.verbose);
assert!(!args.show_credits);
assert!(matches!(args.output_format, OutputFormat::Json));
assert_eq!(args.exclude_patterns, vec!["target/"]);
assert_eq!(args.include_patterns, vec!["src/"]);
assert!(args.use_gpu);
assert!(!args.force_cpu);
}
#[test]
fn test_run_cli_mode_error_handling() {
let args = Args {
repo_path: "/nonexistent/path/that/does/not/exist".to_string(),
source_branch: "main".to_string(),
target_branch: "main".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_run_cli_mode_different_branches() {
let temp_dir = TempDir::new().unwrap();
let repo_path = temp_dir.path().to_str().unwrap().to_string();
let args = Args {
repo_path,
source_branch: "main".to_string(),
target_branch: "develop".to_string(),
cli_mode: true,
verbose: false,
show_credits: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: false,
parallel: false,
disable_ai: false,
};
let result = run_cli_mode(args);
assert!(result.is_ok() || result.is_err());
}