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)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase", description = "These commands are supported:")] #[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command { enum Command {
#[command(description = "display this text.")] #[command(description = "display this text.")]
Help, Help,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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