#![allow(unused_imports)]
mod cascade;
mod integration;
use std::collections::HashMap;
use std::path::PathBuf;
use super::*;
use crate::handlers::{Handler, HandlerConfig, HandlerScope, HANDLER_SYMLINK};
use crate::operations::HandlerIntent;
use crate::packs::Pack;
use crate::paths::{Pather, XdgPather};
use crate::rules::RuleMatch;
pub(super) fn test_pather() -> XdgPather {
XdgPather::builder()
.home("/home/alice")
.dotfiles_root("/home/alice/dotfiles")
.xdg_config_home("/home/alice/.config")
.app_support_dir("/home/alice/Library/Application Support")
.build()
.unwrap()
}
pub(super) fn default_config() -> HandlerConfig {
HandlerConfig {
force_home: vec![
"ssh".into(),
"bashrc".into(),
"zshrc".into(),
"profile".into(),
],
protected_paths: vec![
".ssh/id_rsa".into(),
".ssh/id_ed25519".into(),
".gnupg".into(),
],
targets: std::collections::HashMap::new(),
..HandlerConfig::default()
}
}
#[test]
fn top_level_file_goes_to_pack_xdg_dir() {
let config = HandlerConfig::default();
let target = resolve_target("vim", "vimrc", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/vim/vimrc"));
}
#[test]
fn top_level_dir_goes_to_pack_xdg_dir() {
let config = HandlerConfig::default();
let target = resolve_target("nvim", "lua", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/nvim/lua"));
}
#[test]
fn top_level_dir_wholesale_goes_to_pack_xdg_dir() {
let config = HandlerConfig::default();
let target = resolve_target("warp", "themes", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/warp/themes"));
}
#[test]
fn prefixed_pack_deploys_under_display_name_dir() {
let config = HandlerConfig::default();
let target = resolve_target("010-nvim", "init.lua", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/nvim/init.lua"));
}
#[test]
fn prefixed_pack_works_with_underscore_separator() {
let config = HandlerConfig::default();
let target = resolve_target("020_zsh", "zshrc", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/zsh/zshrc"));
}
#[test]
fn prefixed_pack_with_force_home_still_strips_prefix() {
let target = resolve_target("030-net", "ssh/config", &default_config(), &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.ssh/config"));
}
#[test]
fn top_level_file_named_config_goes_under_pack_no_xdg_collision() {
let config = HandlerConfig::default();
let target = resolve_target("ghostty", "config", &config, &test_pather());
assert_eq!(target, PathBuf::from("/home/alice/.config/ghostty/config"));
}
#[test]
fn nested_file_namespaced_under_pack() {
let config = HandlerConfig::default();
let target = resolve_target("nvim", "lua/options.lua", &config, &test_pather());
assert_eq!(
target,
PathBuf::from("/home/alice/.config/nvim/lua/options.lua")
);
}
#[test]
fn protected_exact_match() {
assert!(is_protected("ssh/id_rsa", &[".ssh/id_rsa".into()]));
assert!(is_protected(".ssh/id_rsa", &[".ssh/id_rsa".into()]));
}
#[test]
fn protected_parent_directory() {
assert!(is_protected(
"gnupg/private-keys-v1.d/key",
&[".gnupg".into()]
));
}
#[test]
fn not_protected() {
assert!(!is_protected("vimrc", &[".ssh/id_rsa".into()]));
}
#[test]
fn force_home_matches_without_dot() {
assert!(is_force_home("ssh/config", &["ssh".into()]));
assert!(is_force_home("bashrc", &["bashrc".into()]));
}
#[test]
fn force_home_does_not_match_unrelated() {
assert!(!is_force_home("vimrc", &["ssh".into(), "bashrc".into()]));
}