Skip to content

Commit 5102939

Browse files
committed
Split test module for metavariable expressions
1 parent 2120c91 commit 5102939

File tree

2 files changed

+92
-86
lines changed

2 files changed

+92
-86
lines changed

crates/hir-def/src/macro_expansion_tests/mbe.rs

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
mod tt_conversion;
55
mod matching;
66
mod meta_syntax;
7+
mod metavar_expr;
78
mod regression;
89

910
use expect_test::expect;
@@ -1614,92 +1615,6 @@ struct Foo;
16141615
)
16151616
}
16161617

1617-
#[test]
1618-
fn test_dollar_dollar() {
1619-
check(
1620-
r#"
1621-
macro_rules! register_struct { ($Struct:ident) => {
1622-
macro_rules! register_methods { ($$($method:ident),*) => {
1623-
macro_rules! implement_methods { ($$$$($$val:expr),*) => {
1624-
struct $Struct;
1625-
impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
1626-
}}
1627-
}}
1628-
}}
1629-
1630-
register_struct!(Foo);
1631-
register_methods!(alpha, beta);
1632-
implement_methods!(1, 2, 3);
1633-
"#,
1634-
expect![[r#"
1635-
macro_rules! register_struct { ($Struct:ident) => {
1636-
macro_rules! register_methods { ($$($method:ident),*) => {
1637-
macro_rules! implement_methods { ($$$$($$val:expr),*) => {
1638-
struct $Struct;
1639-
impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
1640-
}}
1641-
}}
1642-
}}
1643-
1644-
macro_rules !register_methods {
1645-
($($method: ident), *) = > {
1646-
macro_rules!implement_methods {
1647-
($$($val: expr), *) = > {
1648-
struct Foo;
1649-
impl Foo {
1650-
$(fn $method()-> &'static[u32] {
1651-
&[$$($$val), *]
1652-
}
1653-
)*
1654-
}
1655-
}
1656-
}
1657-
}
1658-
}
1659-
macro_rules !implement_methods {
1660-
($($val: expr), *) = > {
1661-
struct Foo;
1662-
impl Foo {
1663-
fn alpha()-> &'static[u32] {
1664-
&[$($val), *]
1665-
}
1666-
fn beta()-> &'static[u32] {
1667-
&[$($val), *]
1668-
}
1669-
}
1670-
}
1671-
}
1672-
struct Foo;
1673-
impl Foo {
1674-
fn alpha() -> &'static[u32] {
1675-
&[1, 2, 3]
1676-
}
1677-
fn beta() -> &'static[u32] {
1678-
&[1, 2, 3]
1679-
}
1680-
}
1681-
"#]],
1682-
)
1683-
}
1684-
1685-
#[test]
1686-
fn test_metavar_exprs() {
1687-
check(
1688-
r#"
1689-
macro_rules! m {
1690-
( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
1691-
}
1692-
const _: i32 = m!(a b c);
1693-
"#,
1694-
expect![[r#"
1695-
macro_rules! m {
1696-
( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
1697-
}
1698-
const _: i32 = -0--1--2;
1699-
"#]],
1700-
);
1701-
}
1702-
17031618
#[test]
17041619
fn test_punct_without_space() {
17051620
// Puncts are "glued" greedily.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//! Tests for RFC 3086 metavariable expressions.
2+
3+
use expect_test::expect;
4+
5+
use crate::macro_expansion_tests::check;
6+
7+
#[test]
8+
fn test_dollar_dollar() {
9+
check(
10+
r#"
11+
macro_rules! register_struct { ($Struct:ident) => {
12+
macro_rules! register_methods { ($$($method:ident),*) => {
13+
macro_rules! implement_methods { ($$$$($$val:expr),*) => {
14+
struct $Struct;
15+
impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
16+
}}
17+
}}
18+
}}
19+
20+
register_struct!(Foo);
21+
register_methods!(alpha, beta);
22+
implement_methods!(1, 2, 3);
23+
"#,
24+
expect![[r#"
25+
macro_rules! register_struct { ($Struct:ident) => {
26+
macro_rules! register_methods { ($$($method:ident),*) => {
27+
macro_rules! implement_methods { ($$$$($$val:expr),*) => {
28+
struct $Struct;
29+
impl $Struct { $$(fn $method() -> &'static [u32] { &[$$$$($$$$val),*] })*}
30+
}}
31+
}}
32+
}}
33+
34+
macro_rules !register_methods {
35+
($($method: ident), *) = > {
36+
macro_rules!implement_methods {
37+
($$($val: expr), *) = > {
38+
struct Foo;
39+
impl Foo {
40+
$(fn $method()-> &'static[u32] {
41+
&[$$($$val), *]
42+
}
43+
)*
44+
}
45+
}
46+
}
47+
}
48+
}
49+
macro_rules !implement_methods {
50+
($($val: expr), *) = > {
51+
struct Foo;
52+
impl Foo {
53+
fn alpha()-> &'static[u32] {
54+
&[$($val), *]
55+
}
56+
fn beta()-> &'static[u32] {
57+
&[$($val), *]
58+
}
59+
}
60+
}
61+
}
62+
struct Foo;
63+
impl Foo {
64+
fn alpha() -> &'static[u32] {
65+
&[1, 2, 3]
66+
}
67+
fn beta() -> &'static[u32] {
68+
&[1, 2, 3]
69+
}
70+
}
71+
"#]],
72+
)
73+
}
74+
75+
#[test]
76+
fn test_metavar_exprs() {
77+
check(
78+
r#"
79+
macro_rules! m {
80+
( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
81+
}
82+
const _: i32 = m!(a b c);
83+
"#,
84+
expect![[r#"
85+
macro_rules! m {
86+
( $( $t:tt )* ) => ( $( ${ignore(t)} -${index()} )-* );
87+
}
88+
const _: i32 = -0--1--2;
89+
"#]],
90+
);
91+
}

0 commit comments

Comments
 (0)