Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/macro_expansion_tests/mbe.rs')
| -rw-r--r-- | crates/hir_def/src/macro_expansion_tests/mbe.rs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index cc6551f8aa..c57e9cd838 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -46,3 +46,116 @@ macro_rules! m { "#]], ); } + +#[test] +fn match_by_first_token_literally() { + check( + r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + (= $ i:ident) => ( fn $ i() {} ); + (+ $ i:ident) => ( struct $ i; ) +} +m! { foo } +m! { = bar } +m! { + Baz } +"#, + expect![[r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + (= $ i:ident) => ( fn $ i() {} ); + (+ $ i:ident) => ( struct $ i; ) +} +mod foo {} +fn bar() {} +struct Baz; +"#]], + ); +} + +#[test] +fn match_by_last_token_literally() { + check( + r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + ($ i:ident =) => ( fn $ i() {} ); + ($ i:ident +) => ( struct $ i; ) +} +m! { foo } +m! { bar = } +m! { Baz + } +"#, + expect![[r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + ($ i:ident =) => ( fn $ i() {} ); + ($ i:ident +) => ( struct $ i; ) +} +mod foo {} +fn bar() {} +struct Baz; +"#]], + ); +} + +#[test] +fn match_by_ident() { + check( + r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + (spam $ i:ident) => ( fn $ i() {} ); + (eggs $ i:ident) => ( struct $ i; ) +} +m! { foo } +m! { spam bar } +m! { eggs Baz } +"#, + expect![[r#" +macro_rules! m { + ($ i:ident) => ( mod $ i {} ); + (spam $ i:ident) => ( fn $ i() {} ); + (eggs $ i:ident) => ( struct $ i; ) +} +mod foo {} +fn bar() {} +struct Baz; +"#]], + ); +} + +#[test] +fn match_by_separator_token() { + check( + r#" +macro_rules! m { + ($ ($ i:ident),*) => ($ ( mod $ i {} )*); + ($ ($ i:ident)#*) => ($ ( fn $ i() {} )*); + ($ i:ident ,# $ j:ident) => ( struct $ i; struct $ j; ) +} + +m! { foo, bar } + +m! { foo# bar } + +m! { Foo,# Bar } +"#, + expect![[r##" +macro_rules! m { + ($ ($ i:ident),*) => ($ ( mod $ i {} )*); + ($ ($ i:ident)#*) => ($ ( fn $ i() {} )*); + ($ i:ident ,# $ j:ident) => ( struct $ i; struct $ j; ) +} + +mod foo {} +mod bar {} + +fn foo() {} +fn bar() {} + +struct Foo; +struct Bar; +"##]], + ); +} |