From ccce3c3db5ce9f59d52012c0a0e22988de2f9b9a Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Wed, 4 Jan 2023 00:51:51 -0700 Subject: [PATCH] test: Add test for opting out of Vec> derive --- tests/derive/occurrences.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/derive/occurrences.rs b/tests/derive/occurrences.rs index 8b2d8f2bc19..c8cbb9e37ab 100644 --- a/tests/derive/occurrences.rs +++ b/tests/derive/occurrences.rs @@ -17,6 +17,28 @@ fn test_vec_of_vec() { ); } +#[test] +fn test_vec_of_vec_opt_out() { + fn parser(s: &str) -> Result>, 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>, + } + + 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)]