• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
2 // Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
3 // Ana Hobden (@hoverbear) <operator@hoverbear.org>
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 //
11 // This work was derived from Structopt (https://github.com/TeXitoi/structopt)
12 // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
13 // MIT/Apache 2.0 license.
14 
15 #![deny(warnings)]
16 
17 use clap::Parser;
18 
try_str(s: &str) -> Result<String, std::convert::Infallible>19 fn try_str(s: &str) -> Result<String, std::convert::Infallible> {
20     Ok(s.into())
21 }
22 
23 #[test]
warning_never_struct()24 fn warning_never_struct() {
25     #[derive(Parser, Debug, PartialEq)]
26     struct Opt {
27         #[arg(value_parser = try_str, default_value_t)]
28         s: String,
29     }
30     assert_eq!(
31         Opt {
32             s: "foo".to_string()
33         },
34         Opt::try_parse_from(["test", "foo"]).unwrap()
35     );
36 }
37 
38 #[test]
warning_never_enum()39 fn warning_never_enum() {
40     #[derive(Parser, Debug, PartialEq)]
41     enum Opt {
42         Foo {
43             #[arg(value_parser = try_str, default_value_t)]
44             s: String,
45         },
46     }
47     assert_eq!(
48         Opt::Foo {
49             s: "foo".to_string()
50         },
51         Opt::try_parse_from(["test", "foo", "foo"]).unwrap()
52     );
53 }
54