use probe_code::search::{perform_probe, SearchOptions};
use std::path::PathBuf;
#[test]
fn test_ip_whitelist_stemming() {
let file_path = PathBuf::from("tests/mocks/test_ip_whitelist.go");
let queries = vec!["ip whitelisting".to_string()];
let custom_ignores: Vec<String> = vec![];
let options = SearchOptions {
path: file_path.parent().unwrap().parent().unwrap(), queries: &queries,
files_only: false,
custom_ignores: &custom_ignores,
exclude_filenames: true,
language: None,
reranker: "hybrid",
frequency_search: true, exact: false,
max_results: None,
max_bytes: None,
max_tokens: None,
allow_tests: true,
no_merge: true,
merge_threshold: None,
dry_run: false,
session: None,
timeout: 30,
};
std::env::set_var("DEBUG", "1");
let search_results = perform_probe(&options).expect("Failed to perform search");
std::env::remove_var("DEBUG");
assert!(!search_results.results.is_empty(), "Should find matches");
let test_file_result = search_results
.results
.iter()
.find(|r| r.file.contains("test_ip_whitelist.go"));
assert!(
test_file_result.is_some(),
"Should find the test_ip_whitelist.go file"
);
if let Some(result) = test_file_result {
if let Some(block_unique_terms) = result.block_unique_terms {
assert!(
block_unique_terms >= 1,
"Expected at least 1 unique term, got {block_unique_terms}"
);
} else {
panic!("block_unique_terms should be set");
}
if let Some(block_total_matches) = result.block_total_matches {
assert!(
block_total_matches >= 1,
"Expected at least 1 total match, got {block_total_matches}"
);
} else {
panic!("block_total_matches should be set");
}
println!("Result for test_ip_whitelist.go:");
println!(" block_unique_terms: {:?}", result.block_unique_terms);
println!(" block_total_matches: {:?}", result.block_total_matches);
println!(" code: {}", result.code);
}
}
#[test]
fn test_negative_terms_exclude_files() {
let file_path = PathBuf::from("tests/mocks/test_ip_whitelist.go");
let queries = vec!["(+ip) -whitelist".to_string()];
let custom_ignores: Vec<String> = vec![];
let options = SearchOptions {
path: file_path.parent().unwrap().parent().unwrap(), queries: &queries,
files_only: false,
custom_ignores: &custom_ignores,
exclude_filenames: true,
language: None,
reranker: "hybrid",
frequency_search: true,
exact: false,
max_results: None,
max_bytes: None,
max_tokens: None,
allow_tests: true,
no_merge: true,
merge_threshold: None,
dry_run: false,
session: None,
timeout: 30,
};
std::env::set_var("DEBUG", "1");
let search_results = perform_probe(&options).expect("Failed to perform search");
std::env::remove_var("DEBUG");
let test_file_result = search_results
.results
.iter()
.find(|r| r.file.contains("test_ip_whitelist.go"));
assert!(
test_file_result.is_none(),
"test_ip_whitelist.go should be excluded from results because it contains 'whitelist'"
);
println!("✓ Files containing negative terms are properly excluded from results");
}