pub fn parent_cycle(parent: &str, child: &str) -> String {
format!("cycle detected: making {parent} a parent of {child} would create a cycle")
}
pub fn parent_self_reference(parent: &str) -> String {
format!("self-reference not allowed: {parent} cannot be its own parent")
}
pub fn parent_edge_not_found(parent: &str, child: &str) -> String {
format!(
"edge not found: no parent->child edge from {parent} to {child} to remove (use `parents {child}` to see existing parents)"
)
}
pub fn parent_duplicate(parent: &str, child: &str) -> String {
format!(
"edge already exists: {child} is already a child of {parent}; remove the existing edge first if you want to re-add it"
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parent_cycle_names_both_sides() {
let msg = parent_cycle("KAN-5", "KAN-7");
assert!(msg.contains("KAN-5"));
assert!(msg.contains("KAN-7"));
assert!(msg.contains("cycle"));
}
#[test]
fn test_parent_self_reference_names_the_card() {
let msg = parent_self_reference("KAN-5");
assert!(msg.contains("KAN-5"));
assert!(msg.to_lowercase().contains("self"));
}
#[test]
fn test_parent_edge_not_found_names_both_sides_and_hints_at_listing() {
let msg = parent_edge_not_found("KAN-5", "KAN-7");
assert!(msg.contains("KAN-5"));
assert!(msg.contains("KAN-7"));
assert!(msg.contains("parents"));
}
#[test]
fn test_parent_duplicate_names_both_sides() {
let msg = parent_duplicate("KAN-5", "KAN-7");
assert!(msg.contains("KAN-5"));
assert!(msg.contains("KAN-7"));
assert!(msg.to_lowercase().contains("already"));
}
}