mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
add top level tests for types
This commit is contained in:
parent
e78424846e
commit
640cc27ff0
3 changed files with 65 additions and 1 deletions
|
@ -122,6 +122,19 @@ pub(crate) mod entry {
|
||||||
}
|
}
|
||||||
m.complete(p, ERROR);
|
m.complete(p, ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn type_(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
types::type_(p);
|
||||||
|
if p.at(EOF) {
|
||||||
|
m.abandon(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while !p.at(EOF) {
|
||||||
|
p.bump_any();
|
||||||
|
}
|
||||||
|
m.complete(p, ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,8 @@ pub enum TopEntryPoint {
|
||||||
Pattern,
|
Pattern,
|
||||||
Type,
|
Type,
|
||||||
Expr,
|
Expr,
|
||||||
|
/// Edge case -- macros generally don't expand to attributes, with the
|
||||||
|
/// exception of `cfg_attr` which does!
|
||||||
MetaItem,
|
MetaItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +122,8 @@ impl TopEntryPoint {
|
||||||
TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts,
|
TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts,
|
||||||
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
|
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
|
||||||
TopEntryPoint::Pattern => grammar::entry::top::pattern,
|
TopEntryPoint::Pattern => grammar::entry::top::pattern,
|
||||||
|
TopEntryPoint::Type => grammar::entry::top::type_,
|
||||||
// FIXME
|
// FIXME
|
||||||
TopEntryPoint::Type => grammar::entry::prefix::ty,
|
|
||||||
TopEntryPoint::Expr => grammar::entry::prefix::expr,
|
TopEntryPoint::Expr => grammar::entry::prefix::expr,
|
||||||
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
||||||
};
|
};
|
||||||
|
|
|
@ -175,6 +175,55 @@ fn macro_pattern() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn type_() {
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Type,
|
||||||
|
"Option<!>",
|
||||||
|
expect![[r#"
|
||||||
|
PATH_TYPE
|
||||||
|
PATH
|
||||||
|
PATH_SEGMENT
|
||||||
|
NAME_REF
|
||||||
|
IDENT "Option"
|
||||||
|
GENERIC_ARG_LIST
|
||||||
|
L_ANGLE "<"
|
||||||
|
TYPE_ARG
|
||||||
|
NEVER_TYPE
|
||||||
|
BANG "!"
|
||||||
|
R_ANGLE ">"
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Type,
|
||||||
|
"() () ()",
|
||||||
|
expect![[r#"
|
||||||
|
ERROR
|
||||||
|
TUPLE_TYPE
|
||||||
|
L_PAREN "("
|
||||||
|
R_PAREN ")"
|
||||||
|
WHITESPACE " "
|
||||||
|
L_PAREN "("
|
||||||
|
R_PAREN ")"
|
||||||
|
WHITESPACE " "
|
||||||
|
L_PAREN "("
|
||||||
|
R_PAREN ")"
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Type,
|
||||||
|
"$$$",
|
||||||
|
expect![[r#"
|
||||||
|
ERROR
|
||||||
|
ERROR
|
||||||
|
DOLLAR "$"
|
||||||
|
DOLLAR "$"
|
||||||
|
DOLLAR "$"
|
||||||
|
error 0: expected type
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
|
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
|
||||||
let (parsed, _errors) = super::parse(entry, input);
|
let (parsed, _errors) = super::parse(entry, input);
|
||||||
|
|
Loading…
Reference in a new issue