#[macro_export]
macro_rules! load_buffer {
(@cmd ($cmd:expr) -w, $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({
$cmd.send_to_clipboard()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -b $buffer:expr, $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({
#[cfg(feature = "tmux_2_0")]
{
$cmd.buffer_name($buffer)
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
{
$cmd.buffer_index($buffer)
}
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_client:expr, $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({
$cmd.target_client($target_client)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({
$cmd.target_session($target_session)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $path:expr, $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({
$cmd.path($path)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::LoadBuffer::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::load_buffer!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::load_buffer!(@cmd ({ $crate::LoadBuffer::new() }) $($tail)*,)
}};
}
#[test]
fn load_buffer_macro() {
use std::borrow::Cow;
let load_buffer = load_buffer!();
#[cfg(feature = "tmux_3_2")]
let load_buffer = load_buffer!((load_buffer), -w);
#[cfg(feature = "tmux_2_0")]
let load_buffer = load_buffer!((load_buffer), -b "1");
#[cfg(feature = "tmux_3_2")]
let load_buffer = load_buffer!((load_buffer), -t "2");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
let load_buffer = load_buffer!((load_buffer), -b "3");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
let load_buffer = load_buffer!((load_buffer), -t "4");
#[cfg(feature = "tmux_0_8")]
let load_buffer = load_buffer!((load_buffer), "5");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "load-buffer";
#[cfg(feature = "cmd_alias")]
let cmd = "loadb";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_3_2")]
s.push("-w");
#[cfg(feature = "tmux_2_0")]
s.extend_from_slice(&["-b", "1"]);
#[cfg(feature = "tmux_3_2")]
s.extend_from_slice(&["-t", "2"]);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
s.extend_from_slice(&["-b", "3"]);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
s.extend_from_slice(&["-t", "4"]);
#[cfg(feature = "tmux_0_8")]
s.push("5");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let load_buffer = load_buffer.build().to_vec();
assert_eq!(load_buffer, s);
}