• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Internal
2 use args::settings::ArgSettings;
3 use args::Arg;
4 use map::VecMap;
5 use INTERNAL_ERROR_MSG;
6 
7 #[derive(PartialEq, Debug)]
8 enum UsageToken {
9     Name,
10     ValName,
11     Short,
12     Long,
13     Help,
14     Multiple,
15     Unknown,
16 }
17 
18 #[doc(hidden)]
19 #[derive(Debug)]
20 pub struct UsageParser<'a> {
21     usage: &'a str,
22     pos: usize,
23     start: usize,
24     prev: UsageToken,
25     explicit_name_set: bool,
26 }
27 
28 impl<'a> UsageParser<'a> {
new(usage: &'a str) -> Self29     fn new(usage: &'a str) -> Self {
30         debugln!("UsageParser::new: usage={:?}", usage);
31         UsageParser {
32             usage: usage,
33             pos: 0,
34             start: 0,
35             prev: UsageToken::Unknown,
36             explicit_name_set: false,
37         }
38     }
39 
from_usage(usage: &'a str) -> Self40     pub fn from_usage(usage: &'a str) -> Self {
41         debugln!("UsageParser::from_usage;");
42         UsageParser::new(usage)
43     }
44 
parse(mut self) -> Arg<'a, 'a>45     pub fn parse(mut self) -> Arg<'a, 'a> {
46         debugln!("UsageParser::parse;");
47         let mut arg = Arg::default();
48         loop {
49             debugln!("UsageParser::parse:iter: pos={};", self.pos);
50             self.stop_at(token);
51             if let Some(&c) = self.usage.as_bytes().get(self.pos) {
52                 match c {
53                     b'-' => self.short_or_long(&mut arg),
54                     b'.' => self.multiple(&mut arg),
55                     b'\'' => self.help(&mut arg),
56                     _ => self.name(&mut arg),
57                 }
58             } else {
59                 break;
60             }
61         }
62         debug_assert!(
63             !arg.b.name.is_empty(),
64             format!(
65                 "No name found for Arg when parsing usage string: {}",
66                 self.usage
67             )
68         );
69         arg.v.num_vals = match arg.v.val_names {
70             Some(ref v) if v.len() >= 2 => Some(v.len() as u64),
71             _ => None,
72         };
73         debugln!("UsageParser::parse: vals...{:?}", arg.v.val_names);
74         arg
75     }
76 
name(&mut self, arg: &mut Arg<'a, 'a>)77     fn name(&mut self, arg: &mut Arg<'a, 'a>) {
78         debugln!("UsageParser::name;");
79         if *self
80             .usage
81             .as_bytes()
82             .get(self.pos)
83             .expect(INTERNAL_ERROR_MSG)
84             == b'<'
85             && !self.explicit_name_set
86         {
87             arg.setb(ArgSettings::Required);
88         }
89         self.pos += 1;
90         self.stop_at(name_end);
91         let name = &self.usage[self.start..self.pos];
92         if self.prev == UsageToken::Unknown {
93             debugln!("UsageParser::name: setting name...{}", name);
94             arg.b.name = name;
95             if arg.s.long.is_none() && arg.s.short.is_none() {
96                 debugln!("UsageParser::name: explicit name set...");
97                 self.explicit_name_set = true;
98                 self.prev = UsageToken::Name;
99             }
100         } else {
101             debugln!("UsageParser::name: setting val name...{}", name);
102             if let Some(ref mut v) = arg.v.val_names {
103                 let len = v.len();
104                 v.insert(len, name);
105             } else {
106                 let mut v = VecMap::new();
107                 v.insert(0, name);
108                 arg.v.val_names = Some(v);
109                 arg.setb(ArgSettings::TakesValue);
110             }
111             self.prev = UsageToken::ValName;
112         }
113     }
114 
stop_at<F>(&mut self, f: F) where F: Fn(u8) -> bool,115     fn stop_at<F>(&mut self, f: F)
116     where
117         F: Fn(u8) -> bool,
118     {
119         debugln!("UsageParser::stop_at;");
120         self.start = self.pos;
121         self.pos += self.usage[self.start..]
122             .bytes()
123             .take_while(|&b| f(b))
124             .count();
125     }
126 
short_or_long(&mut self, arg: &mut Arg<'a, 'a>)127     fn short_or_long(&mut self, arg: &mut Arg<'a, 'a>) {
128         debugln!("UsageParser::short_or_long;");
129         self.pos += 1;
130         if *self
131             .usage
132             .as_bytes()
133             .get(self.pos)
134             .expect(INTERNAL_ERROR_MSG)
135             == b'-'
136         {
137             self.pos += 1;
138             self.long(arg);
139             return;
140         }
141         self.short(arg)
142     }
143 
long(&mut self, arg: &mut Arg<'a, 'a>)144     fn long(&mut self, arg: &mut Arg<'a, 'a>) {
145         debugln!("UsageParser::long;");
146         self.stop_at(long_end);
147         let name = &self.usage[self.start..self.pos];
148         if !self.explicit_name_set {
149             debugln!("UsageParser::long: setting name...{}", name);
150             arg.b.name = name;
151         }
152         debugln!("UsageParser::long: setting long...{}", name);
153         arg.s.long = Some(name);
154         self.prev = UsageToken::Long;
155     }
156 
short(&mut self, arg: &mut Arg<'a, 'a>)157     fn short(&mut self, arg: &mut Arg<'a, 'a>) {
158         debugln!("UsageParser::short;");
159         let start = &self.usage[self.pos..];
160         let short = start.chars().nth(0).expect(INTERNAL_ERROR_MSG);
161         debugln!("UsageParser::short: setting short...{}", short);
162         arg.s.short = Some(short);
163         if arg.b.name.is_empty() {
164             // --long takes precedence but doesn't set self.explicit_name_set
165             let name = &start[..short.len_utf8()];
166             debugln!("UsageParser::short: setting name...{}", name);
167             arg.b.name = name;
168         }
169         self.prev = UsageToken::Short;
170     }
171 
172     // "something..."
multiple(&mut self, arg: &mut Arg)173     fn multiple(&mut self, arg: &mut Arg) {
174         debugln!("UsageParser::multiple;");
175         let mut dot_counter = 1;
176         let start = self.pos;
177         let mut bytes = self.usage[start..].bytes();
178         while bytes.next() == Some(b'.') {
179             dot_counter += 1;
180             self.pos += 1;
181             if dot_counter == 3 {
182                 debugln!("UsageParser::multiple: setting multiple");
183                 arg.setb(ArgSettings::Multiple);
184                 if arg.is_set(ArgSettings::TakesValue) {
185                     arg.setb(ArgSettings::UseValueDelimiter);
186                     arg.unsetb(ArgSettings::ValueDelimiterNotSet);
187                     if arg.v.val_delim.is_none() {
188                         arg.v.val_delim = Some(',');
189                     }
190                 }
191                 self.prev = UsageToken::Multiple;
192                 self.pos += 1;
193                 break;
194             }
195         }
196     }
197 
help(&mut self, arg: &mut Arg<'a, 'a>)198     fn help(&mut self, arg: &mut Arg<'a, 'a>) {
199         debugln!("UsageParser::help;");
200         self.stop_at(help_start);
201         self.start = self.pos + 1;
202         self.pos = self.usage.len() - 1;
203         debugln!(
204             "UsageParser::help: setting help...{}",
205             &self.usage[self.start..self.pos]
206         );
207         arg.b.help = Some(&self.usage[self.start..self.pos]);
208         self.pos += 1; // Move to next byte to keep from thinking ending ' is a start
209         self.prev = UsageToken::Help;
210     }
211 }
212 
213 #[inline]
name_end(b: u8) -> bool214 fn name_end(b: u8) -> bool {
215     b != b']' && b != b'>'
216 }
217 
218 #[inline]
token(b: u8) -> bool219 fn token(b: u8) -> bool {
220     b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'-'
221 }
222 
223 #[inline]
long_end(b: u8) -> bool224 fn long_end(b: u8) -> bool {
225     b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'=' && b != b' '
226 }
227 
228 #[inline]
help_start(b: u8) -> bool229 fn help_start(b: u8) -> bool {
230     b != b'\''
231 }
232 
233 #[cfg(test)]
234 mod test {
235     use args::Arg;
236     use args::ArgSettings;
237 
238     #[test]
create_flag_usage()239     fn create_flag_usage() {
240         let a = Arg::from_usage("[flag] -f 'some help info'");
241         assert_eq!(a.b.name, "flag");
242         assert_eq!(a.s.short.unwrap(), 'f');
243         assert!(a.s.long.is_none());
244         assert_eq!(a.b.help.unwrap(), "some help info");
245         assert!(!a.is_set(ArgSettings::Multiple));
246         assert!(a.v.val_names.is_none());
247         assert!(a.v.num_vals.is_none());
248 
249         let b = Arg::from_usage("[flag] --flag 'some help info'");
250         assert_eq!(b.b.name, "flag");
251         assert_eq!(b.s.long.unwrap(), "flag");
252         assert!(b.s.short.is_none());
253         assert_eq!(b.b.help.unwrap(), "some help info");
254         assert!(!b.is_set(ArgSettings::Multiple));
255         assert!(a.v.val_names.is_none());
256         assert!(a.v.num_vals.is_none());
257 
258         let b = Arg::from_usage("--flag 'some help info'");
259         assert_eq!(b.b.name, "flag");
260         assert_eq!(b.s.long.unwrap(), "flag");
261         assert!(b.s.short.is_none());
262         assert_eq!(b.b.help.unwrap(), "some help info");
263         assert!(!b.is_set(ArgSettings::Multiple));
264         assert!(b.v.val_names.is_none());
265         assert!(b.v.num_vals.is_none());
266 
267         let c = Arg::from_usage("[flag] -f --flag 'some help info'");
268         assert_eq!(c.b.name, "flag");
269         assert_eq!(c.s.short.unwrap(), 'f');
270         assert_eq!(c.s.long.unwrap(), "flag");
271         assert_eq!(c.b.help.unwrap(), "some help info");
272         assert!(!c.is_set(ArgSettings::Multiple));
273         assert!(c.v.val_names.is_none());
274         assert!(c.v.num_vals.is_none());
275 
276         let d = Arg::from_usage("[flag] -f... 'some help info'");
277         assert_eq!(d.b.name, "flag");
278         assert_eq!(d.s.short.unwrap(), 'f');
279         assert!(d.s.long.is_none());
280         assert_eq!(d.b.help.unwrap(), "some help info");
281         assert!(d.is_set(ArgSettings::Multiple));
282         assert!(d.v.val_names.is_none());
283         assert!(d.v.num_vals.is_none());
284 
285         let e = Arg::from_usage("[flag] -f --flag... 'some help info'");
286         assert_eq!(e.b.name, "flag");
287         assert_eq!(e.s.long.unwrap(), "flag");
288         assert_eq!(e.s.short.unwrap(), 'f');
289         assert_eq!(e.b.help.unwrap(), "some help info");
290         assert!(e.is_set(ArgSettings::Multiple));
291         assert!(e.v.val_names.is_none());
292         assert!(e.v.num_vals.is_none());
293 
294         let e = Arg::from_usage("-f --flag... 'some help info'");
295         assert_eq!(e.b.name, "flag");
296         assert_eq!(e.s.long.unwrap(), "flag");
297         assert_eq!(e.s.short.unwrap(), 'f');
298         assert_eq!(e.b.help.unwrap(), "some help info");
299         assert!(e.is_set(ArgSettings::Multiple));
300         assert!(e.v.val_names.is_none());
301         assert!(e.v.num_vals.is_none());
302 
303         let e = Arg::from_usage("--flags");
304         assert_eq!(e.b.name, "flags");
305         assert_eq!(e.s.long.unwrap(), "flags");
306         assert!(e.v.val_names.is_none());
307         assert!(e.v.num_vals.is_none());
308 
309         let e = Arg::from_usage("--flags...");
310         assert_eq!(e.b.name, "flags");
311         assert_eq!(e.s.long.unwrap(), "flags");
312         assert!(e.is_set(ArgSettings::Multiple));
313         assert!(e.v.val_names.is_none());
314         assert!(e.v.num_vals.is_none());
315 
316         let e = Arg::from_usage("[flags] -f");
317         assert_eq!(e.b.name, "flags");
318         assert_eq!(e.s.short.unwrap(), 'f');
319         assert!(e.v.val_names.is_none());
320         assert!(e.v.num_vals.is_none());
321 
322         let e = Arg::from_usage("[flags] -f...");
323         assert_eq!(e.b.name, "flags");
324         assert_eq!(e.s.short.unwrap(), 'f');
325         assert!(e.is_set(ArgSettings::Multiple));
326         assert!(e.v.val_names.is_none());
327         assert!(e.v.num_vals.is_none());
328 
329         let a = Arg::from_usage("-f 'some help info'");
330         assert_eq!(a.b.name, "f");
331         assert_eq!(a.s.short.unwrap(), 'f');
332         assert!(a.s.long.is_none());
333         assert_eq!(a.b.help.unwrap(), "some help info");
334         assert!(!a.is_set(ArgSettings::Multiple));
335         assert!(a.v.val_names.is_none());
336         assert!(a.v.num_vals.is_none());
337 
338         let e = Arg::from_usage("-f");
339         assert_eq!(e.b.name, "f");
340         assert_eq!(e.s.short.unwrap(), 'f');
341         assert!(e.v.val_names.is_none());
342         assert!(e.v.num_vals.is_none());
343 
344         let e = Arg::from_usage("-f...");
345         assert_eq!(e.b.name, "f");
346         assert_eq!(e.s.short.unwrap(), 'f');
347         assert!(e.is_set(ArgSettings::Multiple));
348         assert!(e.v.val_names.is_none());
349         assert!(e.v.num_vals.is_none());
350     }
351 
352     #[test]
create_option_usage0()353     fn create_option_usage0() {
354         // Short only
355         let a = Arg::from_usage("[option] -o [opt] 'some help info'");
356         assert_eq!(a.b.name, "option");
357         assert_eq!(a.s.short.unwrap(), 'o');
358         assert!(a.s.long.is_none());
359         assert_eq!(a.b.help.unwrap(), "some help info");
360         assert!(!a.is_set(ArgSettings::Multiple));
361         assert!(a.is_set(ArgSettings::TakesValue));
362         assert!(!a.is_set(ArgSettings::Required));
363         assert_eq!(
364             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
365             [&"opt"]
366         );
367         assert!(a.v.num_vals.is_none());
368     }
369 
370     #[test]
create_option_usage1()371     fn create_option_usage1() {
372         let b = Arg::from_usage("-o [opt] 'some help info'");
373         assert_eq!(b.b.name, "o");
374         assert_eq!(b.s.short.unwrap(), 'o');
375         assert!(b.s.long.is_none());
376         assert_eq!(b.b.help.unwrap(), "some help info");
377         assert!(!b.is_set(ArgSettings::Multiple));
378         assert!(b.is_set(ArgSettings::TakesValue));
379         assert!(!b.is_set(ArgSettings::Required));
380         assert_eq!(
381             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
382             [&"opt"]
383         );
384         assert!(b.v.num_vals.is_none());
385     }
386 
387     #[test]
create_option_usage2()388     fn create_option_usage2() {
389         let c = Arg::from_usage("<option> -o <opt> 'some help info'");
390         assert_eq!(c.b.name, "option");
391         assert_eq!(c.s.short.unwrap(), 'o');
392         assert!(c.s.long.is_none());
393         assert_eq!(c.b.help.unwrap(), "some help info");
394         assert!(!c.is_set(ArgSettings::Multiple));
395         assert!(c.is_set(ArgSettings::TakesValue));
396         assert!(c.is_set(ArgSettings::Required));
397         assert_eq!(
398             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
399             [&"opt"]
400         );
401         assert!(c.v.num_vals.is_none());
402     }
403 
404     #[test]
create_option_usage3()405     fn create_option_usage3() {
406         let d = Arg::from_usage("-o <opt> 'some help info'");
407         assert_eq!(d.b.name, "o");
408         assert_eq!(d.s.short.unwrap(), 'o');
409         assert!(d.s.long.is_none());
410         assert_eq!(d.b.help.unwrap(), "some help info");
411         assert!(!d.is_set(ArgSettings::Multiple));
412         assert!(d.is_set(ArgSettings::TakesValue));
413         assert!(d.is_set(ArgSettings::Required));
414         assert_eq!(
415             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
416             [&"opt"]
417         );
418         assert!(d.v.num_vals.is_none());
419     }
420 
421     #[test]
create_option_usage4()422     fn create_option_usage4() {
423         let a = Arg::from_usage("[option] -o [opt]... 'some help info'");
424         assert_eq!(a.b.name, "option");
425         assert_eq!(a.s.short.unwrap(), 'o');
426         assert!(a.s.long.is_none());
427         assert_eq!(a.b.help.unwrap(), "some help info");
428         assert!(a.is_set(ArgSettings::Multiple));
429         assert!(a.is_set(ArgSettings::TakesValue));
430         assert!(!a.is_set(ArgSettings::Required));
431         assert_eq!(
432             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
433             [&"opt"]
434         );
435         assert!(a.v.num_vals.is_none());
436     }
437 
438     #[test]
create_option_usage5()439     fn create_option_usage5() {
440         let a = Arg::from_usage("[option]... -o [opt] 'some help info'");
441         assert_eq!(a.b.name, "option");
442         assert_eq!(a.s.short.unwrap(), 'o');
443         assert!(a.s.long.is_none());
444         assert_eq!(a.b.help.unwrap(), "some help info");
445         assert!(a.is_set(ArgSettings::Multiple));
446         assert!(a.is_set(ArgSettings::TakesValue));
447         assert!(!a.is_set(ArgSettings::Required));
448         assert_eq!(
449             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
450             [&"opt"]
451         );
452         assert!(a.v.num_vals.is_none());
453     }
454 
455     #[test]
create_option_usage6()456     fn create_option_usage6() {
457         let b = Arg::from_usage("-o [opt]... 'some help info'");
458         assert_eq!(b.b.name, "o");
459         assert_eq!(b.s.short.unwrap(), 'o');
460         assert!(b.s.long.is_none());
461         assert_eq!(b.b.help.unwrap(), "some help info");
462         assert!(b.is_set(ArgSettings::Multiple));
463         assert!(b.is_set(ArgSettings::TakesValue));
464         assert!(!b.is_set(ArgSettings::Required));
465         assert_eq!(
466             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
467             [&"opt"]
468         );
469         assert!(b.v.num_vals.is_none());
470     }
471 
472     #[test]
create_option_usage7()473     fn create_option_usage7() {
474         let c = Arg::from_usage("<option> -o <opt>... 'some help info'");
475         assert_eq!(c.b.name, "option");
476         assert_eq!(c.s.short.unwrap(), 'o');
477         assert!(c.s.long.is_none());
478         assert_eq!(c.b.help.unwrap(), "some help info");
479         assert!(c.is_set(ArgSettings::Multiple));
480         assert!(c.is_set(ArgSettings::TakesValue));
481         assert!(c.is_set(ArgSettings::Required));
482         assert_eq!(
483             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
484             [&"opt"]
485         );
486         assert!(c.v.num_vals.is_none());
487     }
488 
489     #[test]
create_option_usage8()490     fn create_option_usage8() {
491         let c = Arg::from_usage("<option>... -o <opt> 'some help info'");
492         assert_eq!(c.b.name, "option");
493         assert_eq!(c.s.short.unwrap(), 'o');
494         assert!(c.s.long.is_none());
495         assert_eq!(c.b.help.unwrap(), "some help info");
496         assert!(c.is_set(ArgSettings::Multiple));
497         assert!(c.is_set(ArgSettings::TakesValue));
498         assert!(c.is_set(ArgSettings::Required));
499         assert_eq!(
500             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
501             [&"opt"]
502         );
503         assert!(c.v.num_vals.is_none());
504     }
505 
506     #[test]
create_option_usage9()507     fn create_option_usage9() {
508         let d = Arg::from_usage("-o <opt>... 'some help info'");
509         assert_eq!(d.b.name, "o");
510         assert_eq!(d.s.short.unwrap(), 'o');
511         assert!(d.s.long.is_none());
512         assert_eq!(d.b.help.unwrap(), "some help info");
513         assert!(d.is_set(ArgSettings::Multiple));
514         assert!(d.is_set(ArgSettings::TakesValue));
515         assert!(d.is_set(ArgSettings::Required));
516         assert_eq!(
517             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
518             [&"opt"]
519         );
520         assert!(d.v.num_vals.is_none());
521     }
522 
523     #[test]
create_option_usage_long1()524     fn create_option_usage_long1() {
525         let a = Arg::from_usage("[option] --opt [opt] 'some help info'");
526         assert_eq!(a.b.name, "option");
527         assert_eq!(a.s.long.unwrap(), "opt");
528         assert!(a.s.short.is_none());
529         assert_eq!(a.b.help.unwrap(), "some help info");
530         assert!(!a.is_set(ArgSettings::Multiple));
531         assert!(a.is_set(ArgSettings::TakesValue));
532         assert!(!a.is_set(ArgSettings::Required));
533         assert_eq!(
534             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
535             [&"opt"]
536         );
537         assert!(a.v.num_vals.is_none());
538     }
539 
540     #[test]
create_option_usage_long2()541     fn create_option_usage_long2() {
542         let b = Arg::from_usage("--opt [option] 'some help info'");
543         assert_eq!(b.b.name, "opt");
544         assert_eq!(b.s.long.unwrap(), "opt");
545         assert!(b.s.short.is_none());
546         assert_eq!(b.b.help.unwrap(), "some help info");
547         assert!(!b.is_set(ArgSettings::Multiple));
548         assert!(b.is_set(ArgSettings::TakesValue));
549         assert!(!b.is_set(ArgSettings::Required));
550         assert_eq!(
551             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
552             [&"option"]
553         );
554         assert!(b.v.num_vals.is_none());
555     }
556 
557     #[test]
create_option_usage_long3()558     fn create_option_usage_long3() {
559         let c = Arg::from_usage("<option> --opt <opt> 'some help info'");
560         assert_eq!(c.b.name, "option");
561         assert_eq!(c.s.long.unwrap(), "opt");
562         assert!(c.s.short.is_none());
563         assert_eq!(c.b.help.unwrap(), "some help info");
564         assert!(!c.is_set(ArgSettings::Multiple));
565         assert!(c.is_set(ArgSettings::TakesValue));
566         assert!(c.is_set(ArgSettings::Required));
567         assert_eq!(
568             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
569             [&"opt"]
570         );
571         assert!(c.v.num_vals.is_none());
572     }
573 
574     #[test]
create_option_usage_long4()575     fn create_option_usage_long4() {
576         let d = Arg::from_usage("--opt <option> 'some help info'");
577         assert_eq!(d.b.name, "opt");
578         assert_eq!(d.s.long.unwrap(), "opt");
579         assert!(d.s.short.is_none());
580         assert_eq!(d.b.help.unwrap(), "some help info");
581         assert!(!d.is_set(ArgSettings::Multiple));
582         assert!(d.is_set(ArgSettings::TakesValue));
583         assert!(d.is_set(ArgSettings::Required));
584         assert_eq!(
585             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
586             [&"option"]
587         );
588         assert!(d.v.num_vals.is_none());
589     }
590 
591     #[test]
create_option_usage_long5()592     fn create_option_usage_long5() {
593         let a = Arg::from_usage("[option] --opt [opt]... 'some help info'");
594         assert_eq!(a.b.name, "option");
595         assert_eq!(a.s.long.unwrap(), "opt");
596         assert!(a.s.short.is_none());
597         assert_eq!(a.b.help.unwrap(), "some help info");
598         assert!(a.is_set(ArgSettings::Multiple));
599         assert!(a.is_set(ArgSettings::TakesValue));
600         assert!(!a.is_set(ArgSettings::Required));
601         assert_eq!(
602             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
603             [&"opt"]
604         );
605         assert!(a.v.num_vals.is_none());
606     }
607 
608     #[test]
create_option_usage_long6()609     fn create_option_usage_long6() {
610         let a = Arg::from_usage("[option]... --opt [opt] 'some help info'");
611         assert_eq!(a.b.name, "option");
612         assert_eq!(a.s.long.unwrap(), "opt");
613         assert!(a.s.short.is_none());
614         assert_eq!(a.b.help.unwrap(), "some help info");
615         assert!(a.is_set(ArgSettings::Multiple));
616         assert!(a.is_set(ArgSettings::TakesValue));
617         assert!(!a.is_set(ArgSettings::Required));
618         assert_eq!(
619             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
620             [&"opt"]
621         );
622         assert!(a.v.num_vals.is_none());
623     }
624 
625     #[test]
create_option_usage_long7()626     fn create_option_usage_long7() {
627         let b = Arg::from_usage("--opt [option]... 'some help info'");
628         assert_eq!(b.b.name, "opt");
629         assert_eq!(b.s.long.unwrap(), "opt");
630         assert!(b.s.short.is_none());
631         assert_eq!(b.b.help.unwrap(), "some help info");
632         assert!(b.is_set(ArgSettings::Multiple));
633         assert!(b.is_set(ArgSettings::TakesValue));
634         assert!(!b.is_set(ArgSettings::Required));
635         assert_eq!(
636             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
637             [&"option"]
638         );
639         assert!(b.v.num_vals.is_none());
640     }
641 
642     #[test]
create_option_usage_long8()643     fn create_option_usage_long8() {
644         let c = Arg::from_usage("<option> --opt <opt>... 'some help info'");
645         assert_eq!(c.b.name, "option");
646         assert_eq!(c.s.long.unwrap(), "opt");
647         assert!(c.s.short.is_none());
648         assert_eq!(c.b.help.unwrap(), "some help info");
649         assert!(c.is_set(ArgSettings::Multiple));
650         assert!(c.is_set(ArgSettings::TakesValue));
651         assert!(c.is_set(ArgSettings::Required));
652         assert_eq!(
653             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
654             [&"opt"]
655         );
656         assert!(c.v.num_vals.is_none());
657     }
658 
659     #[test]
create_option_usage_long9()660     fn create_option_usage_long9() {
661         let c = Arg::from_usage("<option>... --opt <opt> 'some help info'");
662         assert_eq!(c.b.name, "option");
663         assert_eq!(c.s.long.unwrap(), "opt");
664         assert!(c.s.short.is_none());
665         assert_eq!(c.b.help.unwrap(), "some help info");
666         assert!(c.is_set(ArgSettings::Multiple));
667         assert!(c.is_set(ArgSettings::TakesValue));
668         assert!(c.is_set(ArgSettings::Required));
669         assert_eq!(
670             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
671             [&"opt"]
672         );
673         assert!(c.v.num_vals.is_none());
674     }
675 
676     #[test]
create_option_usage_long10()677     fn create_option_usage_long10() {
678         let d = Arg::from_usage("--opt <option>... 'some help info'");
679         assert_eq!(d.b.name, "opt");
680         assert_eq!(d.s.long.unwrap(), "opt");
681         assert!(d.s.short.is_none());
682         assert_eq!(d.b.help.unwrap(), "some help info");
683         assert!(d.is_set(ArgSettings::Multiple));
684         assert!(d.is_set(ArgSettings::TakesValue));
685         assert!(d.is_set(ArgSettings::Required));
686         assert_eq!(
687             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
688             [&"option"]
689         );
690         assert!(d.v.num_vals.is_none());
691     }
692 
693     #[test]
create_option_usage_long_equals1()694     fn create_option_usage_long_equals1() {
695         let a = Arg::from_usage("[option] --opt=[opt] 'some help info'");
696         assert_eq!(a.b.name, "option");
697         assert_eq!(a.s.long.unwrap(), "opt");
698         assert!(a.s.short.is_none());
699         assert_eq!(a.b.help.unwrap(), "some help info");
700         assert!(!a.is_set(ArgSettings::Multiple));
701         assert!(a.is_set(ArgSettings::TakesValue));
702         assert!(!a.is_set(ArgSettings::Required));
703         assert_eq!(
704             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
705             [&"opt"]
706         );
707         assert!(a.v.num_vals.is_none());
708     }
709 
710     #[test]
create_option_usage_long_equals2()711     fn create_option_usage_long_equals2() {
712         let b = Arg::from_usage("--opt=[option] 'some help info'");
713         assert_eq!(b.b.name, "opt");
714         assert_eq!(b.s.long.unwrap(), "opt");
715         assert!(b.s.short.is_none());
716         assert_eq!(b.b.help.unwrap(), "some help info");
717         assert!(!b.is_set(ArgSettings::Multiple));
718         assert!(b.is_set(ArgSettings::TakesValue));
719         assert!(!b.is_set(ArgSettings::Required));
720         assert_eq!(
721             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
722             [&"option"]
723         );
724         assert!(b.v.num_vals.is_none());
725     }
726 
727     #[test]
create_option_usage_long_equals3()728     fn create_option_usage_long_equals3() {
729         let c = Arg::from_usage("<option> --opt=<opt> 'some help info'");
730         assert_eq!(c.b.name, "option");
731         assert_eq!(c.s.long.unwrap(), "opt");
732         assert!(c.s.short.is_none());
733         assert_eq!(c.b.help.unwrap(), "some help info");
734         assert!(!c.is_set(ArgSettings::Multiple));
735         assert!(c.is_set(ArgSettings::TakesValue));
736         assert!(c.is_set(ArgSettings::Required));
737         assert_eq!(
738             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
739             [&"opt"]
740         );
741         assert!(c.v.num_vals.is_none());
742     }
743 
744     #[test]
create_option_usage_long_equals4()745     fn create_option_usage_long_equals4() {
746         let d = Arg::from_usage("--opt=<option> 'some help info'");
747         assert_eq!(d.b.name, "opt");
748         assert_eq!(d.s.long.unwrap(), "opt");
749         assert!(d.s.short.is_none());
750         assert_eq!(d.b.help.unwrap(), "some help info");
751         assert!(!d.is_set(ArgSettings::Multiple));
752         assert!(d.is_set(ArgSettings::TakesValue));
753         assert!(d.is_set(ArgSettings::Required));
754         assert_eq!(
755             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
756             [&"option"]
757         );
758         assert!(d.v.num_vals.is_none());
759     }
760 
761     #[test]
create_option_usage_long_equals5()762     fn create_option_usage_long_equals5() {
763         let a = Arg::from_usage("[option] --opt=[opt]... 'some help info'");
764         assert_eq!(a.b.name, "option");
765         assert_eq!(a.s.long.unwrap(), "opt");
766         assert!(a.s.short.is_none());
767         assert_eq!(a.b.help.unwrap(), "some help info");
768         assert!(a.is_set(ArgSettings::Multiple));
769         assert!(a.is_set(ArgSettings::TakesValue));
770         assert!(!a.is_set(ArgSettings::Required));
771         assert_eq!(
772             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
773             [&"opt"]
774         );
775         assert!(a.v.num_vals.is_none());
776     }
777 
778     #[test]
create_option_usage_long_equals6()779     fn create_option_usage_long_equals6() {
780         let a = Arg::from_usage("[option]... --opt=[opt] 'some help info'");
781         assert_eq!(a.b.name, "option");
782         assert_eq!(a.s.long.unwrap(), "opt");
783         assert!(a.s.short.is_none());
784         assert_eq!(a.b.help.unwrap(), "some help info");
785         assert!(a.is_set(ArgSettings::Multiple));
786         assert!(a.is_set(ArgSettings::TakesValue));
787         assert!(!a.is_set(ArgSettings::Required));
788         assert_eq!(
789             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
790             [&"opt"]
791         );
792         assert!(a.v.num_vals.is_none());
793     }
794 
795     #[test]
create_option_usage_long_equals7()796     fn create_option_usage_long_equals7() {
797         let b = Arg::from_usage("--opt=[option]... 'some help info'");
798         assert_eq!(b.b.name, "opt");
799         assert_eq!(b.s.long.unwrap(), "opt");
800         assert!(b.s.short.is_none());
801         assert_eq!(b.b.help.unwrap(), "some help info");
802         assert!(b.is_set(ArgSettings::Multiple));
803         assert!(b.is_set(ArgSettings::TakesValue));
804         assert!(!b.is_set(ArgSettings::Required));
805         assert_eq!(
806             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
807             [&"option"]
808         );
809         assert!(b.v.num_vals.is_none());
810     }
811 
812     #[test]
create_option_usage_long_equals8()813     fn create_option_usage_long_equals8() {
814         let c = Arg::from_usage("<option> --opt=<opt>... 'some help info'");
815         assert_eq!(c.b.name, "option");
816         assert_eq!(c.s.long.unwrap(), "opt");
817         assert!(c.s.short.is_none());
818         assert_eq!(c.b.help.unwrap(), "some help info");
819         assert!(c.is_set(ArgSettings::Multiple));
820         assert!(c.is_set(ArgSettings::TakesValue));
821         assert!(c.is_set(ArgSettings::Required));
822         assert_eq!(
823             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
824             [&"opt"]
825         );
826         assert!(c.v.num_vals.is_none());
827     }
828 
829     #[test]
create_option_usage_long_equals9()830     fn create_option_usage_long_equals9() {
831         let c = Arg::from_usage("<option>... --opt=<opt> 'some help info'");
832         assert_eq!(c.b.name, "option");
833         assert_eq!(c.s.long.unwrap(), "opt");
834         assert!(c.s.short.is_none());
835         assert_eq!(c.b.help.unwrap(), "some help info");
836         assert!(c.is_set(ArgSettings::Multiple));
837         assert!(c.is_set(ArgSettings::TakesValue));
838         assert!(c.is_set(ArgSettings::Required));
839         assert_eq!(
840             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
841             [&"opt"]
842         );
843         assert!(c.v.num_vals.is_none());
844     }
845 
846     #[test]
create_option_usage_long_equals10()847     fn create_option_usage_long_equals10() {
848         let d = Arg::from_usage("--opt=<option>... 'some help info'");
849         assert_eq!(d.b.name, "opt");
850         assert_eq!(d.s.long.unwrap(), "opt");
851         assert!(d.s.short.is_none());
852         assert_eq!(d.b.help.unwrap(), "some help info");
853         assert!(d.is_set(ArgSettings::Multiple));
854         assert!(d.is_set(ArgSettings::TakesValue));
855         assert!(d.is_set(ArgSettings::Required));
856         assert_eq!(
857             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
858             [&"option"]
859         );
860         assert!(d.v.num_vals.is_none());
861     }
862 
863     #[test]
create_option_usage_both1()864     fn create_option_usage_both1() {
865         let a = Arg::from_usage("[option] -o --opt [option] 'some help info'");
866         assert_eq!(a.b.name, "option");
867         assert_eq!(a.s.long.unwrap(), "opt");
868         assert_eq!(a.s.short.unwrap(), 'o');
869         assert_eq!(a.b.help.unwrap(), "some help info");
870         assert!(!a.is_set(ArgSettings::Multiple));
871         assert!(a.is_set(ArgSettings::TakesValue));
872         assert!(!a.is_set(ArgSettings::Required));
873         assert_eq!(
874             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
875             [&"option"]
876         );
877         assert!(a.v.num_vals.is_none());
878     }
879 
880     #[test]
create_option_usage_both2()881     fn create_option_usage_both2() {
882         let b = Arg::from_usage("-o --opt [option] 'some help info'");
883         assert_eq!(b.b.name, "opt");
884         assert_eq!(b.s.long.unwrap(), "opt");
885         assert_eq!(b.s.short.unwrap(), 'o');
886         assert_eq!(b.b.help.unwrap(), "some help info");
887         assert!(!b.is_set(ArgSettings::Multiple));
888         assert!(b.is_set(ArgSettings::TakesValue));
889         assert!(!b.is_set(ArgSettings::Required));
890         assert_eq!(
891             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
892             [&"option"]
893         );
894         assert!(b.v.num_vals.is_none());
895     }
896 
897     #[test]
create_option_usage_both3()898     fn create_option_usage_both3() {
899         let c = Arg::from_usage("<option> -o --opt <opt> 'some help info'");
900         assert_eq!(c.b.name, "option");
901         assert_eq!(c.s.long.unwrap(), "opt");
902         assert_eq!(c.s.short.unwrap(), 'o');
903         assert_eq!(c.b.help.unwrap(), "some help info");
904         assert!(!c.is_set(ArgSettings::Multiple));
905         assert!(c.is_set(ArgSettings::TakesValue));
906         assert!(c.is_set(ArgSettings::Required));
907         assert_eq!(
908             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
909             [&"opt"]
910         );
911         assert!(c.v.num_vals.is_none());
912     }
913 
914     #[test]
create_option_usage_both4()915     fn create_option_usage_both4() {
916         let d = Arg::from_usage("-o --opt <option> 'some help info'");
917         assert_eq!(d.b.name, "opt");
918         assert_eq!(d.s.long.unwrap(), "opt");
919         assert_eq!(d.s.short.unwrap(), 'o');
920         assert_eq!(d.b.help.unwrap(), "some help info");
921         assert!(!d.is_set(ArgSettings::Multiple));
922         assert!(d.is_set(ArgSettings::TakesValue));
923         assert!(d.is_set(ArgSettings::Required));
924         assert_eq!(
925             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
926             [&"option"]
927         );
928         assert!(d.v.num_vals.is_none());
929     }
930 
931     #[test]
create_option_usage_both5()932     fn create_option_usage_both5() {
933         let a = Arg::from_usage("[option]... -o --opt [option] 'some help info'");
934         assert_eq!(a.b.name, "option");
935         assert_eq!(a.s.long.unwrap(), "opt");
936         assert_eq!(a.s.short.unwrap(), 'o');
937         assert_eq!(a.b.help.unwrap(), "some help info");
938         assert!(a.is_set(ArgSettings::Multiple));
939         assert!(a.is_set(ArgSettings::TakesValue));
940         assert!(!a.is_set(ArgSettings::Required));
941         assert_eq!(
942             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
943             [&"option"]
944         );
945         assert!(a.v.num_vals.is_none());
946     }
947 
948     #[test]
create_option_usage_both6()949     fn create_option_usage_both6() {
950         let b = Arg::from_usage("-o --opt [option]... 'some help info'");
951         assert_eq!(b.b.name, "opt");
952         assert_eq!(b.s.long.unwrap(), "opt");
953         assert_eq!(b.s.short.unwrap(), 'o');
954         assert_eq!(b.b.help.unwrap(), "some help info");
955         assert!(b.is_set(ArgSettings::Multiple));
956         assert!(b.is_set(ArgSettings::TakesValue));
957         assert!(!b.is_set(ArgSettings::Required));
958         assert_eq!(
959             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
960             [&"option"]
961         );
962         assert!(b.v.num_vals.is_none());
963     }
964 
965     #[test]
create_option_usage_both7()966     fn create_option_usage_both7() {
967         let c = Arg::from_usage("<option>... -o --opt <opt> 'some help info'");
968         assert_eq!(c.b.name, "option");
969         assert_eq!(c.s.long.unwrap(), "opt");
970         assert_eq!(c.s.short.unwrap(), 'o');
971         assert_eq!(c.b.help.unwrap(), "some help info");
972         assert!(c.is_set(ArgSettings::Multiple));
973         assert!(c.is_set(ArgSettings::TakesValue));
974         assert!(c.is_set(ArgSettings::Required));
975         assert_eq!(
976             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
977             [&"opt"]
978         );
979         assert!(c.v.num_vals.is_none());
980     }
981 
982     #[test]
create_option_usage_both8()983     fn create_option_usage_both8() {
984         let d = Arg::from_usage("-o --opt <option>... 'some help info'");
985         assert_eq!(d.b.name, "opt");
986         assert_eq!(d.s.long.unwrap(), "opt");
987         assert_eq!(d.s.short.unwrap(), 'o');
988         assert_eq!(d.b.help.unwrap(), "some help info");
989         assert!(d.is_set(ArgSettings::Multiple));
990         assert!(d.is_set(ArgSettings::TakesValue));
991         assert!(d.is_set(ArgSettings::Required));
992         assert_eq!(
993             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
994             [&"option"]
995         );
996         assert!(d.v.num_vals.is_none());
997     }
998 
999     #[test]
create_option_usage_both_equals1()1000     fn create_option_usage_both_equals1() {
1001         let a = Arg::from_usage("[option] -o --opt=[option] 'some help info'");
1002         assert_eq!(a.b.name, "option");
1003         assert_eq!(a.s.long.unwrap(), "opt");
1004         assert_eq!(a.s.short.unwrap(), 'o');
1005         assert_eq!(a.b.help.unwrap(), "some help info");
1006         assert!(!a.is_set(ArgSettings::Multiple));
1007         assert!(a.is_set(ArgSettings::TakesValue));
1008         assert!(!a.is_set(ArgSettings::Required));
1009         assert_eq!(
1010             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
1011             [&"option"]
1012         );
1013         assert!(a.v.num_vals.is_none());
1014     }
1015 
1016     #[test]
create_option_usage_both_equals2()1017     fn create_option_usage_both_equals2() {
1018         let b = Arg::from_usage("-o --opt=[option] 'some help info'");
1019         assert_eq!(b.b.name, "opt");
1020         assert_eq!(b.s.long.unwrap(), "opt");
1021         assert_eq!(b.s.short.unwrap(), 'o');
1022         assert_eq!(b.b.help.unwrap(), "some help info");
1023         assert!(!b.is_set(ArgSettings::Multiple));
1024         assert!(b.is_set(ArgSettings::TakesValue));
1025         assert!(!b.is_set(ArgSettings::Required));
1026         assert_eq!(
1027             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
1028             [&"option"]
1029         );
1030         assert!(b.v.num_vals.is_none());
1031     }
1032 
1033     #[test]
create_option_usage_both_equals3()1034     fn create_option_usage_both_equals3() {
1035         let c = Arg::from_usage("<option> -o --opt=<opt> 'some help info'");
1036         assert_eq!(c.b.name, "option");
1037         assert_eq!(c.s.long.unwrap(), "opt");
1038         assert_eq!(c.s.short.unwrap(), 'o');
1039         assert_eq!(c.b.help.unwrap(), "some help info");
1040         assert!(!c.is_set(ArgSettings::Multiple));
1041         assert!(c.is_set(ArgSettings::TakesValue));
1042         assert!(c.is_set(ArgSettings::Required));
1043         assert_eq!(
1044             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
1045             [&"opt"]
1046         );
1047         assert!(c.v.num_vals.is_none());
1048     }
1049 
1050     #[test]
create_option_usage_both_equals4()1051     fn create_option_usage_both_equals4() {
1052         let d = Arg::from_usage("-o --opt=<option> 'some help info'");
1053         assert_eq!(d.b.name, "opt");
1054         assert_eq!(d.s.long.unwrap(), "opt");
1055         assert_eq!(d.s.short.unwrap(), 'o');
1056         assert_eq!(d.b.help.unwrap(), "some help info");
1057         assert!(!d.is_set(ArgSettings::Multiple));
1058         assert!(d.is_set(ArgSettings::TakesValue));
1059         assert!(d.is_set(ArgSettings::Required));
1060         assert_eq!(
1061             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1062             [&"option"]
1063         );
1064         assert!(d.v.num_vals.is_none());
1065     }
1066 
1067     #[test]
create_option_usage_both_equals5()1068     fn create_option_usage_both_equals5() {
1069         let a = Arg::from_usage("[option]... -o --opt=[option] 'some help info'");
1070         assert_eq!(a.b.name, "option");
1071         assert_eq!(a.s.long.unwrap(), "opt");
1072         assert_eq!(a.s.short.unwrap(), 'o');
1073         assert_eq!(a.b.help.unwrap(), "some help info");
1074         assert!(a.is_set(ArgSettings::Multiple));
1075         assert!(a.is_set(ArgSettings::TakesValue));
1076         assert!(!a.is_set(ArgSettings::Required));
1077         assert_eq!(
1078             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
1079             [&"option"]
1080         );
1081         assert!(a.v.num_vals.is_none());
1082     }
1083 
1084     #[test]
create_option_usage_both_equals6()1085     fn create_option_usage_both_equals6() {
1086         let b = Arg::from_usage("-o --opt=[option]... 'some help info'");
1087         assert_eq!(b.b.name, "opt");
1088         assert_eq!(b.s.long.unwrap(), "opt");
1089         assert_eq!(b.s.short.unwrap(), 'o');
1090         assert_eq!(b.b.help.unwrap(), "some help info");
1091         assert!(b.is_set(ArgSettings::Multiple));
1092         assert!(b.is_set(ArgSettings::TakesValue));
1093         assert!(!b.is_set(ArgSettings::Required));
1094         assert_eq!(
1095             b.v.val_names.unwrap().values().collect::<Vec<_>>(),
1096             [&"option"]
1097         );
1098         assert!(b.v.num_vals.is_none());
1099     }
1100 
1101     #[test]
create_option_usage_both_equals7()1102     fn create_option_usage_both_equals7() {
1103         let c = Arg::from_usage("<option>... -o --opt=<opt> 'some help info'");
1104         assert_eq!(c.b.name, "option");
1105         assert_eq!(c.s.long.unwrap(), "opt");
1106         assert_eq!(c.s.short.unwrap(), 'o');
1107         assert_eq!(c.b.help.unwrap(), "some help info");
1108         assert!(c.is_set(ArgSettings::Multiple));
1109         assert!(c.is_set(ArgSettings::TakesValue));
1110         assert!(c.is_set(ArgSettings::Required));
1111         assert_eq!(
1112             c.v.val_names.unwrap().values().collect::<Vec<_>>(),
1113             [&"opt"]
1114         );
1115         assert!(c.v.num_vals.is_none());
1116     }
1117 
1118     #[test]
create_option_usage_both_equals8()1119     fn create_option_usage_both_equals8() {
1120         let d = Arg::from_usage("-o --opt=<option>... 'some help info'");
1121         assert_eq!(d.b.name, "opt");
1122         assert_eq!(d.s.long.unwrap(), "opt");
1123         assert_eq!(d.s.short.unwrap(), 'o');
1124         assert_eq!(d.b.help.unwrap(), "some help info");
1125         assert!(d.is_set(ArgSettings::Multiple));
1126         assert!(d.is_set(ArgSettings::TakesValue));
1127         assert!(d.is_set(ArgSettings::Required));
1128         assert_eq!(
1129             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1130             [&"option"]
1131         );
1132         assert!(d.v.num_vals.is_none());
1133     }
1134 
1135     #[test]
create_option_with_vals1()1136     fn create_option_with_vals1() {
1137         let d = Arg::from_usage("-o <file> <mode> 'some help info'");
1138         assert_eq!(d.b.name, "o");
1139         assert!(d.s.long.is_none());
1140         assert_eq!(d.s.short.unwrap(), 'o');
1141         assert_eq!(d.b.help.unwrap(), "some help info");
1142         assert!(!d.is_set(ArgSettings::Multiple));
1143         assert!(d.is_set(ArgSettings::TakesValue));
1144         assert!(d.is_set(ArgSettings::Required));
1145         assert_eq!(
1146             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1147             [&"file", &"mode"]
1148         );
1149         assert_eq!(d.v.num_vals.unwrap(), 2);
1150     }
1151 
1152     #[test]
create_option_with_vals2()1153     fn create_option_with_vals2() {
1154         let d = Arg::from_usage("-o <file> <mode>... 'some help info'");
1155         assert_eq!(d.b.name, "o");
1156         assert!(d.s.long.is_none());
1157         assert_eq!(d.s.short.unwrap(), 'o');
1158         assert_eq!(d.b.help.unwrap(), "some help info");
1159         assert!(d.is_set(ArgSettings::Multiple));
1160         assert!(d.is_set(ArgSettings::TakesValue));
1161         assert!(d.is_set(ArgSettings::Required));
1162         assert_eq!(
1163             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1164             [&"file", &"mode"]
1165         );
1166         assert_eq!(d.v.num_vals.unwrap(), 2);
1167     }
1168 
1169     #[test]
create_option_with_vals3()1170     fn create_option_with_vals3() {
1171         let d = Arg::from_usage("--opt <file> <mode>... 'some help info'");
1172         assert_eq!(d.b.name, "opt");
1173         assert!(d.s.short.is_none());
1174         assert_eq!(d.s.long.unwrap(), "opt");
1175         assert_eq!(d.b.help.unwrap(), "some help info");
1176         assert!(d.is_set(ArgSettings::Multiple));
1177         assert!(d.is_set(ArgSettings::TakesValue));
1178         assert!(d.is_set(ArgSettings::Required));
1179         assert_eq!(
1180             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1181             [&"file", &"mode"]
1182         );
1183         assert_eq!(d.v.num_vals.unwrap(), 2);
1184     }
1185 
1186     #[test]
create_option_with_vals4()1187     fn create_option_with_vals4() {
1188         let d = Arg::from_usage("[myopt] --opt <file> <mode> 'some help info'");
1189         assert_eq!(d.b.name, "myopt");
1190         assert!(d.s.short.is_none());
1191         assert_eq!(d.s.long.unwrap(), "opt");
1192         assert_eq!(d.b.help.unwrap(), "some help info");
1193         assert!(!d.is_set(ArgSettings::Multiple));
1194         assert!(d.is_set(ArgSettings::TakesValue));
1195         assert!(!d.is_set(ArgSettings::Required));
1196         assert_eq!(
1197             d.v.val_names.unwrap().values().collect::<Vec<_>>(),
1198             [&"file", &"mode"]
1199         );
1200         assert_eq!(d.v.num_vals.unwrap(), 2);
1201     }
1202 
1203     #[test]
create_option_with_vals5()1204     fn create_option_with_vals5() {
1205         let d = Arg::from_usage("--opt <file> <mode> 'some help info'");
1206         assert_eq!(d.b.name, "opt");
1207         assert!(d.s.short.is_none());
1208         assert_eq!(d.s.long.unwrap(), "opt");
1209         assert_eq!(d.b.help.unwrap(), "some help info");
1210         assert!(!d.is_set(ArgSettings::Multiple));
1211         assert!(d.is_set(ArgSettings::TakesValue));
1212         assert!(d.is_set(ArgSettings::Required));
1213         assert_eq!(d.v.num_vals.unwrap(), 2);
1214     }
1215 
1216     #[test]
create_positional_usage()1217     fn create_positional_usage() {
1218         let a = Arg::from_usage("[pos] 'some help info'");
1219         assert_eq!(a.b.name, "pos");
1220         assert_eq!(a.b.help.unwrap(), "some help info");
1221         assert!(!a.is_set(ArgSettings::Multiple));
1222         assert!(!a.is_set(ArgSettings::Required));
1223         assert!(a.v.val_names.is_none());
1224         assert!(a.v.num_vals.is_none());
1225     }
1226 
1227     #[test]
create_positional_usage0()1228     fn create_positional_usage0() {
1229         let b = Arg::from_usage("<pos> 'some help info'");
1230         assert_eq!(b.b.name, "pos");
1231         assert_eq!(b.b.help.unwrap(), "some help info");
1232         assert!(!b.is_set(ArgSettings::Multiple));
1233         assert!(b.is_set(ArgSettings::Required));
1234         assert!(b.v.val_names.is_none());
1235         assert!(b.v.num_vals.is_none());
1236     }
1237 
1238     #[test]
pos_mult_help()1239     fn pos_mult_help() {
1240         let c = Arg::from_usage("[pos]... 'some help info'");
1241         assert_eq!(c.b.name, "pos");
1242         assert_eq!(c.b.help.unwrap(), "some help info");
1243         assert!(c.is_set(ArgSettings::Multiple));
1244         assert!(!c.is_set(ArgSettings::Required));
1245         assert!(c.v.val_names.is_none());
1246         assert!(c.v.num_vals.is_none());
1247     }
1248 
1249     #[test]
pos_help_lit_single_quote()1250     fn pos_help_lit_single_quote() {
1251         let c = Arg::from_usage("[pos]... 'some help\' info'");
1252         assert_eq!(c.b.name, "pos");
1253         assert_eq!(c.b.help.unwrap(), "some help' info");
1254         assert!(c.is_set(ArgSettings::Multiple));
1255         assert!(!c.is_set(ArgSettings::Required));
1256         assert!(c.v.val_names.is_none());
1257         assert!(c.v.num_vals.is_none());
1258     }
1259 
1260     #[test]
pos_help_double_lit_single_quote()1261     fn pos_help_double_lit_single_quote() {
1262         let c = Arg::from_usage("[pos]... 'some \'help\' info'");
1263         assert_eq!(c.b.name, "pos");
1264         assert_eq!(c.b.help.unwrap(), "some 'help' info");
1265         assert!(c.is_set(ArgSettings::Multiple));
1266         assert!(!c.is_set(ArgSettings::Required));
1267         assert!(c.v.val_names.is_none());
1268         assert!(c.v.num_vals.is_none());
1269     }
1270 
1271     #[test]
pos_help_newline()1272     fn pos_help_newline() {
1273         let c = Arg::from_usage(
1274             "[pos]... 'some help{n}\
1275              info'",
1276         );
1277         assert_eq!(c.b.name, "pos");
1278         assert_eq!(c.b.help.unwrap(), "some help{n}info");
1279         assert!(c.is_set(ArgSettings::Multiple));
1280         assert!(!c.is_set(ArgSettings::Required));
1281         assert!(c.v.val_names.is_none());
1282         assert!(c.v.num_vals.is_none());
1283     }
1284 
1285     #[test]
pos_help_newline_lit_sq()1286     fn pos_help_newline_lit_sq() {
1287         let c = Arg::from_usage(
1288             "[pos]... 'some help\' stuff{n}\
1289              info'",
1290         );
1291         assert_eq!(c.b.name, "pos");
1292         assert_eq!(c.b.help.unwrap(), "some help' stuff{n}info");
1293         assert!(c.is_set(ArgSettings::Multiple));
1294         assert!(!c.is_set(ArgSettings::Required));
1295         assert!(c.v.val_names.is_none());
1296         assert!(c.v.num_vals.is_none());
1297     }
1298 
1299     #[test]
pos_req_mult_help()1300     fn pos_req_mult_help() {
1301         let d = Arg::from_usage("<pos>... 'some help info'");
1302         assert_eq!(d.b.name, "pos");
1303         assert_eq!(d.b.help.unwrap(), "some help info");
1304         assert!(d.is_set(ArgSettings::Multiple));
1305         assert!(d.is_set(ArgSettings::Required));
1306         assert!(d.v.val_names.is_none());
1307         assert!(d.v.num_vals.is_none());
1308     }
1309 
1310     #[test]
pos_req()1311     fn pos_req() {
1312         let b = Arg::from_usage("<pos>");
1313         assert_eq!(b.b.name, "pos");
1314         assert!(!b.is_set(ArgSettings::Multiple));
1315         assert!(b.is_set(ArgSettings::Required));
1316         assert!(b.v.val_names.is_none());
1317         assert!(b.v.num_vals.is_none());
1318     }
1319 
1320     #[test]
pos_mult()1321     fn pos_mult() {
1322         let c = Arg::from_usage("[pos]...");
1323         assert_eq!(c.b.name, "pos");
1324         assert!(c.is_set(ArgSettings::Multiple));
1325         assert!(!c.is_set(ArgSettings::Required));
1326         assert!(c.v.val_names.is_none());
1327         assert!(c.v.num_vals.is_none());
1328     }
1329 
1330     #[test]
nonascii()1331     fn nonascii() {
1332         let a = Arg::from_usage("<ASCII> 'üñíčöĐ€'");
1333         assert_eq!(a.b.name, "ASCII");
1334         assert_eq!(a.b.help, Some("üñíčöĐ€"));
1335         let a = Arg::from_usage("<üñíčöĐ€> 'ASCII'");
1336         assert_eq!(a.b.name, "üñíčöĐ€");
1337         assert_eq!(a.b.help, Some("ASCII"));
1338         let a = Arg::from_usage("<üñíčöĐ€> 'üñíčöĐ€'");
1339         assert_eq!(a.b.name, "üñíčöĐ€");
1340         assert_eq!(a.b.help, Some("üñíčöĐ€"));
1341         let a = Arg::from_usage("-ø 'ø'");
1342         assert_eq!(a.b.name, "ø");
1343         assert_eq!(a.s.short, Some('ø'));
1344         assert_eq!(a.b.help, Some("ø"));
1345         let a = Arg::from_usage("--üñíčöĐ€ 'Nōṫ ASCII'");
1346         assert_eq!(a.b.name, "üñíčöĐ€");
1347         assert_eq!(a.s.long, Some("üñíčöĐ€"));
1348         assert_eq!(a.b.help, Some("Nōṫ ASCII"));
1349         let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
1350         assert_eq!(a.b.name, "ñämê");
1351         assert_eq!(a.s.long, Some("ôpt"));
1352         assert_eq!(
1353             a.v.val_names.unwrap().values().collect::<Vec<_>>(),
1354             [&"üñíčöĐ€"]
1355         );
1356         assert_eq!(a.b.help, Some("hælp"));
1357     }
1358 }
1359