use crate::start::identity::mint_conversation;
use crate::start::{identity_preview, parse_identity_stamp, strip_identity_stamp};
#[test]
fn the_preview_predicts_the_name_and_is_not_a_goal_line() {
let line = identity_preview(&[], &super::rng());
let name = line.strip_prefix("will be named ").expect("the prediction");
assert!(!name.is_empty() && !name.contains(char::is_whitespace));
assert!(
parse_identity_stamp(&line).is_none(),
"the preview no longer wears the retired stamp's shape"
);
assert!(!line.contains("--as"));
assert!(!line.contains("workspace"));
}
#[test]
fn parse_identity_stamp_reads_the_legacy_line_only() {
let goal = "You are cobalt-gecko.\n\nfree prose";
assert_eq!(parse_identity_stamp(goal).as_deref(), Some("cobalt-gecko"));
assert_eq!(parse_identity_stamp("hi\n\nYou are late."), None);
assert_eq!(parse_identity_stamp("just do the thing"), None);
assert_eq!(parse_identity_stamp("You are two words."), None);
assert_eq!(parse_identity_stamp("You are ."), None);
assert_eq!(parse_identity_stamp("You are cobalt-gecko"), None);
}
#[test]
fn strip_identity_stamp_gives_back_the_payload_the_stamp_was_prepended_to() {
let goal = "You are cobalt-gecko.\n\nBall bl-1: fix\n\nbody";
assert_eq!(strip_identity_stamp(goal), "Ball bl-1: fix\n\nbody");
assert_eq!(
strip_identity_stamp("just do the thing"),
"just do the thing"
);
assert_eq!(
strip_identity_stamp("hi\n\nYou are late."),
"hi\n\nYou are late."
);
assert_eq!(strip_identity_stamp("You are cobalt-gecko."), "");
}
#[test]
fn mint_conversation_skips_the_workspaces_occupied_names() {
let first = mint_conversation(&[], &super::rng()).unwrap();
assert!(!first.contains('-'), "one word, no compound (bl-d12f)");
let second = mint_conversation(std::slice::from_ref(&first), &super::rng()).unwrap();
assert_ne!(second, first, "an occupied name is scanned past");
}
#[test]
fn preview_and_fire_draw_the_one_litany_mint() {
let occupied = ["ash".to_owned(), "bay".to_owned()];
let fired = mint_conversation(&occupied, &super::rng()).unwrap();
assert_eq!(
identity_preview(&occupied, &super::rng()),
format!("will be named {fired}"),
"the prediction names the word the fire mints"
);
assert_eq!(
litany::mint::mint(&super::rng(), &occupied.iter().cloned().collect()).unwrap(),
fired,
"and that word is the crate's own draw — yog holds no second list"
);
assert!(!occupied.contains(&fired));
}