diff options
Diffstat (limited to 'crates/mbe/src/tests.rs')
-rw-r--r-- | crates/mbe/src/tests.rs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 1d9afb4fb..bd2977ebd 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs | |||
@@ -1,7 +1,11 @@ | |||
1 | use std::fmt::Write; | 1 | use std::fmt::Write; |
2 | 2 | ||
3 | use ::parser::FragmentKind; | 3 | use ::parser::FragmentKind; |
4 | use syntax::{ast, AstNode, NodeOrToken, SyntaxKind::IDENT, SyntaxNode, WalkEvent, T}; | 4 | use syntax::{ |
5 | ast, AstNode, NodeOrToken, | ||
6 | SyntaxKind::{ERROR, IDENT}, | ||
7 | SyntaxNode, WalkEvent, T, | ||
8 | }; | ||
5 | use test_utils::assert_eq_text; | 9 | use test_utils::assert_eq_text; |
6 | 10 | ||
7 | use super::*; | 11 | use super::*; |
@@ -257,7 +261,6 @@ fn test_expr_order() { | |||
257 | 261 | ||
258 | let dump = format!("{:#?}", expanded); | 262 | let dump = format!("{:#?}", expanded); |
259 | assert_eq_text!( | 263 | assert_eq_text!( |
260 | dump.trim(), | ||
261 | r#"[email protected] | 264 | r#"[email protected] |
262 | [email protected] | 265 | [email protected] |
263 | [email protected] "fn" | 266 | [email protected] "fn" |
@@ -281,6 +284,7 @@ fn test_expr_order() { | |||
281 | [email protected] "2" | 284 | [email protected] "2" |
282 | [email protected] ";" | 285 | [email protected] ";" |
283 | [email protected] "}""#, | 286 | [email protected] "}""#, |
287 | dump.trim() | ||
284 | ); | 288 | ); |
285 | } | 289 | } |
286 | 290 | ||
@@ -985,7 +989,6 @@ fn test_tt_composite2() { | |||
985 | 989 | ||
986 | let res = format!("{:#?}", &node); | 990 | let res = format!("{:#?}", &node); |
987 | assert_eq_text!( | 991 | assert_eq_text!( |
988 | res.trim(), | ||
989 | r###"[email protected] | 992 | r###"[email protected] |
990 | [email protected] | 993 | [email protected] |
991 | [email protected] | 994 | [email protected] |
@@ -999,7 +1002,8 @@ fn test_tt_composite2() { | |||
999 | [email protected] ">" | 1002 | [email protected] ">" |
1000 | [email protected] " " | 1003 | [email protected] " " |
1001 | [email protected] "#" | 1004 | [email protected] "#" |
1002 | [email protected] ")""### | 1005 | [email protected] ")""###, |
1006 | res.trim() | ||
1003 | ); | 1007 | ); |
1004 | } | 1008 | } |
1005 | 1009 | ||
@@ -1080,6 +1084,19 @@ fn test_vertical_bar_with_pat() { | |||
1080 | } | 1084 | } |
1081 | 1085 | ||
1082 | #[test] | 1086 | #[test] |
1087 | fn test_dollar_crate_lhs_is_not_meta() { | ||
1088 | parse_macro( | ||
1089 | r#" | ||
1090 | macro_rules! foo { | ||
1091 | ($crate) => {}; | ||
1092 | () => {0}; | ||
1093 | } | ||
1094 | "#, | ||
1095 | ) | ||
1096 | .assert_expand_items(r#"foo!{}"#, r#"0"#); | ||
1097 | } | ||
1098 | |||
1099 | #[test] | ||
1083 | fn test_lifetime() { | 1100 | fn test_lifetime() { |
1084 | parse_macro( | 1101 | parse_macro( |
1085 | r#" | 1102 | r#" |
@@ -1181,6 +1198,23 @@ macro_rules! foo { | |||
1181 | ); | 1198 | ); |
1182 | } | 1199 | } |
1183 | 1200 | ||
1201 | #[test] | ||
1202 | fn test_expr_after_path_colons() { | ||
1203 | assert!(parse_macro( | ||
1204 | r#" | ||
1205 | macro_rules! m { | ||
1206 | ($k:expr) => { | ||
1207 | f(K::$k); | ||
1208 | } | ||
1209 | } | ||
1210 | "#, | ||
1211 | ) | ||
1212 | .expand_statements(r#"m!(C("0"))"#) | ||
1213 | .descendants() | ||
1214 | .find(|token| token.kind() == ERROR) | ||
1215 | .is_some()); | ||
1216 | } | ||
1217 | |||
1184 | // The following tests are based on real world situations | 1218 | // The following tests are based on real world situations |
1185 | #[test] | 1219 | #[test] |
1186 | fn test_vec() { | 1220 | fn test_vec() { |
@@ -1708,7 +1742,7 @@ impl MacroFixture { | |||
1708 | fn assert_expand(&self, invocation: &str, expected: &str) { | 1742 | fn assert_expand(&self, invocation: &str, expected: &str) { |
1709 | let expansion = self.expand_tt(invocation); | 1743 | let expansion = self.expand_tt(invocation); |
1710 | let actual = format!("{:?}", expansion); | 1744 | let actual = format!("{:?}", expansion); |
1711 | test_utils::assert_eq_text!(&actual.trim(), &expected.trim()); | 1745 | test_utils::assert_eq_text!(&expected.trim(), &actual.trim()); |
1712 | } | 1746 | } |
1713 | 1747 | ||
1714 | fn assert_expand_items(&self, invocation: &str, expected: &str) -> &MacroFixture { | 1748 | fn assert_expand_items(&self, invocation: &str, expected: &str) -> &MacroFixture { |
@@ -1907,7 +1941,6 @@ fn test_no_space_after_semi_colon() { | |||
1907 | 1941 | ||
1908 | let dump = format!("{:#?}", expanded); | 1942 | let dump = format!("{:#?}", expanded); |
1909 | assert_eq_text!( | 1943 | assert_eq_text!( |
1910 | dump.trim(), | ||
1911 | r###"[email protected] | 1944 | r###"[email protected] |
1912 | [email protected] | 1945 | [email protected] |
1913 | [email protected] | 1946 | [email protected] |
@@ -1947,6 +1980,7 @@ fn test_no_space_after_semi_colon() { | |||
1947 | [email protected] | 1980 | [email protected] |
1948 | [email protected] "f" | 1981 | [email protected] "f" |
1949 | [email protected] ";""###, | 1982 | [email protected] ";""###, |
1983 | dump.trim() | ||
1950 | ); | 1984 | ); |
1951 | } | 1985 | } |
1952 | 1986 | ||
@@ -1954,7 +1988,7 @@ fn test_no_space_after_semi_colon() { | |||
1954 | #[test] | 1988 | #[test] |
1955 | fn test_rustc_issue_57597() { | 1989 | fn test_rustc_issue_57597() { |
1956 | fn test_error(fixture: &str) { | 1990 | fn test_error(fixture: &str) { |
1957 | assert_eq!(parse_macro_error(fixture), ParseError::RepetitionEmtpyTokenTree); | 1991 | assert_eq!(parse_macro_error(fixture), ParseError::RepetitionEmptyTokenTree); |
1958 | } | 1992 | } |
1959 | 1993 | ||
1960 | test_error("macro_rules! foo { ($($($i:ident)?)+) => {}; }"); | 1994 | test_error("macro_rules! foo { ($($($i:ident)?)+) => {}; }"); |