use tmuxctl::{Engine, Incoming, Notification, PaneId, WindowId};
fn notifications(bytes: &[u8]) -> Vec<Notification> {
let mut engine = Engine::new();
engine
.feed(bytes)
.into_iter()
.filter_map(|incoming| match incoming {
Incoming::Notification(notification) => Some(notification),
Incoming::Reply { .. } => None,
})
.collect()
}
#[test]
fn structural_session_replays_to_expected_notifications() {
let fixture = include_bytes!("fixtures/structural-session.txt");
let notes = notifications(fixture);
let unknown: Vec<_> = notes
.iter()
.filter(|n| matches!(n, Notification::Unknown(_)))
.collect();
assert!(unknown.is_empty(), "unparsed lines: {unknown:?}");
let has = |want: &Notification| notes.iter().any(|n| n == want);
assert!(has(&Notification::WindowAdd(WindowId(0))));
assert!(has(&Notification::SessionsChanged));
assert!(has(&Notification::SessionChanged(
tmuxctl::SessionId(0),
"cap".to_string()
)));
assert!(has(&Notification::UnlinkedWindowAdd(WindowId(1))));
assert!(has(&Notification::WindowPaneChanged {
window: WindowId(1),
pane: PaneId(2),
}));
assert!(has(&Notification::UnlinkedWindowRenamed(
WindowId(1),
"fixture".to_string()
)));
assert!(has(&Notification::UnlinkedWindowClose(WindowId(1))));
assert!(has(&Notification::Exit(None)));
assert!(
notes
.iter()
.any(|n| matches!(n, Notification::WindowRenamed(WindowId(0), _))),
"expected an initial %window-renamed for @0"
);
assert_eq!(notes.len(), 11, "stream drifted: {notes:?}");
}