diff options
Diffstat (limited to 'crates/ra_mbe/src/tests.rs')
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 7ceec7752..0d924ce58 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -1657,7 +1657,7 @@ impl MacroFixture { | |||
1657 | } | 1657 | } |
1658 | } | 1658 | } |
1659 | 1659 | ||
1660 | pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture { | 1660 | fn parse_macro_to_tt(ra_fixture: &str) -> tt::Subtree { |
1661 | let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap(); | 1661 | let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap(); |
1662 | let macro_definition = | 1662 | let macro_definition = |
1663 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); | 1663 | source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); |
@@ -1671,10 +1671,24 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture { | |||
1671 | .0; | 1671 | .0; |
1672 | assert_eq!(definition_tt, parsed); | 1672 | assert_eq!(definition_tt, parsed); |
1673 | 1673 | ||
1674 | definition_tt | ||
1675 | } | ||
1676 | |||
1677 | pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture { | ||
1678 | let definition_tt = parse_macro_to_tt(ra_fixture); | ||
1674 | let rules = MacroRules::parse(&definition_tt).unwrap(); | 1679 | let rules = MacroRules::parse(&definition_tt).unwrap(); |
1675 | MacroFixture { rules } | 1680 | MacroFixture { rules } |
1676 | } | 1681 | } |
1677 | 1682 | ||
1683 | pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError { | ||
1684 | let definition_tt = parse_macro_to_tt(ra_fixture); | ||
1685 | |||
1686 | match MacroRules::parse(&definition_tt) { | ||
1687 | Ok(_) => panic!("Expect error"), | ||
1688 | Err(err) => err, | ||
1689 | } | ||
1690 | } | ||
1691 | |||
1678 | pub(crate) fn parse_to_token_tree_by_syntax(ra_fixture: &str) -> tt::Subtree { | 1692 | pub(crate) fn parse_to_token_tree_by_syntax(ra_fixture: &str) -> tt::Subtree { |
1679 | let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap(); | 1693 | let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap(); |
1680 | let tt = syntax_node_to_token_tree(source_file.syntax()).unwrap().0; | 1694 | let tt = syntax_node_to_token_tree(source_file.syntax()).unwrap().0; |
@@ -1840,6 +1854,27 @@ fn test_no_space_after_semi_colon() { | |||
1840 | ); | 1854 | ); |
1841 | } | 1855 | } |
1842 | 1856 | ||
1857 | // https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-57597.rs | ||
1858 | #[test] | ||
1859 | fn test_rustc_issue_57597() { | ||
1860 | fn test_error(fixture: &str) { | ||
1861 | assert_eq!(parse_macro_error(fixture), ParseError::RepetitionEmtpyTokenTree); | ||
1862 | } | ||
1863 | |||
1864 | test_error("macro_rules! foo { ($($($i:ident)?)+) => {}; }"); | ||
1865 | test_error("macro_rules! foo { ($($($i:ident)?)*) => {}; }"); | ||
1866 | test_error("macro_rules! foo { ($($($i:ident)?)?) => {}; }"); | ||
1867 | test_error("macro_rules! foo { ($($($($i:ident)?)?)?) => {}; }"); | ||
1868 | test_error("macro_rules! foo { ($($($($i:ident)*)?)?) => {}; }"); | ||
1869 | test_error("macro_rules! foo { ($($($($i:ident)?)*)?) => {}; }"); | ||
1870 | test_error("macro_rules! foo { ($($($($i:ident)?)?)*) => {}; }"); | ||
1871 | test_error("macro_rules! foo { ($($($($i:ident)*)*)?) => {}; }"); | ||
1872 | test_error("macro_rules! foo { ($($($($i:ident)?)*)*) => {}; }"); | ||
1873 | test_error("macro_rules! foo { ($($($($i:ident)?)*)+) => {}; }"); | ||
1874 | test_error("macro_rules! foo { ($($($($i:ident)+)?)*) => {}; }"); | ||
1875 | test_error("macro_rules! foo { ($($($($i:ident)+)*)?) => {}; }"); | ||
1876 | } | ||
1877 | |||
1843 | #[test] | 1878 | #[test] |
1844 | fn test_expand_bad_literal() { | 1879 | fn test_expand_bad_literal() { |
1845 | parse_macro( | 1880 | parse_macro( |