mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
move some tests
This commit is contained in:
parent
a3470a8114
commit
c88cda04db
@ -1043,3 +1043,79 @@ macro_rules! m {
|
|||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($tt:tt) => { fn foo() $tt } }
|
||||||
|
m! { { 1; } }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m { ($tt:tt) => { fn foo() $tt } }
|
||||||
|
fn foo() {
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_group() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($($tt:tt)*) => { $($tt)* } }
|
||||||
|
m! { fn foo() {} }"
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m { ($($tt:tt)*) => { $($tt)* } }
|
||||||
|
fn foo() {}"
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_composite() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($tt:tt) => { ok!(); } }
|
||||||
|
m! { => }
|
||||||
|
m! { = > }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m { ($tt:tt) => { ok!(); } }
|
||||||
|
ok!();
|
||||||
|
/* error: leftover tokens */ok!();
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_composite2() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($($tt:tt)*) => { abs!(=> $($tt)*); } }
|
||||||
|
m! {#}
|
||||||
|
"#,
|
||||||
|
expect![[r##"
|
||||||
|
macro_rules! m { ($($tt:tt)*) => { abs!(=> $($tt)*); } }
|
||||||
|
abs!( = > #);
|
||||||
|
"##]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_with_composite_without_space() {
|
||||||
|
// Test macro input without any spaces
|
||||||
|
// See https://github.com/rust-analyzer/rust-analyzer/issues/6692
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($ op:tt, $j:path) => ( ok!(); ) }
|
||||||
|
m!(==,Foo::Bool)
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m { ($ op:tt, $j:path) => ( ok!(); ) }
|
||||||
|
ok!();
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -101,89 +101,6 @@ fn test_attr_to_token_tree() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tt_block() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ i:tt) => { fn foo() $ i }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items(r#"foo! { { 1; } }"#, r#"fn foo () {1 ;}"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tt_group() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($($ i:tt)*) => { $($ i)* }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items(r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tt_composite() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($i:tt) => { 0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items(r#"foo! { => }"#, r#"0"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tt_composite2() {
|
|
||||||
let node = parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($($tt:tt)*) => { abs!(=> $($tt)*) }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.expand_items(r#"foo!{#}"#);
|
|
||||||
|
|
||||||
let res = format!("{:#?}", &node);
|
|
||||||
assert_eq_text!(
|
|
||||||
r###"MACRO_ITEMS@0..10
|
|
||||||
MACRO_CALL@0..10
|
|
||||||
PATH@0..3
|
|
||||||
PATH_SEGMENT@0..3
|
|
||||||
NAME_REF@0..3
|
|
||||||
IDENT@0..3 "abs"
|
|
||||||
BANG@3..4 "!"
|
|
||||||
TOKEN_TREE@4..10
|
|
||||||
L_PAREN@4..5 "("
|
|
||||||
EQ@5..6 "="
|
|
||||||
R_ANGLE@6..7 ">"
|
|
||||||
WHITESPACE@7..8 " "
|
|
||||||
POUND@8..9 "#"
|
|
||||||
R_PAREN@9..10 ")""###,
|
|
||||||
res.trim()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tt_with_composite_without_space() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ op:tt, $j:path) => (
|
|
||||||
0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
// Test macro input without any spaces
|
|
||||||
// See https://github.com/rust-analyzer/rust-analyzer/issues/6692
|
|
||||||
.assert_expand_items("foo!(==,Foo::Bool)", "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_underscore() {
|
fn test_underscore() {
|
||||||
parse_macro(
|
parse_macro(
|
||||||
|
Loading…
Reference in New Issue
Block a user