about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-10 08:09:50 +0000
committerGitHub <noreply@github.com>2021-10-10 08:09:50 +0000
commitcbe66621c354eac042bf6e96b78ff9e8cbf0c14d (patch)
tree31265f8448271fd6bc45379fda70bc59e4b6be5e
parent4439cd8c68f351f46dfaa7e8e534479ebe4cd94d (diff)
parentc6d5c1c9463d485220d041d1617365f03df221a4 (diff)
downloadrust-cbe66621c354eac042bf6e96b78ff9e8cbf0c14d.tar.gz
rust-cbe66621c354eac042bf6e96b78ff9e8cbf0c14d.zip
Merge #10501
10501: internal: move some mbe tests r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
-rw-r--r--crates/hir_def/src/macro_expansion_tests.rs1
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe.rs163
-rw-r--r--crates/mbe/src/tests.rs23
-rw-r--r--crates/mbe/src/tests/expand.rs113
4 files changed, 165 insertions, 135 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs
index c66c75c1436..e892ab52686 100644
--- a/crates/hir_def/src/macro_expansion_tests.rs
+++ b/crates/hir_def/src/macro_expansion_tests.rs
@@ -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) => " ",
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs
index 7279ff7e33c..958f2a1c331 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs
@@ -615,3 +615,166 @@ fn bar() {}
 "#]],
     );
 }
+
+#[test]
+fn test_macro_2_0_panic_2015() {
+    check(
+        r#"
+macro panic_2015 {
+    () => (),
+    (bar) => (),
+}
+panic_2015!(bar);
+"#,
+        expect![[r#"
+macro panic_2015 {
+    () => (),
+    (bar) => (),
+}
+
+"#]],
+    );
+}
+
+#[test]
+fn test_path() {
+    check(
+        r#"
+macro_rules! m {
+    ($p:path) => { fn foo() { let a = $p; } }
+}
+
+m! { foo }
+
+m! { bar::<u8>::baz::<u8> }
+"#,
+        expect![[r#"
+macro_rules! m {
+    ($p:path) => { fn foo() { let a = $p; } }
+}
+
+fn foo() {
+    let a = foo;
+}
+
+fn foo() {
+    let a = bar::<u8>::baz::<u8> ;
+}
+"#]],
+    );
+}
+
+#[test]
+fn test_two_paths() {
+    check(
+        r#"
+macro_rules! m {
+    ($i:path, $j:path) => { fn foo() { let a = $ i; let b = $j; } }
+}
+m! { foo, bar }
+"#,
+        expect![[r#"
+macro_rules! m {
+    ($i:path, $j:path) => { fn foo() { let a = $ i; let b = $j; } }
+}
+fn foo() {
+    let a = foo;
+    let b = bar;
+}
+"#]],
+    );
+}
+
+#[test]
+fn test_path_with_path() {
+    check(
+        r#"
+macro_rules! m {
+    ($p:path) => { fn foo() { let a = $p::bar; } }
+}
+m! { foo }
+"#,
+        expect![[r#"
+macro_rules! m {
+    ($p:path) => { fn foo() { let a = $p::bar; } }
+}
+fn foo() {
+    let a = foo::bar;
+}
+"#]],
+    );
+}
+
+#[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!();
+"#]],
+    )
+}
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs
index ad5ae3a32c2..64d80baa3ed 100644
--- a/crates/mbe/src/tests.rs
+++ b/crates/mbe/src/tests.rs
@@ -80,6 +80,7 @@ macro_rules! impl_fixture {
                 test_utils::assert_eq_text!(&expected.trim(), &actual.trim());
             }
 
+            #[allow(unused)]
             fn assert_expand_items(&self, invocation: &str, expected: &str) -> &$name {
                 self.assert_expansion(ParserEntryPoint::Items, invocation, expected);
                 self
@@ -140,12 +141,6 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture {
     MacroFixture { rules }
 }
 
-pub(crate) fn parse_macro2(ra_fixture: &str) -> MacroFixture2 {
-    let definition_tt = parse_macro_def_to_tt(ra_fixture);
-    let rules = MacroDef::parse(&definition_tt).unwrap();
-    MacroFixture2 { rules }
-}
-
 pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError {
     let definition_tt = parse_macro_rules_to_tt(ra_fixture);
 
@@ -183,22 +178,6 @@ fn parse_macro_rules_to_tt(ra_fixture: &str) -> tt::Subtree {
     definition_tt
 }
 
-fn parse_macro_def_to_tt(ra_fixture: &str) -> tt::Subtree {
-    let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap();
-    let macro_definition =
-        source_file.syntax().descendants().find_map(ast::MacroDef::cast).unwrap();
-
-    let (definition_tt, _) = syntax_node_to_token_tree(macro_definition.body().unwrap().syntax());
-
-    let parsed =
-        parse_to_token_tree(&ra_fixture[macro_definition.body().unwrap().syntax().text_range()])
-            .unwrap()
-            .0;
-    assert_eq!(definition_tt, parsed);
-
-    definition_tt
-}
-
 fn debug_dump_ignore_spaces(node: &syntax::SyntaxNode) -> String {
     let mut level = 0;
     let mut buf = String::new();
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 393c2041d99..01b55335226 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -102,119 +102,6 @@ fn test_attr_to_token_tree() {
 }
 
 #[test]
-fn test_macro_2_0_panic_2015() {
-    parse_macro2(
-        r#"
-macro panic_2015 {
-    () => (
-    ),
-    (bar) => (
-    ),
-}
-"#,
-    )
-    .assert_expand_items("panic_2015!(bar);", "");
-}
-
-#[test]
-fn test_path() {
-    parse_macro(
-        r#"
-        macro_rules! foo {
-            ($ i:path) => {
-                fn foo() { let a = $ i; }
-            }
-        }
-"#,
-    )
-    .assert_expand_items("foo! { foo }", "fn foo () {let a = foo ;}")
-    .assert_expand_items(
-        "foo! { bar::<u8>::baz::<u8> }",
-        "fn foo () {let a = bar ::< u8 >:: baz ::< u8 > ;}",
-    );
-}
-
-#[test]
-fn test_two_paths() {
-    parse_macro(
-        r#"
-        macro_rules! foo {
-            ($ i:path, $ j:path) => {
-                fn foo() { let a = $ i; let b = $j; }
-            }
-        }
-"#,
-    )
-    .assert_expand_items("foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}");
-}
-
-#[test]
-fn test_path_with_path() {
-    parse_macro(
-        r#"
-        macro_rules! foo {
-            ($ i:path) => {
-                fn foo() { let a = $ i :: bar; }
-            }
-        }
-"#,
-    )
-    .assert_expand_items("foo! { foo }", "fn foo () {let a = foo :: bar ;}");
-}
-
-#[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(
         r#"