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 | 48 |
1 files changed, 48 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 new file mode 100644 index 0000000000..cc6551f8aa --- /dev/null +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -0,0 +1,48 @@ +//! Tests specific to declarative macros, aka macros by example. This covers +//! both stable `macro_rules!` macros as well as unstable `macro` macros. + +mod tt_conversion; +mod matching; +mod meta_syntax; + +use expect_test::expect; + +use crate::macro_expansion_tests::check; + +#[test] +fn expansion_does_not_parse_as_expression() { + check( + r#" +macro_rules! stmts { + () => { let _ = 0; } +} + +fn f() { let _ = stmts!(); } +"#, + expect![[r#" +macro_rules! stmts { + () => { let _ = 0; } +} + +fn f() { let _ = /* error: could not convert tokens */; } +"#]], + ) +} + +#[test] +fn wrong_nesting_level() { + check( + r#" +macro_rules! m { + ($($i:ident);*) => ($i) +} +m!{a} +"#, + expect![[r#" +macro_rules! m { + ($($i:ident);*) => ($i) +} +/* error: expected simple binding, found nested binding `i` */ +"#]], + ); +} |