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
15use clap::Parser;
16
17// Tests that clap_derive properly detects an `Option` field
18// that results from a macro expansion
19#[test]
20fn use_option() {
21    macro_rules! expand_ty {
22        ($name:ident: $ty:ty) => {
23            #[derive(Parser)]
24            struct Outer {
25                #[arg(short, long)]
26                #[allow(dead_code)]
27                $name: $ty,
28            }
29        };
30    }
31
32    expand_ty!(my_field: Option<String>);
33}
34
35#[test]
36fn issue_447() {
37    macro_rules! Command {
38        ( $name:ident, [
39        #[$meta:meta] $var:ident($inner:ty)
40      ] ) => {
41            #[derive(Debug, PartialEq, clap::Parser)]
42            enum $name {
43                #[$meta]
44                $var($inner),
45            }
46        };
47    }
48
49    Command! {GitCmd, [
50      #[command(external_subcommand)]
51      Ext(Vec<String>)
52    ]}
53}
54