move tests

This commit is contained in:
Aleksey Kladov 2021-10-10 11:39:08 +03:00
parent 7e53a3ce23
commit a3470a8114
4 changed files with 89 additions and 84 deletions

View file

@ -131,6 +131,7 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
(T![,], _) => " ",
(T![fn], T!['(']) => "",
(T![']'], _) if curr_kind.is_keyword() => " ",
(T![']'], T![#]) => "\n",
_ if prev_kind.is_keyword() => " ",
_ => "",
};

View file

@ -956,3 +956,90 @@ macro_rules! m {
"##]],
);
}
#[test]
fn test_meta_doc_comments() {
cov_mark::check!(test_meta_doc_comments);
check(
r#"
macro_rules! m {
($(#[$m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
m! {
/// Single Line Doc 1
/**
MultiLines Doc
*/
}
"#,
expect![[r##"
macro_rules! m {
($(#[$m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
#[doc = " Single Line Doc 1"]
#[doc = "\n MultiLines Doc\n "] fn bar() {}
"##]],
);
}
#[test]
fn test_meta_extended_key_value_attributes() {
check(
r#"
macro_rules! m {
(#[$m:meta]) => ( #[$m] fn bar() {} )
}
m! { #[doc = concat!("The `", "bla", "` lang item.")] }
"#,
expect![[r##"
macro_rules! m {
(#[$m:meta]) => ( #[$m] fn bar() {} )
}
#[doc = concat!("The `", "bla", "` lang item.")] fn bar() {}
"##]],
);
}
#[test]
fn test_meta_doc_comments_non_latin() {
check(
r#"
macro_rules! m {
($(#[$ m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
m! {
/// 錦瑟無端五十弦,一弦一柱思華年。
/**
*/
}
"#,
expect![[r##"
macro_rules! m {
($(#[$ m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
#[doc = " 錦瑟無端五十弦,一弦一柱思華年。"]
#[doc = "\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\n "] fn bar() {}
"##]],
);
}
#[test]
fn test_meta_doc_comments_escaped_characters() {
check(
r#"
macro_rules! m {
($(#[$m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
m! {
/// \ " '
}
"#,
expect![[r##"
macro_rules! m {
($(#[$m:meta])+) => ( $(#[$m])+ fn bar() {} )
}
#[doc = " \\ \" \'"] fn bar() {}
"##]],
);
}

View file

@ -307,6 +307,7 @@ fn doc_comment_text(comment: &ast::Comment) -> SmolStr {
}
fn convert_doc_comment(token: &syntax::SyntaxToken) -> Option<Vec<tt::TokenTree>> {
cov_mark::hit!(test_meta_doc_comments);
let comment = ast::Comment::cast(token.clone())?;
let doc = comment.kind().doc?;

View file

@ -101,90 +101,6 @@ fn test_attr_to_token_tree() {
);
}
#[test]
fn test_meta_doc_comments() {
parse_macro(
r#"
macro_rules! foo {
($(#[$ i:meta])+) => (
$(#[$ i])+
fn bar() {}
)
}
"#,
).
assert_expand_items(
r#"foo! {
/// Single Line Doc 1
/**
MultiLines Doc
*/
}"#,
"# [doc = \" Single Line Doc 1\"] # [doc = \"\\n MultiLines Doc\\n \"] fn bar () {}",
);
}
#[test]
fn test_meta_extended_key_value_attributes() {
parse_macro(
r#"
macro_rules! foo {
(#[$i:meta]) => (
#[$ i]
fn bar() {}
)
}
"#,
)
.assert_expand_items(
r#"foo! { #[doc = concat!("The `", "bla", "` lang item.")] }"#,
r#"# [doc = concat ! ("The `" , "bla" , "` lang item.")] fn bar () {}"#,
);
}
#[test]
fn test_meta_doc_comments_non_latin() {
parse_macro(
r#"
macro_rules! foo {
($(#[$ i:meta])+) => (
$(#[$ i])+
fn bar() {}
)
}
"#,
).
assert_expand_items(
r#"foo! {
/// 錦瑟無端五十弦,一弦一柱思華年。
/**
*/
}"#,
"# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\n \"] fn bar () {}",
);
}
#[test]
fn test_meta_doc_comments_escaped_characters() {
parse_macro(
r#"
macro_rules! foo {
($(#[$ i:meta])+) => (
$(#[$ i])+
fn bar() {}
)
}
"#,
)
.assert_expand_items(
r#"foo! {
/// \ " '
}"#,
r#"# [doc = " \\ \" \'"] fn bar () {}"#,
);
}
#[test]
fn test_tt_block() {
parse_macro(