internal: allow macro tests to inspect parse tree
This commit is contained in:
parent
aac23f7832
commit
c41b7bbe69
@ -69,6 +69,13 @@ fn check(ra_fixture: &str, mut expect: Expect) {
|
||||
let indent = IndentLevel::from_node(call.syntax());
|
||||
let pp = reindent(indent, pp);
|
||||
format_to!(expn_text, "{}", pp);
|
||||
if call.to_string().contains("// +tree") {
|
||||
let tree = format!("{:#?}", parse.syntax_node())
|
||||
.split_inclusive("\n")
|
||||
.map(|line| format!("// {}", line))
|
||||
.collect::<String>();
|
||||
format_to!(expn_text, "\n{}", tree)
|
||||
}
|
||||
}
|
||||
let range = call.syntax().text_range();
|
||||
let range: Range<usize> = range.into();
|
||||
|
@ -261,3 +261,49 @@ fn baz() {
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_order() {
|
||||
check(
|
||||
r#"
|
||||
macro_rules! m {
|
||||
($ i:expr) => { fn bar() { $ i * 3; } }
|
||||
}
|
||||
// +tree
|
||||
m! { 1 + 2 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
macro_rules! m {
|
||||
($ i:expr) => { fn bar() { $ i * 3; } }
|
||||
}
|
||||
fn bar() {
|
||||
1+2*3;
|
||||
}
|
||||
// MACRO_ITEMS@0..15
|
||||
// FN@0..15
|
||||
// FN_KW@0..2 "fn"
|
||||
// NAME@2..5
|
||||
// IDENT@2..5 "bar"
|
||||
// PARAM_LIST@5..7
|
||||
// L_PAREN@5..6 "("
|
||||
// R_PAREN@6..7 ")"
|
||||
// BLOCK_EXPR@7..15
|
||||
// STMT_LIST@7..15
|
||||
// L_CURLY@7..8 "{"
|
||||
// EXPR_STMT@8..14
|
||||
// BIN_EXPR@8..13
|
||||
// BIN_EXPR@8..11
|
||||
// LITERAL@8..9
|
||||
// INT_NUMBER@8..9 "1"
|
||||
// PLUS@9..10 "+"
|
||||
// LITERAL@10..11
|
||||
// INT_NUMBER@10..11 "2"
|
||||
// STAR@11..12 "*"
|
||||
// LITERAL@12..13
|
||||
// INT_NUMBER@12..13 "3"
|
||||
// SEMICOLON@13..14 ";"
|
||||
// R_CURLY@14..15 "}"
|
||||
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
@ -166,48 +166,6 @@ SUBTREE $
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expr_order() {
|
||||
let expanded = parse_macro(
|
||||
r#"
|
||||
macro_rules! foo {
|
||||
($ i:expr) => {
|
||||
fn bar() { $ i * 2; }
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.expand_items("foo! { 1 + 1}");
|
||||
|
||||
let dump = format!("{:#?}", expanded);
|
||||
assert_eq_text!(
|
||||
r#"MACRO_ITEMS@0..15
|
||||
FN@0..15
|
||||
FN_KW@0..2 "fn"
|
||||
NAME@2..5
|
||||
IDENT@2..5 "bar"
|
||||
PARAM_LIST@5..7
|
||||
L_PAREN@5..6 "("
|
||||
R_PAREN@6..7 ")"
|
||||
BLOCK_EXPR@7..15
|
||||
STMT_LIST@7..15
|
||||
L_CURLY@7..8 "{"
|
||||
EXPR_STMT@8..14
|
||||
BIN_EXPR@8..13
|
||||
BIN_EXPR@8..11
|
||||
LITERAL@8..9
|
||||
INT_NUMBER@8..9 "1"
|
||||
PLUS@9..10 "+"
|
||||
LITERAL@10..11
|
||||
INT_NUMBER@10..11 "1"
|
||||
STAR@11..12 "*"
|
||||
LITERAL@12..13
|
||||
INT_NUMBER@12..13 "2"
|
||||
SEMICOLON@13..14 ";"
|
||||
R_CURLY@14..15 "}""#,
|
||||
dump.trim()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_group_with_multichar_sep() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user