fixup tests and examples that use derive(BotCommands)

Former-commit-id: dc652da1ac
This commit is contained in:
Maybe Waffle 2022-10-05 10:08:50 +04:00
parent 71ad64594d
commit 529a316b0f
11 changed files with 39 additions and 44 deletions

View file

@ -133,7 +133,7 @@ async fn main() {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command {
#[command(description = "display this text.")]
Help,

View file

@ -14,7 +14,7 @@ use teloxide::{prelude::*, types::ChatPermissions, utils::command::BotCommands};
// %PREFIX%%COMMAND% - %DESCRIPTION%
#[derive(BotCommands, Clone)]
#[command(
rename = "lowercase",
rename_rule = "lowercase",
description = "Use commands in format /%command% %num% %unit%",
parse_with = "split"
)]

View file

@ -10,7 +10,7 @@ use teloxide::{
};
#[derive(BotCommands)]
#[command(rename = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command {
#[command(description = "Display this text")]
Help,

View file

@ -11,7 +11,7 @@ async fn main() {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command {
#[command(description = "display this text.")]
Help,

View file

@ -22,7 +22,7 @@ pub enum State {
}
#[derive(Clone, BotCommands)]
#[command(rename = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
pub enum Command {
#[command(description = "get your number.")]
Get,

View file

@ -96,7 +96,7 @@ struct ConfigParameters {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "Simple commands")]
#[command(rename_rule = "lowercase", description = "Simple commands")]
enum SimpleCommand {
#[command(description = "shows this message.")]
Help,
@ -107,7 +107,7 @@ enum SimpleCommand {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "Maintainer commands")]
#[command(rename_rule = "lowercase", description = "Maintainer commands")]
enum MaintainerCommands {
#[command(parse_with = "split", description = "generate a number within range")]
Rand { from: u64, to: u64 },

View file

@ -33,7 +33,7 @@ pub enum State {
}
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command {
#[command(description = "display this text.")]
Help,

View file

@ -25,7 +25,7 @@
//! ```no_run
//! # use teloxide::utils::command::BotCommands;
//! #[derive(BotCommands, Clone)]
//! #[command(rename = "lowercase", description = "These commands are supported:")]
//! #[command(rename_rule = "lowercase", description = "These commands are supported:")]
//! enum Command {
//! #[command(description = "display this text.")]
//! Help,

View file

@ -86,7 +86,7 @@ mod tests {
use crate as teloxide; // fixup for the `BotCommands` macro
#[derive(BotCommands, Clone)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum Cmd {
B,
}

View file

@ -13,7 +13,7 @@
//! type UnitOfTime = u8;
//!
//! #[derive(BotCommands, PartialEq, Debug)]
//! #[command(rename = "lowercase", parse_with = "split")]
//! #[command(rename_rule = "lowercase", parse_with = "split")]
//! enum AdminCommand {
//! Mute(UnitOfTime, char),
//! Ban(UnitOfTime, char),
@ -70,7 +70,7 @@ pub use teloxide_macros::BotCommands;
/// type UnitOfTime = u8;
///
/// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase", parse_with = "split")]
/// #[command(rename_rule = "lowercase", parse_with = "split")]
/// enum AdminCommand {
/// Mute(UnitOfTime, char),
/// Ban(UnitOfTime, char),
@ -105,7 +105,7 @@ pub use teloxide_macros::BotCommands;
/// use teloxide::utils::command::BotCommands;
///
/// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase")]
/// #[command(rename_rule = "lowercase")]
/// enum Command {
/// Text(String),
/// }
@ -125,7 +125,7 @@ pub use teloxide_macros::BotCommands;
/// use teloxide::utils::command::BotCommands;
///
/// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase", parse_with = "split")]
/// #[command(rename_rule = "lowercase", parse_with = "split")]
/// enum Command {
/// Nums(u8, u16, i32),
/// }
@ -145,7 +145,7 @@ pub use teloxide_macros::BotCommands;
/// use teloxide::utils::command::BotCommands;
///
/// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase", parse_with = "split", separator = "|")]
/// #[command(rename_rule = "lowercase", parse_with = "split", separator = "|")]
/// enum Command {
/// Nums(u8, u16, i32),
/// }
@ -192,7 +192,7 @@ pub use teloxide_macros::BotCommands;
/// }
///
/// #[derive(BotCommands, PartialEq, Debug)]
/// #[command(rename = "lowercase")]
/// #[command(rename_rule = "lowercase")]
/// enum Command {
/// #[command(parse_with = "accept_two_digits")]
/// Num(u8),

View file

@ -11,7 +11,7 @@ use teloxide::utils::command::BotCommands;
#[cfg(feature = "macros")]
fn parse_command_with_args() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
Start(String),
Help,
@ -27,7 +27,7 @@ fn parse_command_with_args() {
#[cfg(feature = "macros")]
fn parse_command_with_non_string_arg() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
Start(i32),
Help,
@ -43,7 +43,7 @@ fn parse_command_with_non_string_arg() {
#[cfg(feature = "macros")]
fn attribute_prefix() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
#[command(prefix = "!")]
Start(String),
@ -60,7 +60,7 @@ fn attribute_prefix() {
#[cfg(feature = "macros")]
fn many_attributes() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
#[command(prefix = "!", description = "desc")]
Start,
@ -75,7 +75,7 @@ fn many_attributes() {
#[cfg(feature = "macros")]
fn global_attributes() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(prefix = "!", rename = "lowercase", description = "Bot commands")]
#[command(prefix = "!", rename_rule = "lowercase", description = "Bot commands")]
enum DefaultCommands {
#[command(prefix = "/")]
Start,
@ -91,7 +91,7 @@ fn global_attributes() {
#[cfg(feature = "macros")]
fn parse_command_with_bot_name() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
#[command(prefix = "/")]
Start,
@ -108,7 +108,7 @@ fn parse_command_with_bot_name() {
#[cfg(feature = "macros")]
fn parse_with_split() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
#[command(parse_with = "split")]
enum DefaultCommands {
Start(u8, String),
@ -125,7 +125,7 @@ fn parse_with_split() {
#[cfg(feature = "macros")]
fn parse_with_split2() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
#[command(parse_with = "split", separator = "|")]
enum DefaultCommands {
Start(u8, String),
@ -159,7 +159,7 @@ fn parse_custom_parser() {
use parser::custom_parse_function;
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
#[command(parse_with = "custom_parse_function")]
Start(u8, String),
@ -185,7 +185,7 @@ fn parse_custom_parser() {
#[cfg(feature = "macros")]
fn parse_named_fields() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
#[command(parse_with = "split")]
enum DefaultCommands {
Start { num: u8, data: String },
@ -202,7 +202,7 @@ fn parse_named_fields() {
#[cfg(feature = "macros")]
fn descriptions_off() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
enum DefaultCommands {
#[command(description = "off")]
Start,
@ -217,24 +217,24 @@ fn descriptions_off() {
fn rename_rules() {
#[derive(BotCommands, Debug, PartialEq)]
enum DefaultCommands {
#[command(rename = "lowercase")]
#[command(rename_rule = "lowercase")]
AaaAaa,
#[command(rename = "UPPERCASE")]
#[command(rename_rule = "UPPERCASE")]
BbbBbb,
#[command(rename = "PascalCase")]
#[command(rename_rule = "PascalCase")]
CccCcc,
#[command(rename = "camelCase")]
#[command(rename_rule = "camelCase")]
DddDdd,
#[command(rename = "snake_case")]
#[command(rename_rule = "snake_case")]
EeeEee,
#[command(rename = "SCREAMING_SNAKE_CASE")]
#[command(rename_rule = "SCREAMING_SNAKE_CASE")]
FffFff,
#[command(rename = "kebab-case")]
#[command(rename_rule = "kebab-case")]
GggGgg,
#[command(rename = "SCREAMING-KEBAB-CASE")]
#[command(rename_rule = "SCREAMING-KEBAB-CASE")]
HhhHhh,
//#[command(rename = "Bar")]
//Foo,
#[command(rename = "Bar")]
Foo,
}
assert_eq!(DefaultCommands::AaaAaa, DefaultCommands::parse("/aaaaaa", "").unwrap());
@ -245,15 +245,10 @@ fn rename_rules() {
assert_eq!(DefaultCommands::FffFff, DefaultCommands::parse("/FFF_FFF", "").unwrap());
assert_eq!(DefaultCommands::GggGgg, DefaultCommands::parse("/ggg-ggg", "").unwrap());
assert_eq!(DefaultCommands::HhhHhh, DefaultCommands::parse("/HHH-HHH", "").unwrap());
//assert_eq!(DefaultCommands::Foo, DefaultCommands::parse("/Bar",
// "").unwrap());
assert_eq!(DefaultCommands::Foo, DefaultCommands::parse("/Bar", "").unwrap());
// assert_eq!(
// "/aaaaaa\n/BBBBBB\n/CccCcc\n/dddDdd\n/eee_eee\n/FFF_FFF\n/ggg-ggg\n/
// HHH-HHH\n/Bar", DefaultCommands::descriptions().to_string()
// );
assert_eq!(
"/aaaaaa\n/BBBBBB\n/CccCcc\n/dddDdd\n/eee_eee\n/FFF_FFF\n/ggg-ggg\n/HHH-HHH",
"/aaaaaa\n/BBBBBB\n/CccCcc\n/dddDdd\n/eee_eee\n/FFF_FFF\n/ggg-ggg\n/HHH-HHH\n/Bar",
DefaultCommands::descriptions().to_string()
);
}