add top level tests for types

This commit is contained in:
Aleksey Kladov 2022-01-02 17:45:18 +03:00
parent e78424846e
commit 640cc27ff0
3 changed files with 65 additions and 1 deletions

View File

@ -122,6 +122,19 @@ pub(crate) mod entry {
}
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);
}
}
}

View File

@ -110,6 +110,8 @@ pub enum TopEntryPoint {
Pattern,
Type,
Expr,
/// Edge case -- macros generally don't expand to attributes, with the
/// exception of `cfg_attr` which does!
MetaItem,
}
@ -120,8 +122,8 @@ impl TopEntryPoint {
TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts,
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
TopEntryPoint::Pattern => grammar::entry::top::pattern,
TopEntryPoint::Type => grammar::entry::top::type_,
// FIXME
TopEntryPoint::Type => grammar::entry::prefix::ty,
TopEntryPoint::Expr => grammar::entry::prefix::expr,
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
};

View File

@ -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]
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
let (parsed, _errors) = super::parse(entry, input);