use crate::{AiBackend, AiError, Copilot, GenerateRequest, Ollama};
#[test]
fn ollama_name_is_correct() {
let ai = Ollama::new("llama3.2");
assert_eq!(ai.name(), "ollama");
}
#[test]
fn ollama_with_model_updates_model() {
let ai = Ollama::new("llama3.2").with_model("mistral");
assert_eq!(ai.model(), "mistral");
}
#[test]
fn ollama_with_bin_updates_bin() {
let ai = Ollama::new("llama3.2").with_bin("custom-ollama");
assert_eq!(ai.bin(), "custom-ollama");
}
#[test]
fn copilot_name_is_correct() {
let ai = Copilot::new();
assert_eq!(ai.name(), "copilot");
}
#[test]
fn copilot_default_works() {
let ai = Copilot::default();
assert_eq!(ai.name(), "copilot");
}
#[test]
fn copilot_with_bin_updates_bin() {
let ai = Copilot::new().with_bin("custom-copilot");
assert_eq!(ai.bin(), "custom-copilot");
}
#[test]
fn ollama_constructs() {
let _ = Ollama::new("mistral");
}
#[test]
fn copilot_constructs() {
let _ = Copilot::new();
}
#[test]
fn generate_request_can_hold_instructions() {
let req = crate::GenerateRequest {
instructions: Some("Be concise".into()),
prompt: "Hello".into(),
};
assert_eq!(req.instructions.as_deref(), Some("Be concise"));
assert_eq!(req.prompt, "Hello");
}
#[test]
fn generate_request_new_sets_no_instructions() {
let req = GenerateRequest::new("Hello");
assert_eq!(req.prompt, "Hello");
assert_eq!(req.instructions, None);
}
#[test]
fn generate_request_with_instructions_sets_instructions() {
let req = GenerateRequest::new("Hello").with_instructions("Be concise");
assert_eq!(req.prompt, "Hello");
assert_eq!(req.instructions.as_deref(), Some("Be concise"));
}
#[test]
fn copilot_missing_binary_returns_io_error() {
let ai = Copilot::new().with_bin("definitely-not-a-real-copilot-binary");
let req = GenerateRequest::new("Hello");
let err = ai.generate(&req).unwrap_err();
assert!(matches!(err, AiError::Io(_)));
}
#[test]
fn ollama_missing_binary_returns_io_error() {
let ai = Ollama::new("llama3.2").with_bin("definitely-not-a-real-ollama-binary");
let req = GenerateRequest::new("Hello");
let err = ai.generate(&req).unwrap_err();
assert!(matches!(err, AiError::Io(_)));
}