Skip to main content

commit_wizard/
lib.rs

1pub mod cli;
2pub mod core;
3pub mod engine;
4pub mod infra;
5
6/// A macro to create a vector of strings from a list of string literals.
7#[macro_export]
8macro_rules! strings {
9    ($($s:expr),* $(,)?) => {
10        vec![$($s.to_string()),*]
11    };
12}
13
14#[macro_export]
15macro_rules! string_vec_map {
16    (
17        $(
18            $key:expr => [$($val:expr),* $(,)?]
19        ),* $(,)?
20    ) => {{
21        let mut map = std::collections::BTreeMap::new();
22        $(
23            let vec = vec![$($val.to_string()),*];
24            map.insert($key.to_string(), vec);
25        )*
26        map
27    }};
28}
29
30#[cfg(test)]
31mod tests {
32
33    #[test]
34    fn strings_macro_works_as_expected() {
35        let result = strings!["hello", "world", "123"];
36        let expected = vec!["hello".to_string(), "world".to_string(), "123".to_string()];
37        assert_eq!(result, expected);
38    }
39
40    #[test]
41    fn string_vec_map_macro_works_as_expected() {
42        let result = string_vec_map! {
43            "a" => ["1", "2"],
44            "b" => ["3", "4"]
45        };
46        let mut expected = std::collections::BTreeMap::new();
47        expected.insert("a".to_string(), vec!["1".to_string(), "2".to_string()]);
48        expected.insert("b".to_string(), vec!["3".to_string(), "4".to_string()]);
49        assert_eq!(result, expected);
50    }
51}