use bkmr::config::{create_file_path_with_base, has_base_path, resolve_file_path, Settings};
use std::collections::HashMap;
#[test]
fn test_base_path_configuration() {
let mut base_paths = HashMap::new();
base_paths.insert("SCRIPTS_HOME".to_string(), "$HOME/scripts".to_string());
base_paths.insert("DOCS_HOME".to_string(), "/home/user/documents".to_string());
let settings = Settings {
db_url: "test.db".to_string(),
fzf_opts: Default::default(),
shell_opts: Default::default(),
base_paths,
embeddings: Default::default(),
config_source: Default::default(),
};
assert!(has_base_path(&settings, "SCRIPTS_HOME"));
assert!(has_base_path(&settings, "DOCS_HOME"));
assert!(!has_base_path(&settings, "NONEXISTENT"));
let relative_path = create_file_path_with_base("SCRIPTS_HOME", "backup/daily.sh");
assert_eq!(relative_path, "$SCRIPTS_HOME/backup/daily.sh");
let resolved = resolve_file_path(&settings, "$DOCS_HOME/readme.md");
assert_eq!(resolved, "/home/user/documents/readme.md");
}
#[test]
fn test_base_path_usage_examples() {
let mut base_paths = HashMap::new();
base_paths.insert("SCRIPTS_HOME".to_string(), "$HOME/scripts".to_string());
let settings = Settings {
db_url: "test.db".to_string(),
fzf_opts: Default::default(),
shell_opts: Default::default(),
base_paths,
embeddings: Default::default(),
config_source: Default::default(),
};
let _ = resolve_file_path(&settings, "$HOME/scripts");
let _ = "backup";
let stored_path = create_file_path_with_base("SCRIPTS_HOME", "backup/daily.sh");
assert_eq!(stored_path, "$SCRIPTS_HOME/backup/daily.sh");
}
#[test]
fn test_environment_variable_expansion() {
let mut base_paths = HashMap::new();
base_paths.insert("TEST_HOME".to_string(), "$HOME/test".to_string());
let settings = Settings {
db_url: "test.db".to_string(),
fzf_opts: Default::default(),
shell_opts: Default::default(),
base_paths,
embeddings: Default::default(),
config_source: Default::default(),
};
let resolved = resolve_file_path(&settings, "$TEST_HOME/file.txt");
assert!(resolved.contains("/test/file.txt"));
assert!(!resolved.contains("$HOME"));
assert!(!resolved.contains("$TEST_HOME"));
}