move tests

This commit is contained in:
Aleksey Kladov 2021-10-10 11:15:42 +03:00
parent 1c15f47e00
commit 9c819eaa9a
2 changed files with 65 additions and 48 deletions

View file

@ -783,13 +783,13 @@ x!();
fn test_ty() { fn test_ty() {
check( check(
r#" r#"
macro_rules! foo { macro_rules! m {
($t:ty) => ( fn bar() -> $t {} ) ($t:ty) => ( fn bar() -> $t {} )
} }
foo! { Baz<u8> } m! { Baz<u8> }
"#, "#,
expect![[r#" expect![[r#"
macro_rules! foo { macro_rules! m {
($t:ty) => ( fn bar() -> $t {} ) ($t:ty) => ( fn bar() -> $t {} )
} }
fn bar() -> Baz<u8> {} fn bar() -> Baz<u8> {}
@ -801,16 +801,16 @@ fn bar() -> Baz<u8> {}
fn test_ty_with_complex_type() { fn test_ty_with_complex_type() {
check( check(
r#" r#"
macro_rules! foo { macro_rules! m {
($t:ty) => ( fn bar() -> $ t {} ) ($t:ty) => ( fn bar() -> $ t {} )
} }
foo! { &'a Baz<u8> } m! { &'a Baz<u8> }
foo! { extern "Rust" fn() -> Ret } m! { extern "Rust" fn() -> Ret }
"#, "#,
expect![[r#" expect![[r#"
macro_rules! foo { macro_rules! m {
($t:ty) => ( fn bar() -> $ t {} ) ($t:ty) => ( fn bar() -> $ t {} )
} }
@ -820,3 +820,61 @@ fn bar() -> extern"Rust"fn() -> Ret {}
"#]], "#]],
); );
} }
#[test]
fn test_pat_() {
check(
r#"
macro_rules! m {
($p:pat) => { fn foo() { let $p; } }
}
m! { (a, b) }
"#,
expect![[r#"
macro_rules! m {
($p:pat) => { fn foo() { let $p; } }
}
fn foo() {
let(a,b);
}
"#]],
);
}
#[test]
fn test_stmt() {
check(
r#"
macro_rules! m {
($s:stmt) => ( fn bar() { $s; } )
}
m! { 2 }
m! { let a = 0 }
"#,
expect![[r#"
macro_rules! m {
($s:stmt) => ( fn bar() { $s; } )
}
fn bar() {
2;
}
fn bar() {
let a = 0;
}
"#]],
)
}
#[test]
fn test_single_item() {
check(
r#"
macro_rules! m { ($i:item) => ( $i ) }
m! { mod c {} }
"#,
expect![[r#"
macro_rules! m { ($i:item) => ( $i ) }
mod c {}
"#]],
)
}

View file

@ -101,47 +101,6 @@ fn test_attr_to_token_tree() {
); );
} }
#[test]
fn test_pat_() {
parse_macro(
r#"
macro_rules! foo {
($ i:pat) => { fn foo() { let $ i; } }
}
"#,
)
.assert_expand_items("foo! { (a, b) }", "fn foo () {let (a , b) ;}");
}
#[test]
fn test_stmt() {
parse_macro(
r#"
macro_rules! foo {
($ i:stmt) => (
fn bar() { $ i; }
)
}
"#,
)
.assert_expand_items("foo! { 2 }", "fn bar () {2 ;}")
.assert_expand_items("foo! { let a = 0 }", "fn bar () {let a = 0 ;}");
}
#[test]
fn test_single_item() {
parse_macro(
r#"
macro_rules! foo {
($ i:item) => (
$ i
)
}
"#,
)
.assert_expand_items("foo! {mod c {}}", "mod c {}");
}
#[test] #[test]
fn test_all_items() { fn test_all_items() {
parse_macro( parse_macro(