clap/tests/derive/boxed.rs

49 lines
920 B
Rust
Raw Normal View History

use clap::{Args, Parser, Subcommand};
2020-02-13 15:21:01 +00:00
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[command(subcommand)]
sub: Box<Sub>,
}
2020-02-13 15:21:01 +00:00
#[derive(Subcommand, PartialEq, Debug)]
enum Sub {
Flame {
#[command(flatten)]
arg: Box<Ext>,
},
}
2020-02-13 15:21:01 +00:00
#[derive(Args, PartialEq, Debug)]
struct Ext {
arg: u32,
}
2020-02-13 15:21:01 +00:00
#[test]
fn boxed_flatten_subcommand() {
2020-02-13 15:21:01 +00:00
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 1 })
})
},
2022-11-24 13:54:25 +00:00
Opt::try_parse_from(["test", "flame", "1"]).unwrap()
2020-02-13 15:21:01 +00:00
);
}
#[test]
fn update_boxed_flatten_subcommand() {
2022-11-24 13:54:25 +00:00
let mut opt = Opt::try_parse_from(["test", "flame", "1"]).unwrap();
2023-01-10 02:52:06 +00:00
opt.try_update_from(["test", "flame", "42"]).unwrap();
assert_eq!(
Opt {
sub: Box::new(Sub::Flame {
arg: Box::new(Ext { arg: 42 })
})
},
opt
);
}