move tests

This commit is contained in:
Aleksey Kladov 2021-10-10 14:58:25 +03:00
parent 42fd71e6c8
commit dce41e5a03
4 changed files with 82 additions and 88 deletions

View File

@ -77,3 +77,64 @@ macro_rules! f3 { ($i:_) => () }
"#]],
)
}
#[test]
fn test_rustc_issue_57597() {
// <https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-57597.rs>
check(
r#"
macro_rules! m0 { ($($($i:ident)?)+) => {}; }
macro_rules! m1 { ($($($i:ident)?)*) => {}; }
macro_rules! m2 { ($($($i:ident)?)?) => {}; }
macro_rules! m3 { ($($($($i:ident)?)?)?) => {}; }
macro_rules! m4 { ($($($($i:ident)*)?)?) => {}; }
macro_rules! m5 { ($($($($i:ident)?)*)?) => {}; }
macro_rules! m6 { ($($($($i:ident)?)?)*) => {}; }
macro_rules! m7 { ($($($($i:ident)*)*)?) => {}; }
macro_rules! m8 { ($($($($i:ident)?)*)*) => {}; }
macro_rules! m9 { ($($($($i:ident)?)*)+) => {}; }
macro_rules! mA { ($($($($i:ident)+)?)*) => {}; }
macro_rules! mB { ($($($($i:ident)+)*)?) => {}; }
m0!();
m1!();
m2!();
m3!();
m4!();
m5!();
m6!();
m7!();
m8!();
m9!();
mA!();
mB!();
"#,
expect![[r#"
macro_rules! m0 { ($($($i:ident)?)+) => {}; }
macro_rules! m1 { ($($($i:ident)?)*) => {}; }
macro_rules! m2 { ($($($i:ident)?)?) => {}; }
macro_rules! m3 { ($($($($i:ident)?)?)?) => {}; }
macro_rules! m4 { ($($($($i:ident)*)?)?) => {}; }
macro_rules! m5 { ($($($($i:ident)?)*)?) => {}; }
macro_rules! m6 { ($($($($i:ident)?)?)*) => {}; }
macro_rules! m7 { ($($($($i:ident)*)*)?) => {}; }
macro_rules! m8 { ($($($($i:ident)?)*)*) => {}; }
macro_rules! m9 { ($($($($i:ident)?)*)+) => {}; }
macro_rules! mA { ($($($($i:ident)+)?)*) => {}; }
macro_rules! mB { ($($($($i:ident)+)*)?) => {}; }
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
/* error: invalid macro definition: empty token tree in repetition */
"#]],
);
}

View File

@ -879,3 +879,24 @@ pub fn new() {
"#]],
);
}
#[test]
fn test_no_space_after_semi_colon() {
check(
r#"
macro_rules! with_std {
($($i:item)*) => ($(#[cfg(feature = "std")]$i)*)
}
with_std! {mod m;mod f;}
"#,
expect![[r##"
macro_rules! with_std {
($($i:item)*) => ($(#[cfg(feature = "std")]$i)*)
}
#[cfg(feature = "std")] mod m;
#[cfg(feature = "std")] mod f;
"##]],
)
}

View File

@ -141,15 +141,6 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture {
MacroFixture { rules }
}
pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError {
let definition_tt = parse_macro_rules_to_tt(ra_fixture);
match MacroRules::parse(&definition_tt) {
Ok(_) => panic!("Expect error"),
Err(err) => err,
}
}
pub(crate) fn parse_to_token_tree_by_syntax(ra_fixture: &str) -> tt::Subtree {
let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap();
let tt = syntax_node_to_token_tree(source_file.syntax()).0;

View File

@ -1,6 +1,5 @@
use ::parser::ParserEntryPoint;
use syntax::{SyntaxKind::IDENT, T};
use test_utils::assert_eq_text;
use super::*;
@ -98,84 +97,6 @@ fn test_attr_to_token_tree() {
);
}
#[test]
fn test_no_space_after_semi_colon() {
let expanded = parse_macro(
r#"
macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) }
"#,
)
.expand_items(r#"with_std! {mod m;mod f;}"#);
let dump = format!("{:#?}", expanded);
assert_eq_text!(
r###"MACRO_ITEMS@0..52
MODULE@0..26
ATTR@0..21
POUND@0..1 "#"
L_BRACK@1..2 "["
META@2..20
PATH@2..5
PATH_SEGMENT@2..5
NAME_REF@2..5
IDENT@2..5 "cfg"
TOKEN_TREE@5..20
L_PAREN@5..6 "("
IDENT@6..13 "feature"
EQ@13..14 "="
STRING@14..19 "\"std\""
R_PAREN@19..20 ")"
R_BRACK@20..21 "]"
MOD_KW@21..24 "mod"
NAME@24..25
IDENT@24..25 "m"
SEMICOLON@25..26 ";"
MODULE@26..52
ATTR@26..47
POUND@26..27 "#"
L_BRACK@27..28 "["
META@28..46
PATH@28..31
PATH_SEGMENT@28..31
NAME_REF@28..31
IDENT@28..31 "cfg"
TOKEN_TREE@31..46
L_PAREN@31..32 "("
IDENT@32..39 "feature"
EQ@39..40 "="
STRING@40..45 "\"std\""
R_PAREN@45..46 ")"
R_BRACK@46..47 "]"
MOD_KW@47..50 "mod"
NAME@50..51
IDENT@50..51 "f"
SEMICOLON@51..52 ";""###,
dump.trim()
);
}
// https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-57597.rs
#[test]
fn test_rustc_issue_57597() {
fn test_error(fixture: &str) {
assert_eq!(parse_macro_error(fixture), ParseError::RepetitionEmptyTokenTree);
}
test_error("macro_rules! foo { ($($($i:ident)?)+) => {}; }");
test_error("macro_rules! foo { ($($($i:ident)?)*) => {}; }");
test_error("macro_rules! foo { ($($($i:ident)?)?) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)?)?)?) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)*)?)?) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)?)*)?) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)?)?)*) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)*)*)?) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)?)*)*) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)?)*)+) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)+)?)*) => {}; }");
test_error("macro_rules! foo { ($($($($i:ident)+)*)?) => {}; }");
}
#[test]
fn test_expand_bad_literal() {
parse_macro(