use probe_code::extract::{handle_extract, ExtractOptions};
use std::fs;
use tempfile::tempdir;
#[test]
fn test_parallel_file_extraction() {
let temp_dir = tempdir().unwrap();
let base_path = temp_dir.path();
let file_count = 10;
let mut file_paths = Vec::new();
for i in 0..file_count {
let file_path = base_path.join(format!("test_file_{i}.rs"));
let content = format!(
"// Test file {i}\n\nfn function_a() {{\n println!(\"Hello from function A\");\n}}\n\nfn function_b() {{\n println!(\"Hello from function B\");\n}}\n"
);
fs::write(&file_path, content).unwrap();
file_paths.push(file_path.to_string_lossy().to_string());
}
let options = ExtractOptions {
files: file_paths,
custom_ignores: Vec::new(),
context_lines: 0,
format: "plain".to_string(),
from_clipboard: false,
input_file: None,
to_clipboard: false,
dry_run: false,
diff: false,
allow_tests: true,
instructions: None,
keep_input: false,
prompt: None,
};
let result = handle_extract(options);
assert!(result.is_ok(), "Extraction should succeed");
}
#[test]
fn test_parallel_extraction_with_specific_lines() {
let temp_dir = tempdir().unwrap();
let base_path = temp_dir.path();
let file_path = base_path.join("multi_function.rs");
let content = r#"
fn function_one() {
println!("This is function one");
}
fn function_two() {
println!("This is function two");
}
fn function_three() {
println!("This is function three");
}
fn function_four() {
println!("This is function four");
}
"#;
fs::write(&file_path, content).unwrap();
let file_count = 5;
let mut file_paths = Vec::new();
for i in 0..file_count {
let path = base_path.join(format!("multi_function_{i}.rs"));
fs::write(&path, content).unwrap();
file_paths.push(path.to_string_lossy().to_string());
}
let options = ExtractOptions {
files: file_paths,
custom_ignores: Vec::new(),
context_lines: 0,
format: "plain".to_string(),
from_clipboard: false,
input_file: None,
to_clipboard: false,
dry_run: false,
diff: false,
allow_tests: true,
instructions: None,
keep_input: false,
prompt: None,
};
let result = handle_extract(options);
assert!(result.is_ok(), "Extraction should succeed");
}
#[test]
fn test_parallel_extraction_performance() {
if std::env::var("CI").is_ok() {
return;
}
let temp_dir = tempdir().unwrap();
let base_path = temp_dir.path();
let file_count = 50; let mut file_paths = Vec::new();
for i in 0..file_count {
let file_path = base_path.join(format!("perf_test_{i}.rs"));
let content = format!(
"// Performance test file {}\n\n{}\n",
i,
(0..20)
.map(|j| format!(
"fn function_{i}_{j}() {{\n let x = {j};\n println!(\"Value: {{}}\", x);\n}}\n"
))
.collect::<Vec<_>>()
.join("\n")
);
fs::write(&file_path, content).unwrap();
file_paths.push(file_path.to_string_lossy().to_string());
}
let options = ExtractOptions {
files: file_paths,
custom_ignores: Vec::new(),
context_lines: 0,
format: "plain".to_string(),
from_clipboard: false,
input_file: None,
to_clipboard: false,
dry_run: true, diff: false,
allow_tests: true,
instructions: None,
keep_input: false,
prompt: None,
};
let result = handle_extract(options);
assert!(
result.is_ok(),
"Parallel extraction should succeed with many files"
);
}