internal: move some macro tests
This commit is contained in:
parent
c2e425dd00
commit
a060b9a4b2
@ -123,6 +123,9 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
|
||||
(IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ",
|
||||
(IDENT, _) if curr_kind.is_keyword() => " ",
|
||||
(_, IDENT) if prev_kind.is_keyword() => " ",
|
||||
(T![>], IDENT) => " ",
|
||||
(T![>], _) if curr_kind.is_keyword() => " ",
|
||||
(T![->], _) | (_, T![->]) => " ",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
@ -133,8 +136,9 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
|
||||
}
|
||||
|
||||
res.push_str(space);
|
||||
if space == "\n" && curr_kind != T!['}'] {
|
||||
res.push_str(&" ".repeat(indent_level));
|
||||
if space == "\n" {
|
||||
let level = if curr_kind == T!['}'] { indent_level - 1 } else { indent_level };
|
||||
res.push_str(&" ".repeat(level));
|
||||
}
|
||||
prev_kind = curr_kind;
|
||||
format_to!(res, "{}", token)
|
||||
|
@ -9,6 +9,45 @@
|
||||
|
||||
use crate::macro_expansion_tests::check;
|
||||
|
||||
#[test]
|
||||
fn mbe_smoke_test() {
|
||||
check(
|
||||
r#"
|
||||
macro_rules! impl_froms {
|
||||
($e:ident: $($v:ident),*) => {
|
||||
$(
|
||||
impl From<$v> for $e {
|
||||
fn from(it: $v) -> $e { $e::$v(it) }
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
impl_froms!(TokenTree: Leaf, Subtree);
|
||||
"#,
|
||||
expect![[r#"
|
||||
macro_rules! impl_froms {
|
||||
($e:ident: $($v:ident),*) => {
|
||||
$(
|
||||
impl From<$v> for $e {
|
||||
fn from(it: $v) -> $e { $e::$v(it) }
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
impl From<Leaf> for TokenTree {
|
||||
fn from(it:Leaf) -> TokenTree {
|
||||
TokenTree::Leaf(it)
|
||||
}
|
||||
}
|
||||
impl From<Subtree> for TokenTree {
|
||||
fn from(it:Subtree) -> TokenTree {
|
||||
TokenTree::Subtree(it)
|
||||
}
|
||||
}
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expansion_does_not_parse_as_expression() {
|
||||
check(
|
||||
|
@ -71,102 +71,6 @@ macro_rules! foobar {
|
||||
assert_eq!(get_text(tt::TokenId(13), T!['{']), "{");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_tt() {
|
||||
parse_macro(r#"
|
||||
macro_rules! impl_froms {
|
||||
($e:ident: $($v:ident),*) => {
|
||||
$(
|
||||
impl From<$v> for $e {
|
||||
fn from(it: $v) -> $e {
|
||||
$e::$v(it)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
"#)
|
||||
.assert_expand_tt(
|
||||
"impl_froms!(TokenTree: Leaf, Subtree);",
|
||||
"impl From <Leaf > for TokenTree {fn from (it : Leaf) -> TokenTree {TokenTree ::Leaf (it)}} \
|
||||
impl From <Subtree > for TokenTree {fn from (it : Subtree) -> TokenTree {TokenTree ::Subtree (it)}}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_tt2() {
|
||||
parse_macro(
|
||||
r#"
|
||||
macro_rules! impl_froms {
|
||||
($e:ident: $($v:ident),*) => {
|
||||
$(
|
||||
impl From<$v> for $e {
|
||||
fn from(it: $v) -> $e {
|
||||
$e::$v(it)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.assert_expand(
|
||||
"impl_froms!(TokenTree: Leaf, Subtree);",
|
||||
r#"
|
||||
SUBTREE $
|
||||
IDENT impl 20
|
||||
IDENT From 21
|
||||
PUNCH < [joint] 22
|
||||
IDENT Leaf 53
|
||||
PUNCH > [alone] 25
|
||||
IDENT for 26
|
||||
IDENT TokenTree 51
|
||||
SUBTREE {} 29
|
||||
IDENT fn 30
|
||||
IDENT from 31
|
||||
SUBTREE () 32
|
||||
IDENT it 33
|
||||
PUNCH : [alone] 34
|
||||
IDENT Leaf 53
|
||||
PUNCH - [joint] 37
|
||||
PUNCH > [alone] 38
|
||||
IDENT TokenTree 51
|
||||
SUBTREE {} 41
|
||||
IDENT TokenTree 51
|
||||
PUNCH : [joint] 44
|
||||
PUNCH : [joint] 45
|
||||
IDENT Leaf 53
|
||||
SUBTREE () 48
|
||||
IDENT it 49
|
||||
IDENT impl 20
|
||||
IDENT From 21
|
||||
PUNCH < [joint] 22
|
||||
IDENT Subtree 55
|
||||
PUNCH > [alone] 25
|
||||
IDENT for 26
|
||||
IDENT TokenTree 51
|
||||
SUBTREE {} 29
|
||||
IDENT fn 30
|
||||
IDENT from 31
|
||||
SUBTREE () 32
|
||||
IDENT it 33
|
||||
PUNCH : [alone] 34
|
||||
IDENT Subtree 55
|
||||
PUNCH - [joint] 37
|
||||
PUNCH > [alone] 38
|
||||
IDENT TokenTree 51
|
||||
SUBTREE {} 41
|
||||
IDENT TokenTree 51
|
||||
PUNCH : [joint] 44
|
||||
PUNCH : [joint] 45
|
||||
IDENT Subtree 55
|
||||
SUBTREE () 48
|
||||
IDENT it 49
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_match_group_with_multichar_sep() {
|
||||
parse_macro(
|
||||
|
Loading…
Reference in New Issue
Block a user