difflore_core/infra/
paths.rs1use std::path::PathBuf;
2
3pub fn data_home() -> Result<PathBuf, String> {
6 crate::infra::db::difflore_dir()
7}
8
9pub fn config_home() -> Result<PathBuf, String> {
12 data_home()
13}
14
15pub fn config_file() -> Result<PathBuf, String> {
17 Ok(config_home()?.join("config.toml"))
18}
19
20pub use crate::infra::db::current_project_root;
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn data_home_resolves_to_existing_dir_under_test_home() {
29 let home = data_home().expect("data_home should resolve in tests");
34 assert!(home.is_absolute(), "expected absolute path, got {home:?}");
35 }
36
37 #[test]
38 fn config_home_equals_data_home() {
39 assert_eq!(config_home().unwrap(), data_home().unwrap());
40 }
41
42 #[test]
43 fn config_file_is_config_toml_under_config_home() {
44 let cfg = config_file().unwrap();
45 assert_eq!(cfg.file_name().unwrap(), "config.toml");
46 assert!(cfg.starts_with(config_home().unwrap()));
47 }
48
49 #[test]
50 fn current_project_root_returns_path() {
51 let p = current_project_root();
53 assert!(!p.as_os_str().is_empty());
54 }
55}