#[test]
fn control_mode_line() {
use crate::control_mode::control_mode::{ControlModeLine, Response};
#[cfg(feature = "tmux_1_8")]
{
let output = "%begin 1618054308 777 1".control_mode_line().unwrap();
assert_eq!(
Response::OutputBlockBegin {
time: 1618054308,
num: 777,
flags: 1
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%end 1618054308 777 1".control_mode_line().unwrap();
assert_eq!(
Response::OutputBlockEnd {
time: 1618054308,
num: 777,
flags: 1
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%error 1618054308 777 1".control_mode_line().unwrap();
assert_eq!(
Response::OutputBlockError {
time: 1618054308,
num: 777,
flags: 1
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "1".control_mode_line().unwrap();
assert_eq!(Response::OutputBlockData("1".to_string()), output);
}
#[cfg(feature = "tmux_3_2")]
{
let output = "%client-detached 1".control_mode_line().unwrap();
assert_eq!(Response::ClientDetached("1".to_string()), output);
}
#[cfg(feature = "tmux_2_4")]
{
let output = "%client-session-changed 1 2 3".control_mode_line().unwrap();
assert_eq!(
Response::ClientSessionChanged {
client: "1".to_string(),
session_id: "2".to_string(),
name: "3".to_string()
},
output
);
}
#[cfg(feature = "tmux_3_4")]
{
let output = "%config-error 1".control_mode_line().unwrap();
assert_eq!(Response::ConfigError("1".to_string()), output);
}
#[cfg(feature = "tmux_3_2")]
{
let output = "%continue 1".control_mode_line().unwrap();
assert_eq!(Response::Continue("1".to_string()), output);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%exit 1".control_mode_line().unwrap();
assert_eq!(Response::Exit(Some("1".to_string())), output);
let output = "%exit".control_mode_line().unwrap();
assert_eq!(Response::Exit(None), output);
}
#[cfg(feature = "tmux_3_2")]
{
let output = "%extended-output 1 2 3 : 4".control_mode_line().unwrap();
assert_eq!(
Response::ExtendedOutput {
pane_id: "1".to_string(),
age: "2".to_string(),
reserved: vec!["3".to_string()],
value: "4".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
#[cfg(all(feature = "tmux_1_8", not(feature = "tmux_2_2")))]
let output = "%layout-change 1 2".control_mode_line().unwrap();
#[cfg(feature = "tmux_2_2")]
let output = "%layout-change 1 2 3 4".control_mode_line().unwrap();
assert_eq!(
Response::LayoutChange {
window_id: "1".to_string(),
window_layout: "2".to_string(),
#[cfg(feature = "tmux_2_2")]
window_visible_layout: "3".to_string(),
#[cfg(feature = "tmux_2_2")]
window_flags: "4".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%output 1 2 3".control_mode_line().unwrap();
assert_eq!(
Response::Output {
pane_id: "1".to_string(),
value: "2 3".to_string()
},
output
);
}
#[cfg(feature = "tmux_2_5")]
{
let output = "%pane-mode-changed 1".control_mode_line().unwrap();
assert_eq!(Response::PaneModeChanged("1".to_string()), output);
}
#[cfg(feature = "tmux_3_2")]
{
let output = "%pause 1".control_mode_line().unwrap();
assert_eq!(Response::Pause("1".to_string()), output);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%session-changed $1 2".control_mode_line().unwrap();
assert_eq!(
Response::SessionChanged {
session_id: "$1".to_string(),
name: "2".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%session-renamed 1 2".control_mode_line().unwrap();
assert_eq!(Response::SessionRenamed("1 2".to_string()), output);
}
#[cfg(feature = "tmux_2_5")]
{
let output = "%session-window-changed 1 2".control_mode_line().unwrap();
assert_eq!(
Response::SessionWindowChanged {
session_id: "1".to_string(),
window_id: "2".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%sessions-changed".control_mode_line().unwrap();
assert_eq!(Response::SessionsChanged, output);
}
#[cfg(feature = "tmux_3_2")]
{
let output = "%subscription-changed 1 2 3 4".control_mode_line().unwrap();
assert_eq!(
Response::SubscriptionChanged {
name: "1".to_string(),
session_id: "2".to_string(),
window_id: "3".to_string(),
window_index: "4".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%unlinked-window-add 1".control_mode_line().unwrap();
assert_eq!(Response::UnlinkedWindowAdd("1".to_string()), output);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%window-add 1".control_mode_line().unwrap();
assert_eq!(Response::WindowAdd("1".to_string()), output);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%window-close 1".control_mode_line().unwrap();
assert_eq!(Response::WindowClose("1".to_string()), output);
}
#[cfg(feature = "tmux_2_5")]
{
let output = "%window-pane-changed 1 2".control_mode_line().unwrap();
assert_eq!(
Response::WindowPaneChanged {
window_id: "1".to_string(),
pane_id: "2".to_string()
},
output
);
}
#[cfg(feature = "tmux_1_8")]
{
let output = "%window-renamed 1 2 3".control_mode_line().unwrap();
assert_eq!(
Response::WindowRenamed {
window_id: "1".to_string(),
name: "2 3".to_string()
},
output
);
}
}
#[test]
fn next() {
use crate::control_mode::control_mode::{ControlModeOutput, OutputBlock, Response};
use std::io::{BufRead, BufReader};
let s = "%begin 1618081916 17688 1\n0: 3 windows (created Sat Apr 10 13:01:08 2021) (attached)\n%end 1618081916 17688 1\n%session-changed $0 0";
let s = BufReader::new(s.as_bytes());
let lines = s.lines();
let mut cm_mode_lines = ControlModeOutput::new(lines);
let cm_mode_line = cm_mode_lines.next().unwrap();
let output_block = Response::OutputBlock(OutputBlock {
time: 1618081916,
num: 17688,
flags: 1,
success: true,
data: Some("0: 3 windows (created Sat Apr 10 13:01:08 2021) (attached)".to_string()),
});
assert_eq!(cm_mode_line, output_block);
let cm_mode_line = cm_mode_lines.next().unwrap();
let output_block = Response::SessionChanged {
session_id: "$0".to_string(),
name: "0".to_string(),
};
assert_eq!(cm_mode_line, output_block);
}
#[test]
fn for_loop() {
use crate::control_mode::control_mode::{ControlModeOutput, Response};
use std::io::{BufRead, BufReader};
let s = "%begin 1618081916 17688 0\n%end 1618081916 17688 0\n%session-changed $0 0";
let s = BufReader::new(s.as_bytes());
let lines = s.lines();
let cm_mode_lines = ControlModeOutput::new(lines);
for cm_mode_line in cm_mode_lines {
match cm_mode_line {
Response::OutputBlock(_) => {}
Response::SessionChanged { session_id, name } => {}
_ => {}
}
}
}