tmux_interface/commands/buffers/
list_buffers_macro.rs1#[macro_export]
23macro_rules! list_buffers {
24 (@cmd ($cmd:expr) -F $format:expr, $($tail:tt)*) => {{
25 $crate::list_buffers!(@cmd ({
26 $cmd.format($format)
27 }) $($tail)*)
28 }};
29 (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
30 $crate::list_buffers!(@cmd ({
31 $cmd.target_session($target_session)
32 }) $($tail)*)
33 }};
34 (@cmd ($cmd:expr)) => {{
38 $cmd
39 }};
40 () => {{
41 $crate::ListBuffers::new()
42 }};
43 (($cmd:expr), $($tail:tt)*) => {{
44 $crate::list_buffers!(@cmd ($cmd) $($tail)*,)
45 }};
46 ($($tail:tt)*) => {{
47 $crate::list_buffers!(@cmd ({ $crate::ListBuffers::new() }) $($tail)*,)
48 }};
49}
50
51#[test]
52fn list_buffers_macro() {
53 use std::borrow::Cow;
54
55 let list_buffers = list_buffers!();
77 #[cfg(feature = "tmux_1_7")]
78 let list_buffers = list_buffers!((list_buffers), -F "1");
79 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
80 let list_buffers = list_buffers!((list_buffers), -t "2");
81
82 #[cfg(not(feature = "cmd_alias"))]
83 let cmd = "list-buffers";
84 #[cfg(feature = "cmd_alias")]
85 let cmd = "lsb";
86
87 let mut s: Vec<&str> = Vec::new();
88 #[cfg(any(
89 all(feature = "tmux_0_8", not(feature = "tmux_1_5")),
90 feature = "tmux_1_7"
91 ))]
92 s.push(cmd);
93 #[cfg(feature = "tmux_1_7")]
94 s.extend_from_slice(&["-F", "1"]);
95 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
96 s.extend_from_slice(&["-t", "2"]);
97 #[cfg(any(
98 all(feature = "tmux_0_8", not(feature = "tmux_1_5")),
99 feature = "tmux_1_7"
100 ))]
101 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
102
103 let list_buffers = list_buffers.build().to_vec();
104
105 assert_eq!(list_buffers, s);
106}