#[macro_export]
macro_rules! if_shell {
(@cmd ($cmd:expr) -b, $($tail:tt)*) => {{
$crate::if_shell!(@cmd ({
$cmd.background()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -F, $($tail:tt)*) => {{
$crate::if_shell!(@cmd ({
$cmd.not_execute()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_pane:expr, $($tail:tt)*) => {{
$crate::if_shell!(@cmd ({
$cmd.target_pane($target_pane)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $shell_command:expr, $($tail:tt)*) => {{
$crate::if_shell!(@cmd ({
$cmd.shell_command($shell_command)
}) $($tail)*)
}};
(@cmd ($cmd:expr) --command $command:expr, $($tail:tt)*) => {{
$crate::if_shell!(@cmd ({
$cmd.command($command)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::IfShell::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::if_shell!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::if_shell!(@cmd ({ $crate::IfShell::new() }) $($tail)*,)
}};
}
#[test]
fn if_shell_macro() {
use std::borrow::Cow;
let if_shell = if_shell!();
#[cfg(feature = "tmux_1_8")]
let if_shell = if_shell!((if_shell), -b);
#[cfg(feature = "tmux_2_0")]
let if_shell = if_shell!((if_shell), -F);
#[cfg(feature = "tmux_1_8")]
let if_shell = if_shell!((if_shell), -t "1");
#[cfg(feature = "tmux_1_5")]
let if_shell = if_shell!((if_shell), "2");
#[cfg(feature = "tmux_1_5")]
let if_shell = if_shell!((if_shell), --command "3");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "if-shell";
#[cfg(feature = "cmd_alias")]
let cmd = "if";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_1_8")]
s.push("-b");
#[cfg(feature = "tmux_2_0")]
s.push("-F");
#[cfg(feature = "tmux_1_8")]
s.extend_from_slice(&["-t", "1"]);
#[cfg(feature = "tmux_1_5")]
s.push("2");
#[cfg(feature = "tmux_1_5")]
s.push("3");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let if_shell = if_shell.build().to_vec();
assert_eq!(if_shell, s);
}