diff options
Diffstat (limited to 'crates/mbe/src/tests.rs')
-rw-r--r-- | crates/mbe/src/tests.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 0147506c7..1d9afb4fb 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs | |||
@@ -1032,6 +1032,42 @@ fn test_underscore() { | |||
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | #[test] | 1034 | #[test] |
1035 | fn test_underscore_not_greedily() { | ||
1036 | parse_macro( | ||
1037 | r#" | ||
1038 | macro_rules! q { | ||
1039 | ($($a:ident)* _) => {0}; | ||
1040 | } | ||
1041 | "#, | ||
1042 | ) | ||
1043 | // `_` overlaps with `$a:ident` but rustc matches it under the `_` token | ||
1044 | .assert_expand_items(r#"q![a b c d _]"#, r#"0"#); | ||
1045 | |||
1046 | parse_macro( | ||
1047 | r#" | ||
1048 | macro_rules! q { | ||
1049 | ($($a:expr => $b:ident)* _ => $c:expr) => {0}; | ||
1050 | } | ||
1051 | "#, | ||
1052 | ) | ||
1053 | // `_ => ou` overlaps with `$a:expr => $b:ident` but rustc matches it under `_ => $c:expr` | ||
1054 | .assert_expand_items(r#"q![a => b c => d _ => ou]"#, r#"0"#); | ||
1055 | } | ||
1056 | |||
1057 | #[test] | ||
1058 | fn test_underscore_as_type() { | ||
1059 | parse_macro( | ||
1060 | r#" | ||
1061 | macro_rules! q { | ||
1062 | ($a:ty) => {0}; | ||
1063 | } | ||
1064 | "#, | ||
1065 | ) | ||
1066 | // Underscore is a type | ||
1067 | .assert_expand_items(r#"q![_]"#, r#"0"#); | ||
1068 | } | ||
1069 | |||
1070 | #[test] | ||
1035 | fn test_vertical_bar_with_pat() { | 1071 | fn test_vertical_bar_with_pat() { |
1036 | parse_macro( | 1072 | parse_macro( |
1037 | r#" | 1073 | r#" |