use std::path::PathBuf;
pub fn data_home() -> Result<PathBuf, String> {
crate::infra::db::difflore_dir()
}
pub fn config_home() -> Result<PathBuf, String> {
data_home()
}
pub fn config_file() -> Result<PathBuf, String> {
Ok(config_home()?.join("config.toml"))
}
pub use crate::infra::db::current_project_root;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn data_home_resolves_to_existing_dir_under_test_home() {
let home = data_home().expect("data_home should resolve in tests");
assert!(home.is_absolute(), "expected absolute path, got {home:?}");
}
#[test]
fn config_home_equals_data_home() {
assert_eq!(config_home().unwrap(), data_home().unwrap());
}
#[test]
fn config_file_is_config_toml_under_config_home() {
let cfg = config_file().unwrap();
assert_eq!(cfg.file_name().unwrap(), "config.toml");
assert!(cfg.starts_with(config_home().unwrap()));
}
#[test]
fn current_project_root_returns_path() {
let p = current_project_root();
assert!(!p.as_os_str().is_empty());
}
}