use super::*;
use crate::config_edit::brazen::BrazenPaths;
fn ambient() -> Env {
Env::from_pairs([
("HOME", "/h"),
("XDG_DATA_HOME", "/d"),
(YOG_WALL, "/stale/wall"),
])
}
#[test]
fn the_wall_is_the_world_root_plus_the_workspace_leaf() {
let world = crate::world::compose(&ambient());
assert_eq!(walls_dir(Path::new("/w")), PathBuf::from("/w/walls"));
assert_eq!(
root(&world, "corp"),
PathBuf::from("/d/yog/world/walls/corp")
);
assert_eq!(
root_under(Path::new("/w"), "corp"),
PathBuf::from("/w/walls/corp")
);
assert_eq!(
root_of(&world, Path::new("/d/yog/workspaces/corp")),
PathBuf::from("/d/yog/world/walls/corp")
);
assert_eq!(
root_of(&world, Path::new("/elsewhere/litany/workspaces/a1b2")),
PathBuf::from("/d/yog/world/walls/a1b2")
);
}
#[test]
fn the_lens_replaces_a_standing_wall_and_is_idempotent() {
let world = crate::world::compose(&ambient());
let corp = env(&world, Path::new("/ws/corp"));
assert_eq!(corp.wall(), Some(PathBuf::from("/d/yog/world/walls/corp")));
let home = env(&corp, Path::new("/ws/home"));
assert_eq!(home.wall(), Some(PathBuf::from("/d/yog/world/walls/home")));
assert_eq!(env(&corp, Path::new("/ws/corp")).wall(), corp.wall());
assert_eq!(corp.yog_data_root(), world.yog_data_root());
}
#[test]
fn no_focus_is_no_wall_and_no_brazen_paths() {
let world = crate::world::compose(&ambient());
let none = env_opt(&world, None);
assert_eq!(none.wall(), None);
assert_eq!(BrazenPaths::of(&none), None);
assert!(pairs_of(&none).is_empty());
let ws = Path::new("/ws/corp");
assert_eq!(env_opt(&world, Some(ws)).wall(), env(&world, ws).wall());
}
#[test]
fn the_spawn_layer_and_the_read_lens_name_one_path() {
let world = crate::world::compose(&ambient());
let ws = Path::new("/ws/corp");
let lensed = env(&world, ws);
assert_eq!(pairs(&world, ws), pairs_of(&lensed));
assert_eq!(
pairs(&world, ws),
vec![(YOG_WALL.to_owned(), "/d/yog/world/walls/corp".to_owned())]
);
}
#[test]
fn brazen_folds_land_inside_the_wall_and_nowhere_ambient() {
let ambient = Env::from_pairs([
("HOME", "/h"),
("XDG_DATA_HOME", "/d"),
("XDG_CONFIG_HOME", "/cfg"),
("XDG_CACHE_HOME", "/cache"),
("BRAZEN_CONFIG", "/ambient/brazen.toml"),
]);
let world = crate::world::compose(&ambient);
let paths = BrazenPaths::of(&env(&world, Path::new("/ws/corp"))).expect("a focused wall");
assert_eq!(
paths,
BrazenPaths {
config: PathBuf::from("/d/yog/world/walls/corp/brazen/config.toml"),
credentials_dir: PathBuf::from("/d/yog/world/walls/corp/brazen/credentials"),
models_cache_dir: PathBuf::from("/d/yog/world/walls/corp/brazen/models"),
}
);
let other = BrazenPaths::of(&env(&world, Path::new("/ws/home"))).expect("a focused wall");
assert_ne!(paths.config, other.config);
assert_ne!(paths.credentials_dir, other.credentials_dir);
assert_ne!(paths.models_cache_dir, other.models_cache_dir);
}