hide_aliases tests

This commit is contained in:
TheAwiteb 2023-09-25 16:19:58 +03:00
parent ed90485fdf
commit f3281b6eac
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34

View file

@ -489,6 +489,93 @@ fn aliases_help_message() {
);
}
#[test]
#[cfg(feature = "macros")]
fn hide_aliases_for_unaliases_command() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename_rule = "snake_case")]
enum DefaultCommands {
/// Start command.
Start,
/// Show help message.
#[command(hide_aliases)]
Help,
}
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/start", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/help", "").unwrap());
assert_eq!(
"/start — Start command.\n/help — Show help message.",
DefaultCommands::descriptions().to_string()
);
}
#[test]
#[cfg(feature = "macros")]
fn hide_aliases_with_alias() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename_rule = "snake_case")]
enum DefaultCommands {
/// Start.
#[command(alias = "s")]
Start,
/// Help.
#[command(alias = "h", hide_aliases)]
Help,
}
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/start", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/help", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/h", "").unwrap());
assert_eq!("/start, /s — Start.\n/help — Help.", DefaultCommands::descriptions().to_string());
}
#[test]
#[cfg(feature = "macros")]
fn hide_command_with_aliases() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename_rule = "snake_case")]
enum DefaultCommands {
/// Start.
#[command(alias = "s", hide)]
Start,
/// Help.
#[command(alias = "h")]
Help,
}
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/start", "").unwrap());
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/s", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/help", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/h", "").unwrap());
assert_eq!("/help, /h — Help.", DefaultCommands::descriptions().to_string());
}
#[test]
#[cfg(feature = "macros")]
fn hide_aliases_with_aliases() {
#[derive(BotCommands, Debug, PartialEq)]
#[command(rename_rule = "snake_case")]
enum DefaultCommands {
#[command(aliases = ["s", "старт"])]
Start,
#[command(aliases = ["h", "помощь"], hide_aliases)]
Help,
}
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/start", "").unwrap());
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/s", "").unwrap());
assert_eq!(DefaultCommands::Start, DefaultCommands::parse("/старт", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/help", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/h", "").unwrap());
assert_eq!(DefaultCommands::Help, DefaultCommands::parse("/помощь", "").unwrap());
assert_eq!("/start, /s, /старт\n/help", DefaultCommands::descriptions().to_string());
}
#[test]
#[cfg(feature = "macros")]
fn custom_result() {