internal: more focused parsing tests

This commit is contained in:
Aleksey Kladov
2021-09-17 22:15:12 +03:00
parent 55078c81e0
commit 073d5f7733
19 changed files with 206 additions and 187 deletions

View File

@@ -245,29 +245,9 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
T![mod] => mod_item(p, m),
T![type] => type_alias(p, m),
T![struct] => {
// test struct_items
// struct Foo;
// struct Foo {}
// struct Foo();
// struct Foo(String, usize);
// struct Foo {
// a: i32,
// b: f32,
// }
adt::strukt(p, m);
}
T![struct] => adt::strukt(p, m),
T![enum] => adt::enum_(p, m),
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
// test union_items
// union Foo {}
// union Foo {
// a: i32,
// b: f32,
// }
adt::union(p, m);
}
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => adt::union(p, m),
// test pub_macro_def
// pub macro m($:ident) {}
@@ -324,6 +304,31 @@ pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
m.complete(p, MODULE);
}
// test type_alias
// type Foo = Bar;
fn type_alias(p: &mut Parser, m: Marker) {
p.bump(T![type]);
name(p);
// test type_item_type_params
// type Result<T> = ();
type_params::opt_generic_param_list(p);
if p.at(T![:]) {
type_params::bounds(p);
}
// test type_item_where_clause
// type Foo where Foo: Copy = ();
type_params::opt_where_clause(p);
if p.eat(T![=]) {
types::type_(p);
}
p.expect(T![;]);
m.complete(p, TYPE_ALIAS);
}
pub(crate) fn item_list(p: &mut Parser) {
assert!(p.at(T!['{']));
let m = p.start();
@@ -374,32 +379,6 @@ fn fn_(p: &mut Parser) {
}
}
// test type_item
// type Foo = Bar;
fn type_alias(p: &mut Parser, m: Marker) {
assert!(p.at(T![type]));
p.bump(T![type]);
name(p);
// test type_item_type_params
// type Result<T> = ();
type_params::opt_generic_param_list(p);
if p.at(T![:]) {
type_params::bounds(p);
}
// test type_item_where_clause
// type Foo where Foo: Copy = ();
type_params::opt_where_clause(p);
if p.eat(T![=]) {
types::type_(p);
}
p.expect(T![;]);
m.complete(p, TYPE_ALIAS);
}
fn macro_rules(p: &mut Parser, m: Marker) {
assert!(p.at_contextual_kw("macro_rules"));
p.bump_remap(T![macro_rules]);