mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-05 10:24:32 +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
|
## 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
|
## 0.7.1 - 2023-01-17
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -125,8 +125,8 @@ fn parser_with_separator<'a>(
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
<#types>::from_str(s).map_err(|e| teloxide::utils::command::ParseError::IncorrectFormat(e.into()))?
|
<#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;
|
let res = #res;
|
||||||
|
|
||||||
match splitted.next() {
|
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,
|
expected: #expected,
|
||||||
found: #expected + 1,
|
found: #expected + 1 + splitted.count(),
|
||||||
message: format!("Excess argument: {}", d),
|
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!(
|
assert_eq!(
|
||||||
DefaultCommands::Start(10, "hello".to_string()),
|
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]
|
#[test]
|
||||||
#[cfg(feature = "macros")]
|
#[cfg(feature = "macros")]
|
||||||
fn parse_custom_parser() {
|
fn parse_custom_parser() {
|
||||||
|
|
Loading…
Reference in a new issue