use super::*;
use crate::opslog::Origin;
use crate::start::Prepared;
fn shapes(named: &str) -> Vec<Gesture> {
let prepared = Prepared {
workspace: named.to_owned(),
binding: None,
goal: String::new(),
origin: Origin::Conversation,
};
vec![
Gesture::Act(Action::Scan {
workspace: named.to_owned(),
}),
Gesture::Act(Action::Monitor(crate::monitor::Verb::Disarm {
workspace: named.to_owned(),
})),
Gesture::Act(Action::Fleet(crate::fleet::Verb::Disarm {
workspace: named.to_owned(),
})),
Gesture::Act(Action::Prompt {
prepared,
goal: String::new(),
seed: None,
}),
Gesture::Ask(Query::Conversations {
workspace: named.to_owned(),
}),
]
}
#[test]
fn a_gesture_that_names_a_workspace_carries_the_new_name_after_the_rewrite() {
for (gesture, already) in shapes("leaf").into_iter().zip(shapes("host")) {
assert_eq!(gesture.workspace().as_deref(), Some("leaf"), "{gesture:?}");
let crossing = gesture.with_workspace("host");
assert_eq!(
crossing.workspace().as_deref(),
Some("host"),
"{crossing:?}"
);
assert_eq!(crossing, already, "only the name changed");
}
}
#[test]
fn a_gesture_naming_no_workspace_is_unchanged() {
for gesture in [
Gesture::Act(Action::Ack),
Gesture::Act(Action::Advertise { tools: Vec::new() }),
Gesture::Ask(Query::Workspaces),
Gesture::Ask(Query::Invocations),
] {
assert_eq!(gesture.workspace(), None, "{gesture:?}");
assert_eq!(gesture.clone().with_workspace("host"), gesture);
}
}
#[test]
fn reading_the_name_leaves_the_gesture_holding_it() {
let gesture = Gesture::Act(Action::Scan {
workspace: "leaf".to_owned(),
});
assert_eq!(gesture.workspace().as_deref(), Some("leaf"));
assert_eq!(gesture.workspace().as_deref(), Some("leaf"));
}