use super::{data_root, root_of};
use std::ffi::OsString;
use std::path::PathBuf;
fn stated(text: &str) -> OsString {
OsString::from(text)
}
#[test]
fn the_xdg_variable_names_the_root_outright() {
assert_eq!(
root_of(Some(stated("/var/lib/app")), Some(stated("/home/u"))),
Ok(PathBuf::from("/var/lib/app/thrall"))
);
}
#[test]
fn without_it_the_root_is_the_convention_under_the_home_directory() {
assert_eq!(
root_of(None, Some(stated("/home/u"))),
Ok(PathBuf::from("/home/u/.local/share/thrall"))
);
}
#[test]
fn a_variable_with_no_value_has_said_nothing() {
assert_eq!(
root_of(Some(stated("")), Some(stated("/home/u"))),
Ok(PathBuf::from("/home/u/.local/share/thrall"))
);
assert!(root_of(Some(stated("")), Some(stated(""))).is_err());
}
#[test]
fn neither_variable_set_refuses_and_names_them_both() {
let refusal = root_of(None, None).expect_err("refused");
assert!(refusal.contains("XDG_DATA_HOME"), "{refusal}");
assert!(refusal.contains("HOME"), "{refusal}");
assert!(refusal.contains("will not guess"), "{refusal}");
}
#[test]
fn the_edge_read_is_the_rule_applied_to_this_process() {
assert_eq!(
data_root(),
root_of(std::env::var_os("XDG_DATA_HOME"), std::env::var_os("HOME"))
);
}