tmux_interface/commands/buffers/
list_buffers_macro.rs

1/// List the global buffers.
2///
3/// # Manual
4///
5/// tmux ^1.7:
6/// ```text
7/// list-buffers [-F format]
8/// (alias: lsb)
9/// ```
10///
11/// tmux ^1.5:
12/// ```text
13/// list-buffers
14/// (alias: lsb)
15/// ```
16///
17/// tmux ^0.8:
18/// ```text
19/// list-buffers [-t target-session]
20/// (alias: lsb)
21/// ```
22#[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) -$unknown:tt, $($tail:tt)*) => {{
35        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
36    //}};
37    (@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    // List the global buffers.
56    //
57    // # Manual
58    //
59    // tmux ^1.7:
60    // ```text
61    // list-buffers [-F format]
62    // (alias: lsb)
63    // ```
64    //
65    // tmux ^1.5:
66    // ```text
67    // list-buffers
68    // (alias: lsb)
69    // ```
70    //
71    // tmux ^0.8:
72    // ```text
73    // list-buffers [-t target-session]
74    // (alias: lsb)
75    // ```
76    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}