clap/clap_derive/tests/boxed.rs
Ed Page 60c9c2e59a docs(derive): Use more-specific traits
This helps to raise visibility of the new derive traits.

I didn't touch ui tests because there were a lot and they didn't seem to
be as high value.
2021-10-12 07:51:11 -05:00

48 lines
878 B
Rust

use clap::{Args, Parser, Subcommand};
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(subcommand)]
sub: Box<Sub>,
}
#[derive(Subcommand, PartialEq, Debug)]
enum Sub {
Flame {
#[clap(flatten)]
arg: Box<Ext>,
},
}
#[derive(Args, PartialEq, Debug)]
struct Ext {
arg: u32,
}
#[test]
fn boxed_flatten_subcommand() {
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 1 })
})
},
Opt::parse_from(&["test", "flame", "1"])
);
}
#[test]
fn update_boxed_flatten_subcommand() {
let mut opt = Opt::parse_from(&["test", "flame", "1"]);
opt.update_from(&["test", "flame", "42"]);
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 42 })
})
},
opt
);
}