Unnamed repository; edit this file 'description' to name the repository.
internal: allow macro tests to inspect parse tree
| -rw-r--r-- | crates/hir_def/src/macro_expansion_tests.rs | 7 | ||||
| -rw-r--r-- | crates/hir_def/src/macro_expansion_tests/mbe.rs | 46 | ||||
| -rw-r--r-- | crates/mbe/src/tests/expand.rs | 42 |
3 files changed, 53 insertions, 42 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs index ac0a2d27b3..0a9ab93157 100644 --- a/crates/hir_def/src/macro_expansion_tests.rs +++ b/crates/hir_def/src/macro_expansion_tests.rs @@ -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(); diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index f1e979503e..7c9a19613b 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -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; +} +// [email protected] "fn" +// [email protected] "bar" +// [email protected] "(" +// [email protected] ")" +// [email protected] "{" +// [email protected] "1" +// [email protected] "+" +// [email protected] "2" +// [email protected] "*" +// [email protected] "3" +// [email protected] ";" +// [email protected] "}" + +"#]], + ) +} diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 3655cb5a63..85a51588eb 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -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#"[email protected] - [email protected] "fn" - [email protected] "bar" - [email protected] "(" - [email protected] ")" - [email protected] "{" - [email protected] "1" - [email protected] "+" - [email protected] "1" - [email protected] "*" - [email protected] "2" - [email protected] ";" - [email protected] "}""#, - dump.trim() - ); -} #[test] fn test_match_group_with_multichar_sep() { |