aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src/tests
diff options
context:
space:
mode:
authorChayim Refael Friedman <[email protected]>2021-04-18 01:16:38 +0100
committerChayim Refael Friedman <[email protected]>2021-04-18 01:16:38 +0100
commitf92be7eaabe27387a2d860c3842443bf32e99c73 (patch)
tree966d0d870973548ccf771126c23df693b2d392fc /crates/mbe/src/tests
parentbb1d925dab36372c6bd1fb5671bb68ce938ff009 (diff)
Escape characters in doc comments in macros correctly
Previously they were escaped twice, both by `.escape_default()` and the debug view of strings (`{:?}`). This leads to things like newlines or tabs in documentation comments being `\\n`, but we unescape literals only once, ending up with `\n`. This was hard to spot because CMark unescaped them (at least for `'` and `"`), but it did not do so in code blocks. This also was the root cause of #7781. This issue was solved by using `.escape_debug()` instead of `.escape_default()`, but the real issue remained. We can bring the `.escape_default()` back by now, however I didn't do it because it is probably slower than `.escape_debug()` (more work to do), and also in order to change the code the least.
Diffstat (limited to 'crates/mbe/src/tests')
-rw-r--r--crates/mbe/src/tests/expand.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 8951f3813..84f19d3e2 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -921,7 +921,7 @@ fn test_meta_doc_comments() {
921 MultiLines Doc 921 MultiLines Doc
922 */ 922 */
923 }"#, 923 }"#,
924 "# [doc = \" Single Line Doc 1\"] # [doc = \"\\\\n MultiLines Doc\\\\n \"] fn bar () {}", 924 "# [doc = \" Single Line Doc 1\"] # [doc = \"\\n MultiLines Doc\\n \"] fn bar () {}",
925 ); 925 );
926} 926}
927 927
@@ -944,7 +944,27 @@ fn test_meta_doc_comments_non_latin() {
944 莊生曉夢迷蝴蝶,望帝春心託杜鵑。 944 莊生曉夢迷蝴蝶,望帝春心託杜鵑。
945 */ 945 */
946 }"#, 946 }"#,
947 "# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\\\n \"] fn bar () {}", 947 "# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\n \"] fn bar () {}",
948 );
949}
950
951#[test]
952fn test_meta_doc_comments_escaped_characters() {
953 parse_macro(
954 r#"
955 macro_rules! foo {
956 ($(#[$ i:meta])+) => (
957 $(#[$ i])+
958 fn bar() {}
959 )
960 }
961"#,
962 )
963 .assert_expand_items(
964 r#"foo! {
965 /// \ " '
966 }"#,
967 r#"# [doc = " \\ \" \'"] fn bar () {}"#,
948 ); 968 );
949} 969}
950 970