Skip to content

Commit

Permalink
Fix and add choice name override tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kovaxis committed Feb 4, 2025
1 parent 61b5745 commit 9388137
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion argh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@
//! use argh::{FromArgs, FromArgValue};
//!
//! #[derive(FromArgValue)]
//! struct Mode {
//! enum Mode {
//! SoftCore,
//! HardCore,
//! }
//!
//! #[derive(FromArgs)]
//! /// Do the thing.
//! struct DoIt {
//! #[argh(option)]
//! /// how to do it
//! how: Mode,
//! }
//!
Expand Down
11 changes: 10 additions & 1 deletion argh/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ Options:
#[derive(FromArgValue, PartialEq, Debug)]
enum ThreeChoices {
FirstChoice,
#[argh(name = "に")]
Two,
Three,
}
Expand Down Expand Up @@ -574,11 +575,19 @@ Options:
)
}

#[test]
fn with_name_override() {
assert_output(
&["--choice2", "に", "--choice1", "hola"],
WithChoices { choice1: TwoChoices::Hola, choice2: ThreeChoices::Two },
)
}

#[test]
fn invalid_choice() {
assert_error::<WithChoices>(
&["--choice2", "something"],
r###"Error parsing option '--choice2' with value 'something': expected "first_choice", "two" or "three"
r###"Error parsing option '--choice2' with value 'something': expected "first_choice", "" or "three"
"###,
)
}
Expand Down

0 comments on commit 9388137

Please sign in to comment.