Unnamed repository; edit this file 'description' to name the repository.
Split test module for metavariable expressions
Ryo Yoshida 2023-05-28
parent f6e3a87 · commit 9ebaa85
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe.rs87
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe/metavar_expr.rs91
2 files changed, 92 insertions, 86 deletions
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe.rs b/crates/hir-def/src/macro_expansion_tests/mbe.rs
index c056c077a5..553ffe3d0b 100644
--- a/crates/hir-def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mbe.rs
@@ -4,6 +4,7 @@
mod tt_conversion;
mod matching;
mod meta_syntax;
+mod metavar_expr;
mod regression;
use expect_test::expect;
@@ -1615,92 +1616,6 @@ struct Foo;
}
#[test]
-fn test_dollar_dollar() {
- check(
- r#"
-macro_rules! register_struct { ($Struct:ident) => {
- macro_rules! register_methods { ($$($method:ident),*) => {
- macro_rules! implement_methods { ($$$$($$val:expr),*) => {
- struct $Struct;
- impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
- }}
- }}
-}}
-
-register_struct!(Foo);
-register_methods!(alpha, beta);
-implement_methods!(1, 2, 3);
-"#,
- expect![[r#"
-macro_rules! register_struct { ($Struct:ident) => {
- macro_rules! register_methods { ($$($method:ident),*) => {
- macro_rules! implement_methods { ($$$$($$val:expr),*) => {
- struct $Struct;
- impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
- }}
- }}
-}}
-
-macro_rules !register_methods {
- ($($method: ident), *) = > {
- macro_rules!implement_methods {
- ($$($val: expr), *) = > {
- struct Foo;
- impl Foo {
- $(fn $method()-> &'static[u32] {
- &[$$($$val), *]
- }
- )*
- }
- }
- }
- }
-}
-macro_rules !implement_methods {
- ($($val: expr), *) = > {
- struct Foo;
- impl Foo {
- fn alpha()-> &'static[u32] {
- &[$($val), *]
- }
- fn beta()-> &'static[u32] {
- &[$($val), *]
- }
- }
- }
-}
-struct Foo;
-impl Foo {
- fn alpha() -> &'static[u32] {
- &[1, 2, 3]
- }
- fn beta() -> &'static[u32] {
- &[1, 2, 3]
- }
-}
-"#]],
- )
-}
-
-#[test]
-fn test_metavar_exprs() {
- check(
- r#"
-macro_rules! m {
- ( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
-}
-const _: i32 = m!(a b c);
- "#,
- expect![[r#"
-macro_rules! m {
- ( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
-}
-const _: i32 = -0--1--2;
- "#]],
- );
-}
-
-#[test]
fn test_punct_without_space() {
// Puncts are "glued" greedily.
check(
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe/metavar_expr.rs b/crates/hir-def/src/macro_expansion_tests/mbe/metavar_expr.rs
new file mode 100644
index 0000000000..ae138529ea
--- /dev/null
+++ b/crates/hir-def/src/macro_expansion_tests/mbe/metavar_expr.rs
@@ -0,0 +1,91 @@
+//! Tests for RFC 3086 metavariable expressions.
+
+use expect_test::expect;
+
+use crate::macro_expansion_tests::check;
+
+#[test]
+fn test_dollar_dollar() {
+ check(
+ r#"
+macro_rules! register_struct { ($Struct:ident) => {
+ macro_rules! register_methods { ($$($method:ident),*) => {
+ macro_rules! implement_methods { ($$$$($$val:expr),*) => {
+ struct $Struct;
+ impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
+ }}
+ }}
+}}
+
+register_struct!(Foo);
+register_methods!(alpha, beta);
+implement_methods!(1, 2, 3);
+"#,
+ expect![[r#"
+macro_rules! register_struct { ($Struct:ident) => {
+ macro_rules! register_methods { ($$($method:ident),*) => {
+ macro_rules! implement_methods { ($$$$($$val:expr),*) => {
+ struct $Struct;
+ impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
+ }}
+ }}
+}}
+
+macro_rules !register_methods {
+ ($($method: ident), *) = > {
+ macro_rules!implement_methods {
+ ($$($val: expr), *) = > {
+ struct Foo;
+ impl Foo {
+ $(fn $method()-> &'static[u32] {
+ &[$$($$val), *]
+ }
+ )*
+ }
+ }
+ }
+ }
+}
+macro_rules !implement_methods {
+ ($($val: expr), *) = > {
+ struct Foo;
+ impl Foo {
+ fn alpha()-> &'static[u32] {
+ &[$($val), *]
+ }
+ fn beta()-> &'static[u32] {
+ &[$($val), *]
+ }
+ }
+ }
+}
+struct Foo;
+impl Foo {
+ fn alpha() -> &'static[u32] {
+ &[1, 2, 3]
+ }
+ fn beta() -> &'static[u32] {
+ &[1, 2, 3]
+ }
+}
+"#]],
+ )
+}
+
+#[test]
+fn test_metavar_exprs() {
+ check(
+ r#"
+macro_rules! m {
+ ( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
+}
+const _: i32 = m!(a b c);
+ "#,
+ expect![[r#"
+macro_rules! m {
+ ( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
+}
+const _: i32 = -0--1--2;
+ "#]],
+ );
+}