1 
2 use structopt::StructOpt;
3 
4 #[test]
generic_struct_flatten()5 fn generic_struct_flatten() {
6 
7     #[derive(StructOpt,PartialEq,Debug)]
8     struct Inner{
9         pub answer: isize
10     }
11 
12     #[derive(StructOpt,PartialEq,Debug)]
13     struct Outer<T:StructOpt>{
14         #[structopt(flatten)]
15         pub inner: T
16     }
17 
18     assert_eq!(
19         Outer{inner: Inner{ answer: 42 }},
20         Outer::from_iter(&[ "--answer",  "42" ])
21     )
22 }
23 
24 #[test]
generic_struct_flatten_w_where_clause()25 fn generic_struct_flatten_w_where_clause() {
26 
27     #[derive(StructOpt,PartialEq,Debug)]
28     struct Inner{
29         pub answer: isize
30     }
31 
32     #[derive(StructOpt,PartialEq,Debug)]
33     struct Outer<T> where T:StructOpt {
34         #[structopt(flatten)]
35         pub inner: T
36     }
37 
38     assert_eq!(
39         Outer{inner: Inner{ answer: 42 }},
40         Outer::from_iter(&[ "--answer",  "42" ])
41     )
42 }
43 
44 #[test]
generic_enum()45 fn generic_enum() {
46 
47     #[derive(StructOpt,PartialEq,Debug)]
48     struct Inner{
49         pub answer: isize
50     }
51 
52     #[derive(StructOpt,PartialEq,Debug)]
53     enum GenericEnum<T: StructOpt> {
54 
55         Start(T),
56         Stop,
57     }
58 
59     assert_eq!(
60         GenericEnum::Start(Inner{answer: 42}),
61         GenericEnum::from_iter(&[ "test", "start", "42" ])
62     )
63 
64 }
65 
66 #[test]
generic_enum_w_where_clause()67 fn generic_enum_w_where_clause() {
68 
69     #[derive(StructOpt,PartialEq,Debug)]
70     struct Inner{
71         pub answer: isize
72     }
73 
74     #[derive(StructOpt,PartialEq,Debug)]
75     enum GenericEnum<T> where T: StructOpt {
76 
77         Start(T),
78         Stop,
79     }
80 
81     assert_eq!(
82         GenericEnum::Start(Inner{answer: 42}),
83         GenericEnum::from_iter(&[ "test", "start", "42" ])
84     )
85 
86 }
87 
88 #[test]
generic_w_fromstr_trait_bound()89 fn generic_w_fromstr_trait_bound() {
90 
91     use std::{fmt, str::FromStr};
92 
93     #[derive(StructOpt,PartialEq,Debug)]
94     struct Opt<T> where T:FromStr, <T as FromStr>::Err: fmt::Debug + fmt::Display
95     {
96         answer: T
97     }
98 
99     assert_eq!(
100         Opt::<isize>{answer:42},
101         Opt::<isize>::from_iter([& "--answer", "42" ])
102     )
103 }
104 
105 #[test]
generic_wo_trait_bound()106 fn generic_wo_trait_bound() {
107 
108     use std::time::Duration;
109 
110     #[derive(StructOpt,PartialEq,Debug)]
111     struct Opt<T> {
112         answer: isize,
113         #[structopt(skip)]
114         took: Option<T>
115     }
116 
117     assert_eq!(
118         Opt::<Duration>{answer:42,took:None},
119         Opt::<Duration>::from_iter([& "--answer", "42" ])
120     )
121 }
122 
123 #[test]
generic_where_clause_w_trailing_comma()124 fn generic_where_clause_w_trailing_comma() {
125 
126     use std::{fmt, str::FromStr};
127 
128     #[derive(StructOpt,PartialEq,Debug)]
129     struct Opt<T> where T:FromStr, <T as FromStr>::Err: fmt::Debug + fmt::Display {
130         pub answer: T
131     }
132 
133     assert_eq!(
134         Opt::<isize>{answer:42},
135         Opt::<isize>::from_iter(&[ "--answer", "42" ])
136     )
137 }
138