clap/tests/derive/boxed.rs
Ed Page 177511dab1 fix: Deprecate validator / validator_os
`validator_regex` is being ignored for now as I await on a comment
period for #3743
2022-05-25 12:57:11 -05:00

49 lines
930 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 {
#[clap(value_parser)]
arg: u32,
}
#[test]
fn boxed_flatten_subcommand() {
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 1 })
})
},
Opt::try_parse_from(&["test", "flame", "1"]).unwrap()
);
}
#[test]
fn update_boxed_flatten_subcommand() {
let mut opt = Opt::try_parse_from(&["test", "flame", "1"]).unwrap();
opt.update_from(&["test", "flame", "42"]);
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 42 })
})
},
opt
);
}