use codebook_config::{CodebookConfig, CodebookConfigFile};
use std::fs;
use tempfile::TempDir;
#[test]
fn test_min_word_length_from_config() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("codebook.toml");
let config_content = r#"
dictionaries = ["en_us"]
min_word_length = 2
"#;
fs::write(&config_path, config_content).unwrap();
let config = CodebookConfigFile::load(Some(temp_dir.path())).unwrap();
assert_eq!(config.get_min_word_length(), 2);
}
#[test]
fn test_min_word_length_default() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("codebook.toml");
let config_content = r#"
dictionaries = ["en_us"]
"#;
fs::write(&config_path, config_content).unwrap();
let config = CodebookConfigFile::load(Some(temp_dir.path())).unwrap();
assert_eq!(config.get_min_word_length(), 3);
}
#[test]
fn test_min_word_length_with_global_config() {
let global_dir = TempDir::new().unwrap();
let project_dir = TempDir::new().unwrap();
let global_config_dir = global_dir.path().join("config");
fs::create_dir_all(&global_config_dir).unwrap();
let global_config_path = global_config_dir.join("codebook.toml");
let global_config_content = r#"
min_word_length = 4
"#;
fs::write(&global_config_path, global_config_content).unwrap();
let project_config_path = project_dir.path().join("codebook.toml");
let project_config_content = r#"
min_word_length = 2
"#;
fs::write(&project_config_path, project_config_content).unwrap();
unsafe {
std::env::set_var("XDG_CONFIG_HOME", global_dir.path());
}
let config = CodebookConfigFile::load(Some(project_dir.path())).unwrap();
assert_eq!(config.get_min_word_length(), 2);
unsafe {
std::env::remove_var("XDG_CONFIG_HOME");
}
}
#[test]
fn test_min_word_length_zero() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("codebook.toml");
let config_content = r#"
min_word_length = 0
"#;
fs::write(&config_path, config_content).unwrap();
let config = CodebookConfigFile::load(Some(temp_dir.path())).unwrap();
assert_eq!(config.get_min_word_length(), 0);
}
#[test]
fn test_min_word_length_large_value() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("codebook.toml");
let config_content = r#"
min_word_length = 10
"#;
fs::write(&config_path, config_content).unwrap();
let config = CodebookConfigFile::load(Some(temp_dir.path())).unwrap();
assert_eq!(config.get_min_word_length(), 10);
}