mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
Merge pull request #837 from puuuuh/master
fix split parser for tuple struct with len <2
This commit is contained in:
commit
da00c9274b
3 changed files with 38 additions and 6 deletions
|
@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix `split` parser for tuple variants with len < 2 ([issue #834](https://github.com/teloxide/teloxide/issues/834))
|
||||
|
||||
## 0.7.1 - 2023-01-17
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -125,8 +125,8 @@ fn parser_with_separator<'a>(
|
|||
})?;
|
||||
|
||||
<#types>::from_str(s).map_err(|e| teloxide::utils::command::ParseError::IncorrectFormat(e.into()))?
|
||||
}
|
||||
),*
|
||||
},
|
||||
)*
|
||||
)
|
||||
}
|
||||
};
|
||||
|
@ -139,12 +139,12 @@ fn parser_with_separator<'a>(
|
|||
let res = #res;
|
||||
|
||||
match splitted.next() {
|
||||
Some(d) => ::std::result::Result::Err(teloxide::utils::command::ParseError::TooManyArguments {
|
||||
Some(d) if !s.is_empty() => ::std::result::Result::Err(teloxide::utils::command::ParseError::TooManyArguments {
|
||||
expected: #expected,
|
||||
found: #expected + 1,
|
||||
found: #expected + 1 + splitted.count(),
|
||||
message: format!("Excess argument: {}", d),
|
||||
}),
|
||||
None => ::std::result::Result::Ok(res)
|
||||
_ => ::std::result::Result::Ok(res)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -117,7 +117,7 @@ fn parse_with_split() {
|
|||
|
||||
assert_eq!(
|
||||
DefaultCommands::Start(10, "hello".to_string()),
|
||||
DefaultCommands::parse("/start 10 hello", "").unwrap()
|
||||
DefaultCommands::parse("/start 10 hello", "").unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -138,6 +138,34 @@ fn parse_with_split2() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn parse_with_split3() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
#[command(parse_with = "split")]
|
||||
enum DefaultCommands {
|
||||
Start(u8),
|
||||
Help,
|
||||
}
|
||||
|
||||
assert_eq!(DefaultCommands::Start(10), DefaultCommands::parse("/start 10", "").unwrap(),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn parse_with_split4() {
|
||||
#[derive(BotCommands, Debug, PartialEq)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
#[command(parse_with = "split")]
|
||||
enum DefaultCommands {
|
||||
Start(),
|
||||
Help,
|
||||
}
|
||||
|
||||
assert_eq!(DefaultCommands::Start(), DefaultCommands::parse("/start", "").unwrap(),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn parse_custom_parser() {
|
||||
|
|
Loading…
Reference in a new issue