From 9545075023af40106084e2993c94017d23eb6bfd Mon Sep 17 00:00:00 2001 From: TheAwiteb Date: Sun, 10 Sep 2023 10:07:31 +0300 Subject: [PATCH] Keep the `\n` in the `doc` comment as it is (don't replace it to newline) --- crates/teloxide-macros/src/command_attr.rs | 2 +- crates/teloxide/tests/command.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/teloxide-macros/src/command_attr.rs b/crates/teloxide-macros/src/command_attr.rs index a074d08e..58ca93e9 100644 --- a/crates/teloxide-macros/src/command_attr.rs +++ b/crates/teloxide-macros/src/command_attr.rs @@ -154,7 +154,7 @@ pub(crate) fn parse_doc_comment(attr: &Attribute) -> Option { if let syn::Meta::NameValue(syn::MetaNameValue { lit: syn::Lit::Str(s), .. }) = attr.parse_meta().ok()? { - return Some(s.value().trim().replace(r"\n", "\n")); + return Some(s.value().trim().to_owned()); } } None diff --git a/crates/teloxide/tests/command.rs b/crates/teloxide/tests/command.rs index 2598756b..84eadcd4 100644 --- a/crates/teloxide/tests/command.rs +++ b/crates/teloxide/tests/command.rs @@ -250,7 +250,7 @@ fn description_with_doc_attr() { enum DefaultCommands { /// Start command Start, - /// Help command\nwith new line + /// Help command\nwithout replace the `\n` Help, /// Foo command /// with new line @@ -259,8 +259,8 @@ fn description_with_doc_attr() { assert_eq!( DefaultCommands::descriptions().to_string(), - "/start — Start command\n/help — Help command\nwith new line\n/foo — Foo command\nwith \ - new line" + "/start — Start command\n/help — Help command\\nwithout replace the `\\n`\n/foo — Foo \ + command\nwith new line" ); }