Skip to content

Commit

Permalink
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 81d7f0a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/derive/occurrences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ 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 81d7f0a

Please sign in to comment.