mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
add top-level tests for expressions
This commit is contained in:
parent
640cc27ff0
commit
fa049d94d1
3 changed files with 54 additions and 1 deletions
|
@ -135,6 +135,19 @@ pub(crate) mod entry {
|
||||||
}
|
}
|
||||||
m.complete(p, ERROR);
|
m.complete(p, ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn expr(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
expressions::expr(p);
|
||||||
|
if p.at(EOF) {
|
||||||
|
m.abandon(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while !p.at(EOF) {
|
||||||
|
p.bump_any();
|
||||||
|
}
|
||||||
|
m.complete(p, ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ impl TopEntryPoint {
|
||||||
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_,
|
TopEntryPoint::Type => grammar::entry::top::type_,
|
||||||
|
TopEntryPoint::Expr => grammar::entry::top::expr,
|
||||||
// FIXME
|
// FIXME
|
||||||
TopEntryPoint::Expr => grammar::entry::prefix::expr,
|
|
||||||
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
||||||
};
|
};
|
||||||
let mut p = parser::Parser::new(input);
|
let mut p = parser::Parser::new(input);
|
||||||
|
|
|
@ -224,6 +224,46 @@ fn type_() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expr() {
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Expr,
|
||||||
|
"2 + 2 == 5",
|
||||||
|
expect![[r#"
|
||||||
|
BIN_EXPR
|
||||||
|
BIN_EXPR
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "2"
|
||||||
|
WHITESPACE " "
|
||||||
|
PLUS "+"
|
||||||
|
WHITESPACE " "
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "2"
|
||||||
|
WHITESPACE " "
|
||||||
|
EQ2 "=="
|
||||||
|
WHITESPACE " "
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "5"
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Expr,
|
||||||
|
"let _ = 0;",
|
||||||
|
expect![[r#"
|
||||||
|
ERROR
|
||||||
|
LET_KW "let"
|
||||||
|
WHITESPACE " "
|
||||||
|
UNDERSCORE "_"
|
||||||
|
WHITESPACE " "
|
||||||
|
EQ "="
|
||||||
|
WHITESPACE " "
|
||||||
|
INT_NUMBER "0"
|
||||||
|
SEMICOLON ";"
|
||||||
|
error 0: expected expression
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[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…
Add table
Add a link
Reference in a new issue