internal: move some mbe tests

This commit is contained in:
Aleksey Kladov 2021-10-09 23:33:43 +03:00
parent f17f5d68f9
commit e9902b92ab
3 changed files with 75 additions and 52 deletions

View File

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

View File

@ -704,3 +704,77 @@ fn foo() {
"#]],
);
}
#[test]
fn test_expr() {
check(
r#"
macro_rules! m {
($e:expr) => { fn bar() { $e; } }
}
m! { 2 + 2 * baz(3).quux() }
"#,
expect![[r#"
macro_rules! m {
($e:expr) => { fn bar() { $e; } }
}
fn bar() {
2+2*baz(3).quux();
}
"#]],
)
}
#[test]
fn test_last_expr() {
check(
r#"
macro_rules! vec {
($($item:expr),*) => {{
let mut v = Vec::new();
$( v.push($item); )*
v
}};
}
fn f() {
vec![1,2,3];
}
"#,
expect![[r#"
macro_rules! vec {
($($item:expr),*) => {{
let mut v = Vec::new();
$( v.push($item); )*
v
}};
}
fn f() {
{
let mut v = Vec::new();
v.push(1);
v.push(2);
v.push(3);
v
};
}
"#]],
);
}
#[test]
fn test_expr_with_attr() {
check(
r#"
macro_rules! m { ($a:expr) => { x!(); } }
m!(#[allow(a)]());
"#,
expect![[r#"
macro_rules! m { ($a:expr) => { x!(); } }
x!();
"#]],
)
}

View File

@ -101,58 +101,6 @@ fn test_attr_to_token_tree() {
);
}
#[test]
fn test_expr() {
parse_macro(
r#"
macro_rules! foo {
($ i:expr) => {
fn bar() { $ i; }
}
}
"#,
)
.assert_expand_items(
"foo! { 2 + 2 * baz(3).quux() }",
"fn bar () {2 + 2 * baz (3) . quux () ;}",
);
}
#[test]
fn test_last_expr() {
parse_macro(
r#"
macro_rules! vec {
($($item:expr),*) => {
{
let mut v = Vec::new();
$(
v.push($item);
)*
v
}
};
}
"#,
)
.assert_expand_items(
"vec!(1,2,3);",
"{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}",
);
}
#[test]
fn test_expr_with_attr() {
parse_macro(
r#"
macro_rules! m {
($a:expr) => {0}
}
"#,
)
.assert_expand_items("m!(#[allow(a)]())", "0");
}
#[test]
fn test_ty() {
parse_macro(