mod utils; use clap::{Args, Parser}; #[test] fn generic_struct_flatten() { #[derive(Args, PartialEq, Debug)] struct Inner { pub answer: isize, } #[derive(Parser, PartialEq, Debug)] struct Outer { #[clap(flatten)] pub inner: T, } assert_eq!( Outer { inner: Inner { answer: 42 } }, Outer::parse_from(&["--answer", "42"]) ) } #[test] fn generic_struct_flatten_w_where_clause() { #[derive(Args, PartialEq, Debug)] struct Inner { pub answer: isize, } #[derive(Parser, PartialEq, Debug)] struct Outer where T: Args, { #[clap(flatten)] pub inner: T, } assert_eq!( Outer { inner: Inner { answer: 42 } }, Outer::parse_from(&["--answer", "42"]) ) } #[test] fn generic_enum() { #[derive(Args, PartialEq, Debug)] struct Inner { pub answer: isize, } #[derive(Parser, PartialEq, Debug)] enum GenericEnum { Start(T), Stop, } assert_eq!( GenericEnum::Start(Inner { answer: 42 }), GenericEnum::parse_from(&["test", "start", "42"]) ) } #[test] fn generic_enum_w_where_clause() { #[derive(Args, PartialEq, Debug)] struct Inner { pub answer: isize, } #[derive(Parser, PartialEq, Debug)] enum GenericEnum where T: Args, { Start(T), Stop, } assert_eq!( GenericEnum::Start(Inner { answer: 42 }), GenericEnum::parse_from(&["test", "start", "42"]) ) } #[test] fn generic_w_fromstr_trait_bound() { use std::str::FromStr; #[derive(Parser, PartialEq, Debug)] struct Opt where T: FromStr, ::Err: std::error::Error + Sync + Send + 'static, { answer: T, } assert_eq!( Opt:: { answer: 42 }, Opt::::parse_from(&["--answer", "42"]) ) } #[test] fn generic_wo_trait_bound() { use std::time::Duration; #[derive(Parser, PartialEq, Debug)] struct Opt { answer: isize, #[clap(skip)] took: Option, } assert_eq!( Opt:: { answer: 42, took: None }, Opt::::parse_from(&["--answer", "42"]) ) } #[test] fn generic_where_clause_w_trailing_comma() { use std::str::FromStr; #[derive(Parser, PartialEq, Debug)] struct Opt where T: FromStr, ::Err: std::error::Error + Sync + Send + 'static, { pub answer: T, } assert_eq!( Opt:: { answer: 42 }, Opt::::parse_from(&["--answer", "42"]) ) }