mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Rewrite inline parser test infra to generated proper rust test cases
This commit is contained in:
parent
ef462ca88e
commit
7a5bf92b89
503 changed files with 955 additions and 163 deletions
|
@ -388,7 +388,7 @@ fn macro_def(p: &mut Parser<'_>, m: Marker) {
|
|||
m.complete(p, MACRO_DEF);
|
||||
}
|
||||
|
||||
// test fn
|
||||
// test fn_
|
||||
// fn foo() {}
|
||||
fn fn_(p: &mut Parser<'_>, m: Marker) {
|
||||
p.bump(T![fn]);
|
||||
|
|
|
@ -169,7 +169,7 @@ fn array_or_slice_type(p: &mut Parser<'_>) {
|
|||
m.complete(p, kind);
|
||||
}
|
||||
|
||||
// test reference_type;
|
||||
// test reference_type
|
||||
// type A = &();
|
||||
// type B = &'static ();
|
||||
// type C = &mut ();
|
||||
|
|
|
@ -11,6 +11,9 @@ use expect_test::expect_file;
|
|||
|
||||
use crate::{Edition, LexedStr, TopEntryPoint};
|
||||
|
||||
#[path = "../test_data/generated/runner.rs"]
|
||||
mod runner;
|
||||
|
||||
#[test]
|
||||
fn lex_ok() {
|
||||
for case in TestCase::list("lexer/ok") {
|
||||
|
@ -54,16 +57,6 @@ fn parse_ok() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_inline_ok() {
|
||||
for case in TestCase::list("parser/inline/ok") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
|
||||
assert!(!errors, "errors in an OK file {}:\n{actual}", case.rs.display());
|
||||
expect_file![case.rast].assert_eq(&actual);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_err() {
|
||||
for case in TestCase::list("parser/err") {
|
||||
|
@ -74,16 +67,6 @@ fn parse_err() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_inline_err() {
|
||||
for case in TestCase::list("parser/inline/err") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
|
||||
assert!(errors, "no errors in an ERR file {}:\n{actual}", case.rs.display());
|
||||
expect_file![case.rast].assert_eq(&actual)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
|
||||
let lexed = LexedStr::new(Edition::CURRENT, text);
|
||||
let input = lexed.to_input();
|
||||
|
@ -167,3 +150,27 @@ impl TestCase {
|
|||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn run_and_expect_no_errors(path: &str) {
|
||||
let path = PathBuf::from(path);
|
||||
let text = std::fs::read_to_string(&path).unwrap();
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
|
||||
assert!(!errors, "errors in an OK file {}:\n{actual}", path.display());
|
||||
let mut p = PathBuf::from("..");
|
||||
p.push(path);
|
||||
p.set_extension("rast");
|
||||
expect_file![p].assert_eq(&actual)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn run_and_expect_errors(path: &str) {
|
||||
let path = PathBuf::from(path);
|
||||
let text = std::fs::read_to_string(&path).unwrap();
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
|
||||
assert!(errors, "no errors in an ERR file {}:\n{actual}", path.display());
|
||||
let mut p = PathBuf::from("..");
|
||||
p.push(path);
|
||||
p.set_extension("rast");
|
||||
expect_file![p].assert_eq(&actual)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue