move test

This commit is contained in:
Aleksey Kladov 2021-10-10 13:24:48 +03:00
parent e255e9577f
commit 5b44770102
2 changed files with 41 additions and 96 deletions

View file

@ -1427,3 +1427,44 @@ macro_rules! foo {
"#]], "#]],
); );
} }
// The following tests are based on real world situations
#[test]
fn test_vec() {
check(
r#"
macro_rules! vec {
($($item:expr),*) => {{
let mut v = Vec::new();
$( v.push($item); )*
v
}};
}
fn main() {
vec!();
vec![1u32,2];
}
"#,
expect![[r#"
macro_rules! vec {
($($item:expr),*) => {{
let mut v = Vec::new();
$( v.push($item); )*
v
}};
}
fn main() {
{
let mut v = Vec::new();
v
};
{
let mut v = Vec::new();
v.push(1u32);
v.push(2);
v
};
}
"#]],
);
}

View file

@ -98,102 +98,6 @@ fn test_attr_to_token_tree() {
); );
} }
// The following tests are based on real world situations
#[test]
fn test_vec() {
let fixture = parse_macro(
r#"
macro_rules! vec {
($($item:expr),*) => {
{
let mut v = Vec::new();
$(
v.push($item);
)*
v
}
};
}
"#,
);
fixture
.assert_expand_items(r#"vec!();"#, r#"{let mut v = Vec :: new () ; v}"#)
.assert_expand_items(
r#"vec![1u32,2];"#,
r#"{let mut v = Vec :: new () ; v . push (1u32) ; v . push (2) ; v}"#,
);
let tree = fixture.expand_expr(r#"vec![1u32,2];"#);
assert_eq_text!(
&format!("{:#?}", tree),
r#"BLOCK_EXPR@0..45
STMT_LIST@0..45
L_CURLY@0..1 "{"
LET_STMT@1..20
LET_KW@1..4 "let"
IDENT_PAT@4..8
MUT_KW@4..7 "mut"
NAME@7..8
IDENT@7..8 "v"
EQ@8..9 "="
CALL_EXPR@9..19
PATH_EXPR@9..17
PATH@9..17
PATH@9..12
PATH_SEGMENT@9..12
NAME_REF@9..12
IDENT@9..12 "Vec"
COLON2@12..14 "::"
PATH_SEGMENT@14..17
NAME_REF@14..17
IDENT@14..17 "new"
ARG_LIST@17..19
L_PAREN@17..18 "("
R_PAREN@18..19 ")"
SEMICOLON@19..20 ";"
EXPR_STMT@20..33
METHOD_CALL_EXPR@20..32
PATH_EXPR@20..21
PATH@20..21
PATH_SEGMENT@20..21
NAME_REF@20..21
IDENT@20..21 "v"
DOT@21..22 "."
NAME_REF@22..26
IDENT@22..26 "push"
ARG_LIST@26..32
L_PAREN@26..27 "("
LITERAL@27..31
INT_NUMBER@27..31 "1u32"
R_PAREN@31..32 ")"
SEMICOLON@32..33 ";"
EXPR_STMT@33..43
METHOD_CALL_EXPR@33..42
PATH_EXPR@33..34
PATH@33..34
PATH_SEGMENT@33..34
NAME_REF@33..34
IDENT@33..34 "v"
DOT@34..35 "."
NAME_REF@35..39
IDENT@35..39 "push"
ARG_LIST@39..42
L_PAREN@39..40 "("
LITERAL@40..41
INT_NUMBER@40..41 "2"
R_PAREN@41..42 ")"
SEMICOLON@42..43 ";"
PATH_EXPR@43..44
PATH@43..44
PATH_SEGMENT@43..44
NAME_REF@43..44
IDENT@43..44 "v"
R_CURLY@44..45 "}"
"#
);
}
#[test] #[test]
fn test_winapi_struct() { fn test_winapi_struct() {
// from https://github.com/retep998/winapi-rs/blob/a7ef2bca086aae76cf6c4ce4c2552988ed9798ad/src/macros.rs#L366 // from https://github.com/retep998/winapi-rs/blob/a7ef2bca086aae76cf6c4ce4c2552988ed9798ad/src/macros.rs#L366