1#![cfg(feature = "unstable-v5")]
2use clap::Parser;
3
4#[test]
5fn test_vec_of_vec() {
6    #[derive(Parser, Debug, PartialEq)]
7    struct Opt {
8        #[arg(short = 'p', num_args = 2)]
9        points: Vec<Vec<i32>>,
10    }
11
12    assert_eq!(
13        Opt {
14            points: vec![vec![1, 2], vec![0, 0]]
15        },
16        Opt::try_parse_from(&["test", "-p", "1", "2", "-p", "0", "0"]).unwrap()
17    );
18}
19
20#[test]
21fn test_vec_of_vec_opt_out() {
22    fn parser(s: &str) -> Result<Vec<String>, std::convert::Infallible> {
23        Ok(s.split(',').map(str::to_owned).collect())
24    }
25
26    #[derive(Parser, PartialEq, Debug)]
27    struct Opt {
28        #[arg(value_parser = parser, short = 'p')]
29        arg: Vec<::std::vec::Vec<String>>,
30    }
31
32    assert_eq!(
33        Opt {
34            arg: vec![vec!["1".into(), "2".into()], vec!["a".into(), "b".into()]],
35        },
36        Opt::try_parse_from(["test", "-p", "1,2", "-p", "a,b"]).unwrap(),
37    );
38}
39
40#[test]
41fn test_vec_vec_empty() {
42    #[derive(Parser, Debug, PartialEq)]
43    struct Opt {
44        #[arg(short = 'p', num_args = 2)]
45        points: Vec<Vec<i32>>,
46    }
47
48    assert_eq!(
49        Opt { points: vec![] },
50        Opt::try_parse_from(&["test"]).unwrap()
51    );
52}
53
54#[test]
55fn test_option_vec_vec() {
56    #[derive(Parser, Debug, PartialEq)]
57    struct Opt {
58        #[arg(short = 'p', num_args = 2)]
59        points: Option<Vec<Vec<i32>>>,
60    }
61
62    assert_eq!(
63        Opt {
64            points: Some(vec![vec![1, 2], vec![3, 4]])
65        },
66        Opt::try_parse_from(&["test", "-p", "1", "2", "-p", "3", "4"]).unwrap()
67    );
68}
69
70#[test]
71fn test_option_vec_vec_empty() {
72    #[derive(Parser, Debug, PartialEq)]
73    struct Opt {
74        #[arg(short = 'p', num_args = 2)]
75        points: Option<Vec<Vec<i32>>>,
76    }
77
78    assert_eq!(
79        Opt { points: None },
80        Opt::try_parse_from(&["test"]).unwrap()
81    );
82}
83