use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::TempDir;
#[test]
fn test_search_command_finds_files() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(temp_dir.path().join("auth.rs"), "fn authenticate() {}").unwrap();
std::fs::write(temp_dir.path().join("main.rs"), "// No auth here").unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg("search")
.arg("authenticate")
.arg(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains("auth.rs"))
.stdout(predicate::str::contains("authenticate"));
}
#[test]
fn test_search_command_auto_enables_semantic_flags() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join("main.rs"),
r#"
use auth::login;
fn main() {
login("user", "pass");
}
"#,
)
.unwrap();
std::fs::write(
temp_dir.path().join("auth.rs"),
r#"
pub fn login(username: &str, password: &str) -> bool {
// login logic
true
}
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg("search")
.arg("login")
.arg(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains("main.rs")) .stdout(predicate::str::contains("auth.rs")) .stdout(predicate::str::contains("Function calls: login")) .stdout(predicate::str::contains("Type references: login")); }
#[test]
fn test_search_command_no_semantic_flag() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(temp_dir.path().join("test.rs"), "login();").unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg("search")
.arg("login")
.arg("--no-semantic")
.arg(temp_dir.path())
.assert()
.success();
}