mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
b190a6a817
This reduces the need for us to have `clap` as a dependency in `clap_derive`, preparing the way to fix #15.
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use clap::Parser;
|
|
|
|
use crate::utils;
|
|
|
|
#[test]
|
|
fn default_value() {
|
|
#[derive(Parser, PartialEq, Debug)]
|
|
struct Opt {
|
|
#[clap(default_value = "3")]
|
|
arg: i32,
|
|
}
|
|
assert_eq!(Opt { arg: 3 }, Opt::try_parse_from(&["test"]).unwrap());
|
|
assert_eq!(Opt { arg: 1 }, Opt::try_parse_from(&["test", "1"]).unwrap());
|
|
|
|
let help = utils::get_long_help::<Opt>();
|
|
assert!(help.contains("[default: 3]"));
|
|
}
|
|
|
|
#[test]
|
|
fn default_value_t() {
|
|
#[derive(Parser, PartialEq, Debug)]
|
|
struct Opt {
|
|
#[clap(default_value_t = 3)]
|
|
arg: i32,
|
|
}
|
|
assert_eq!(Opt { arg: 3 }, Opt::try_parse_from(&["test"]).unwrap());
|
|
assert_eq!(Opt { arg: 1 }, Opt::try_parse_from(&["test", "1"]).unwrap());
|
|
|
|
let help = utils::get_long_help::<Opt>();
|
|
assert!(help.contains("[default: 3]"));
|
|
}
|
|
|
|
#[test]
|
|
fn auto_default_value_t() {
|
|
#[derive(Parser, PartialEq, Debug)]
|
|
struct Opt {
|
|
#[clap(default_value_t)]
|
|
arg: i32,
|
|
}
|
|
assert_eq!(Opt { arg: 0 }, Opt::try_parse_from(&["test"]).unwrap());
|
|
assert_eq!(Opt { arg: 1 }, Opt::try_parse_from(&["test", "1"]).unwrap());
|
|
|
|
let help = utils::get_long_help::<Opt>();
|
|
assert!(help.contains("[default: 0]"));
|
|
}
|