Skip to content

Commit

Permalink
test: Add test for opting out of Vec<Vec<T>> derive
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Jan 4, 2023
1 parent 710b1e2 commit c3ac5b6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/derive/occurrences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ fn test_vec_of_vec() {
);
}

#[test]
fn test_vec_of_vec_opt_out() {
fn parser(s: &str) -> Result<Vec<Vec<String>>, std::convert::Infallible> {
Ok(s.split(':')
.map(|v| v.split(',').map(str::to_owned).collect())
.collect())
}

#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[arg(value_parser = parser, short = 'p')]
arg: ::std::vec::Vec<Vec<String>>,
}

assert_eq!(
Opt {
arg: vec![vec!["1".into(), "2".into()], vec!["a".into(), "b".into()]],
},
Opt::try_parse_from(["test", "-p", "1,2:a,b"]).unwrap(),
);
}

#[test]
fn test_vec_vec_empty() {
#[derive(Parser, Debug, PartialEq)]
Expand Down

0 comments on commit c3ac5b6

Please sign in to comment.