mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Merge #10501
10501: internal: move some mbe tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
cbe66621c3
4 changed files with 165 additions and 135 deletions
|
@ -121,6 +121,7 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
|
||||||
(T![;] | T!['{'] | T!['}'], _) => "\n",
|
(T![;] | T!['{'] | T!['}'], _) => "\n",
|
||||||
(_, T!['}']) => "\n",
|
(_, T!['}']) => "\n",
|
||||||
(IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ",
|
(IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ",
|
||||||
|
_ if prev_kind.is_keyword() && curr_kind.is_keyword() => " ",
|
||||||
(IDENT, _) if curr_kind.is_keyword() => " ",
|
(IDENT, _) if curr_kind.is_keyword() => " ",
|
||||||
(_, IDENT) if prev_kind.is_keyword() => " ",
|
(_, IDENT) if prev_kind.is_keyword() => " ",
|
||||||
(T![>], IDENT) => " ",
|
(T![>], IDENT) => " ",
|
||||||
|
|
|
@ -615,3 +615,166 @@ fn bar() {}
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_macro_2_0_panic_2015() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro panic_2015 {
|
||||||
|
() => (),
|
||||||
|
(bar) => (),
|
||||||
|
}
|
||||||
|
panic_2015!(bar);
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro panic_2015 {
|
||||||
|
() => (),
|
||||||
|
(bar) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($p:path) => { fn foo() { let a = $p; } }
|
||||||
|
}
|
||||||
|
|
||||||
|
m! { foo }
|
||||||
|
|
||||||
|
m! { bar::<u8>::baz::<u8> }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($p:path) => { fn foo() { let a = $p; } }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let a = foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let a = bar::<u8>::baz::<u8> ;
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_two_paths() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($i:path, $j:path) => { fn foo() { let a = $ i; let b = $j; } }
|
||||||
|
}
|
||||||
|
m! { foo, bar }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($i:path, $j:path) => { fn foo() { let a = $ i; let b = $j; } }
|
||||||
|
}
|
||||||
|
fn foo() {
|
||||||
|
let a = foo;
|
||||||
|
let b = bar;
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_with_path() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($p:path) => { fn foo() { let a = $p::bar; } }
|
||||||
|
}
|
||||||
|
m! { foo }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($p:path) => { fn foo() { let a = $p::bar; } }
|
||||||
|
}
|
||||||
|
fn foo() {
|
||||||
|
let a = foo::bar;
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_expr() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($e:expr) => { fn bar() { $e; } }
|
||||||
|
}
|
||||||
|
|
||||||
|
m! { 2 + 2 * baz(3).quux() }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($e:expr) => { fn bar() { $e; } }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar() {
|
||||||
|
2+2*baz(3).quux();
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_last_expr() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! vec {
|
||||||
|
($($item:expr),*) => {{
|
||||||
|
let mut v = Vec::new();
|
||||||
|
$( v.push($item); )*
|
||||||
|
v
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
vec![1,2,3];
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! vec {
|
||||||
|
($($item:expr),*) => {{
|
||||||
|
let mut v = Vec::new();
|
||||||
|
$( v.push($item); )*
|
||||||
|
v
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
{
|
||||||
|
let mut v = Vec::new();
|
||||||
|
v.push(1);
|
||||||
|
v.push(2);
|
||||||
|
v.push(3);
|
||||||
|
v
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_expr_with_attr() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
macro_rules! m { ($a:expr) => { x!(); } }
|
||||||
|
m!(#[allow(a)]());
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
macro_rules! m { ($a:expr) => { x!(); } }
|
||||||
|
x!();
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ macro_rules! impl_fixture {
|
||||||
test_utils::assert_eq_text!(&expected.trim(), &actual.trim());
|
test_utils::assert_eq_text!(&expected.trim(), &actual.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
fn assert_expand_items(&self, invocation: &str, expected: &str) -> &$name {
|
fn assert_expand_items(&self, invocation: &str, expected: &str) -> &$name {
|
||||||
self.assert_expansion(ParserEntryPoint::Items, invocation, expected);
|
self.assert_expansion(ParserEntryPoint::Items, invocation, expected);
|
||||||
self
|
self
|
||||||
|
@ -140,12 +141,6 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture {
|
||||||
MacroFixture { rules }
|
MacroFixture { rules }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_macro2(ra_fixture: &str) -> MacroFixture2 {
|
|
||||||
let definition_tt = parse_macro_def_to_tt(ra_fixture);
|
|
||||||
let rules = MacroDef::parse(&definition_tt).unwrap();
|
|
||||||
MacroFixture2 { rules }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError {
|
pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError {
|
||||||
let definition_tt = parse_macro_rules_to_tt(ra_fixture);
|
let definition_tt = parse_macro_rules_to_tt(ra_fixture);
|
||||||
|
|
||||||
|
@ -183,22 +178,6 @@ fn parse_macro_rules_to_tt(ra_fixture: &str) -> tt::Subtree {
|
||||||
definition_tt
|
definition_tt
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_macro_def_to_tt(ra_fixture: &str) -> tt::Subtree {
|
|
||||||
let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap();
|
|
||||||
let macro_definition =
|
|
||||||
source_file.syntax().descendants().find_map(ast::MacroDef::cast).unwrap();
|
|
||||||
|
|
||||||
let (definition_tt, _) = syntax_node_to_token_tree(macro_definition.body().unwrap().syntax());
|
|
||||||
|
|
||||||
let parsed =
|
|
||||||
parse_to_token_tree(&ra_fixture[macro_definition.body().unwrap().syntax().text_range()])
|
|
||||||
.unwrap()
|
|
||||||
.0;
|
|
||||||
assert_eq!(definition_tt, parsed);
|
|
||||||
|
|
||||||
definition_tt
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_dump_ignore_spaces(node: &syntax::SyntaxNode) -> String {
|
fn debug_dump_ignore_spaces(node: &syntax::SyntaxNode) -> String {
|
||||||
let mut level = 0;
|
let mut level = 0;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
|
@ -101,119 +101,6 @@ fn test_attr_to_token_tree() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_macro_2_0_panic_2015() {
|
|
||||||
parse_macro2(
|
|
||||||
r#"
|
|
||||||
macro panic_2015 {
|
|
||||||
() => (
|
|
||||||
),
|
|
||||||
(bar) => (
|
|
||||||
),
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items("panic_2015!(bar);", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_path() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ i:path) => {
|
|
||||||
fn foo() { let a = $ i; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items("foo! { foo }", "fn foo () {let a = foo ;}")
|
|
||||||
.assert_expand_items(
|
|
||||||
"foo! { bar::<u8>::baz::<u8> }",
|
|
||||||
"fn foo () {let a = bar ::< u8 >:: baz ::< u8 > ;}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_two_paths() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ i:path, $ j:path) => {
|
|
||||||
fn foo() { let a = $ i; let b = $j; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items("foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_path_with_path() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ i:path) => {
|
|
||||||
fn foo() { let a = $ i :: bar; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items("foo! { foo }", "fn foo () {let a = foo :: bar ;}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_expr() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {
|
|
||||||
($ i:expr) => {
|
|
||||||
fn bar() { $ i; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items(
|
|
||||||
"foo! { 2 + 2 * baz(3).quux() }",
|
|
||||||
"fn bar () {2 + 2 * baz (3) . quux () ;}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_last_expr() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! vec {
|
|
||||||
($($item:expr),*) => {
|
|
||||||
{
|
|
||||||
let mut v = Vec::new();
|
|
||||||
$(
|
|
||||||
v.push($item);
|
|
||||||
)*
|
|
||||||
v
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items(
|
|
||||||
"vec!(1,2,3);",
|
|
||||||
"{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_expr_with_attr() {
|
|
||||||
parse_macro(
|
|
||||||
r#"
|
|
||||||
macro_rules! m {
|
|
||||||
($a:expr) => {0}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.assert_expand_items("m!(#[allow(a)]())", "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ty() {
|
fn test_ty() {
|
||||||
parse_macro(
|
parse_macro(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue