Unnamed repository; edit this file 'description' to name the repository.
move some tests
Aleksey Kladov 2021-10-09
parent cb1b6a2 · commit 036c0ff
-rw-r--r--crates/hir_def/src/macro_expansion_tests.rs4
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe.rs63
-rw-r--r--crates/mbe/src/tests/expand.rs42
3 files changed, 66 insertions, 43 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs
index b14f484e76..d4520939b6 100644
--- a/crates/hir_def/src/macro_expansion_tests.rs
+++ b/crates/hir_def/src/macro_expansion_tests.rs
@@ -102,9 +102,11 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
let curr_kind = token.kind();
let space = match (prev_kind, curr_kind) {
_ if prev_kind.is_trivia() || curr_kind.is_trivia() => "",
+ (T!['{'], T!['}']) => "",
(T![=], _) | (_, T![=]) => " ",
(_, T!['{']) => " ",
- (T![;] | T!['}'], _) => "\n",
+ (T![;] | T!['{'] | T!['}'], _) => "\n",
+ (_, T!['}']) => "\n",
(IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ",
(IDENT, _) if curr_kind.is_keyword() => " ",
(_, IDENT) if prev_kind.is_keyword() => " ",
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs
index c57e9cd838..8851028845 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs
@@ -159,3 +159,66 @@ struct Bar;
"##]],
);
}
+
+#[test]
+fn test_match_group_pattern_with_multiple_defs() {
+ check(
+ r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( impl Bar { $ ( fn $ i {} )*} );
+}
+m! { foo, bar }
+"#,
+ expect![[r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( impl Bar { $ ( fn $ i {} )*} );
+}
+impl Bar {
+fn foo {}
+fn bar {}
+}
+"#]],
+ );
+}
+
+#[test]
+fn test_match_group_pattern_with_multiple_statement() {
+ check(
+ r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( fn baz { $ ( $ i (); )*} );
+}
+m! { foo, bar }
+"#,
+ expect![[r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( fn baz { $ ( $ i (); )*} );
+}
+fn baz {
+foo();
+bar();
+}
+"#]],
+ )
+}
+
+#[test]
+fn test_match_group_pattern_with_multiple_statement_without_semi() {
+ check(
+ r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( fn baz { $ ( $i() );*} );
+}
+m! { foo, bar }
+"#,
+ expect![[r#"
+macro_rules! m {
+ ($ ($ i:ident),*) => ( fn baz { $ ( $i() );*} );
+}
+fn baz {
+foo();
+bar()
+}
+"#]],
+ )
+}
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 7becaa6658..d329784023 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -210,48 +210,6 @@ fn test_expr_order() {
}
#[test]
-fn test_match_group_pattern_with_multiple_defs() {
- parse_macro(
- r#"
- macro_rules! foo {
- ($ ($ i:ident),*) => ( struct Bar { $ (
- fn $ i {}
- )*} );
- }
-"#,
- )
- .assert_expand_items("foo! { foo, bar }", "struct Bar {fn foo {} fn bar {}}");
-}
-
-#[test]
-fn test_match_group_pattern_with_multiple_statement() {
- parse_macro(
- r#"
- macro_rules! foo {
- ($ ($ i:ident),*) => ( fn baz { $ (
- $ i ();
- )*} );
- }
-"#,
- )
- .assert_expand_items("foo! { foo, bar }", "fn baz {foo () ; bar () ;}");
-}
-
-#[test]
-fn test_match_group_pattern_with_multiple_statement_without_semi() {
- parse_macro(
- r#"
- macro_rules! foo {
- ($ ($ i:ident),*) => ( fn baz { $ (
- $i()
- );*} );
- }
-"#,
- )
- .assert_expand_items("foo! { foo, bar }", "fn baz {foo () ;bar ()}");
-}
-
-#[test]
fn test_match_group_empty_fixed_token() {
parse_macro(
r#"