mirror of
https://github.com/teloxide/teloxide.git
synced 2024-10-24 01:47:08 +02:00
Merge pull request #564 from teloxide/update-docs
Documen and test all command renaming rules
This commit is contained in:
commit
e3be9cc9a8
3 changed files with 43 additions and 3 deletions
|
@ -59,7 +59,7 @@ full = [
|
|||
|
||||
[dependencies]
|
||||
teloxide-core = { version = "0.4", default-features = false }
|
||||
teloxide-macros = { version = "0.5", optional = true }
|
||||
teloxide-macros = { version = "0.5.1", optional = true }
|
||||
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
|
|
@ -78,8 +78,10 @@ pub use teloxide_macros::BotCommand;
|
|||
///
|
||||
/// # Enum attributes
|
||||
/// 1. `#[command(rename = "rule")]`
|
||||
/// Rename all commands by `rule`. Allowed rules are `lowercase`. If you will
|
||||
/// not use this attribute, commands will be parsed by their original names.
|
||||
/// Rename all commands by `rule`. If you will not use this attribute, commands
|
||||
/// will be parsed by their original names. Allowed rules are `lowercase`,
|
||||
/// `UPPERCASE`, `PascalCase`, `camelCase`, `snake_case`,
|
||||
/// `SCREAMING_SNAKE_CASE`, `kebab-case`, and `SCREAMING-KEBAB-CASE`.
|
||||
///
|
||||
/// 2. `#[command(prefix = "prefix")]`
|
||||
/// Change a prefix for all commands (the default is `/`).
|
||||
|
|
|
@ -196,3 +196,41 @@ fn descriptions_off() {
|
|||
|
||||
assert_eq!(DefaultCommands::descriptions(), "/help\n".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn rename_rules() {
|
||||
#[derive(BotCommand, Debug, PartialEq)]
|
||||
enum DefaultCommands {
|
||||
#[command(rename = "lowercase")]
|
||||
AaaAaa,
|
||||
#[command(rename = "UPPERCASE")]
|
||||
BbbBbb,
|
||||
#[command(rename = "PascalCase")]
|
||||
CccCcc,
|
||||
#[command(rename = "camelCase")]
|
||||
DddDdd,
|
||||
#[command(rename = "snake_case")]
|
||||
EeeEee,
|
||||
#[command(rename = "SCREAMING_SNAKE_CASE")]
|
||||
FffFff,
|
||||
#[command(rename = "kebab-case")]
|
||||
GggGgg,
|
||||
#[command(rename = "SCREAMING-KEBAB-CASE")]
|
||||
HhhHhh,
|
||||
}
|
||||
|
||||
assert_eq!(DefaultCommands::AaaAaa, DefaultCommands::parse("/aaaaaa", "").unwrap());
|
||||
assert_eq!(DefaultCommands::BbbBbb, DefaultCommands::parse("/BBBBBB", "").unwrap());
|
||||
assert_eq!(DefaultCommands::CccCcc, DefaultCommands::parse("/CccCcc", "").unwrap());
|
||||
assert_eq!(DefaultCommands::DddDdd, DefaultCommands::parse("/dddDdd", "").unwrap());
|
||||
assert_eq!(DefaultCommands::EeeEee, DefaultCommands::parse("/eee_eee", "").unwrap());
|
||||
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!(
|
||||
"/aaaaaa\n/BBBBBB\n/CccCcc\n/dddDdd\n/eee_eee\n/FFF_FFF\n/ggg-ggg\n/HHH-HHH\n",
|
||||
DefaultCommands::descriptions()
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue