From 9c819eaa9a7f6dc394571c95a8b4ad8cec440d5b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 10 Oct 2021 11:15:42 +0300 Subject: [PATCH] move tests --- .../hir_def/src/macro_expansion_tests/mbe.rs | 72 +++++++++++++++++-- crates/mbe/src/tests/expand.rs | 41 ----------- 2 files changed, 65 insertions(+), 48 deletions(-) diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index 0d3d86c8ad..1cabce70fe 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -783,13 +783,13 @@ x!(); fn test_ty() { check( r#" -macro_rules! foo { +macro_rules! m { ($t:ty) => ( fn bar() -> $t {} ) } -foo! { Baz } +m! { Baz } "#, expect![[r#" -macro_rules! foo { +macro_rules! m { ($t:ty) => ( fn bar() -> $t {} ) } fn bar() -> Baz {} @@ -801,16 +801,16 @@ fn bar() -> Baz {} fn test_ty_with_complex_type() { check( r#" -macro_rules! foo { +macro_rules! m { ($t:ty) => ( fn bar() -> $ t {} ) } -foo! { &'a Baz } +m! { &'a Baz } -foo! { extern "Rust" fn() -> Ret } +m! { extern "Rust" fn() -> Ret } "#, expect![[r#" -macro_rules! foo { +macro_rules! m { ($t:ty) => ( fn bar() -> $ t {} ) } @@ -820,3 +820,61 @@ fn bar() -> extern"Rust"fn() -> Ret {} "#]], ); } + +#[test] +fn test_pat_() { + check( + r#" +macro_rules! m { + ($p:pat) => { fn foo() { let $p; } } +} +m! { (a, b) } +"#, + expect![[r#" +macro_rules! m { + ($p:pat) => { fn foo() { let $p; } } +} +fn foo() { + let(a,b); +} +"#]], + ); +} + +#[test] +fn test_stmt() { + check( + r#" +macro_rules! m { + ($s:stmt) => ( fn bar() { $s; } ) +} +m! { 2 } +m! { let a = 0 } +"#, + expect![[r#" +macro_rules! m { + ($s:stmt) => ( fn bar() { $s; } ) +} +fn bar() { + 2; +} +fn bar() { + let a = 0; +} +"#]], + ) +} + +#[test] +fn test_single_item() { + check( + r#" +macro_rules! m { ($i:item) => ( $i ) } +m! { mod c {} } +"#, + expect![[r#" +macro_rules! m { ($i:item) => ( $i ) } +mod c {} +"#]], + ) +} diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 8528318152..2cb0fc4aad 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -101,47 +101,6 @@ fn test_attr_to_token_tree() { ); } -#[test] -fn test_pat_() { - parse_macro( - r#" - macro_rules! foo { - ($ i:pat) => { fn foo() { let $ i; } } - } -"#, - ) - .assert_expand_items("foo! { (a, b) }", "fn foo () {let (a , b) ;}"); -} - -#[test] -fn test_stmt() { - parse_macro( - r#" - macro_rules! foo { - ($ i:stmt) => ( - fn bar() { $ i; } - ) - } -"#, - ) - .assert_expand_items("foo! { 2 }", "fn bar () {2 ;}") - .assert_expand_items("foo! { let a = 0 }", "fn bar () {let a = 0 ;}"); -} - -#[test] -fn test_single_item() { - parse_macro( - r#" - macro_rules! foo { - ($ i:item) => ( - $ i - ) - } -"#, - ) - .assert_expand_items("foo! {mod c {}}", "mod c {}"); -} - #[test] fn test_all_items() { parse_macro(