#![cfg(test)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
#[test]
fn test_context_builder_module_can_be_imported() {
let temp_dir = TempDir::new().unwrap();
fs::write(
temp_dir.path().join("test.rs"),
r#"
fn main() {
println!("Hello, world!");
}
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg(temp_dir.path())
.arg("--quiet")
.assert()
.success()
.stdout(predicate::str::contains("# Code Context"));
}
#[test]
fn test_context_options_struct_works() {
let temp_dir = TempDir::new().unwrap();
fs::write(
temp_dir.path().join("test.py"),
r#"
def hello():
print("Hello, world!")
"#,
)
.unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg(temp_dir.path())
.arg("--max-tokens")
.arg("10000")
.arg("--quiet")
.assert()
.success()
.stdout(predicate::str::contains("test.py"));
}
#[test]
fn test_all_core_modules_resolve_correctly() {
let temp_dir = TempDir::new().unwrap();
fs::write(temp_dir.path().join("test.rs"), "fn main() {}").unwrap();
fs::write(temp_dir.path().join("test.py"), "print('hello')").unwrap();
fs::write(temp_dir.path().join("test.js"), "console.log('hello');").unwrap();
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg(temp_dir.path())
.arg("--quiet")
.assert()
.success()
.stdout(predicate::str::contains("test.rs"))
.stdout(predicate::str::contains("test.py"))
.stdout(predicate::str::contains("test.js"));
}
#[test]
fn test_crate_name_in_error_messages() {
let mut cmd = Command::cargo_bin("context-creator").unwrap();
cmd.arg("--invalid-flag")
.assert()
.failure()
.stderr(predicate::str::contains("context-creator").or(predicate::str::contains("error")));
}