use super::*;
use tempfile::TempDir;
fn worktree(config: Option<&str>) -> TempDir {
let root = TempDir::new().unwrap();
if let Some(config) = config {
std::fs::create_dir_all(root.path().join(".wsb")).unwrap();
std::fs::write(root.path().join(FILE), config).unwrap();
}
root
}
#[test]
fn a_declared_family_is_its_members() {
let root = worktree(Some(r#"{"parity_families": {"lib": ["lib/lib-rs", "lib/lib-js"]}}"#));
assert_eq!(
members(root.path(), "lib").unwrap(),
vec!["lib/lib-rs".to_string(), "lib/lib-js".to_string()]
);
}
#[test]
fn an_undeclared_family_names_the_ones_that_are() {
let root = worktree(Some(r#"{"parity_families": {"lib": ["a"], "other": ["b"]}}"#));
let said = format!("{:#}", members(root.path(), "nope").unwrap_err());
assert!(said.contains("'nope'"), "{said}");
assert!(said.contains("lib, other"), "{said}");
}
#[test]
fn a_workspace_with_no_configuration_declares_no_family() {
let root = worktree(None);
assert!(declared(root.path()).unwrap().is_empty());
let said = format!("{:#}", members(root.path(), "lib").unwrap_err());
assert!(said.contains("names none"), "{said}");
}
#[test]
fn an_unknown_key_is_refused() {
let root = worktree(Some(r#"{"parity": {}}"#));
let said = format!("{:#}", declared(root.path()).unwrap_err());
assert!(said.contains("unknown field"), "{said}");
}