mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Add basic edition inline parser test support
This commit is contained in:
parent
7a5bf92b89
commit
713c47f25b
8 changed files with 185 additions and 172 deletions
|
|
@ -145,7 +145,7 @@ pub(super) fn atom_expr(
|
|||
stmt_list(p);
|
||||
m.complete(p, BLOCK_EXPR)
|
||||
}
|
||||
// test_err gen_blocks
|
||||
// test gen_blocks 2024
|
||||
// pub fn main() {
|
||||
// gen { yield ""; };
|
||||
// async gen { yield ""; };
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ fn lex(text: &str) -> String {
|
|||
fn parse_ok() {
|
||||
for case in TestCase::list("parser/ok") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text, Edition::CURRENT);
|
||||
assert!(!errors, "errors in an OK file {}:\n{actual}", case.rs.display());
|
||||
expect_file![case.rast].assert_eq(&actual);
|
||||
}
|
||||
|
|
@ -61,16 +61,16 @@ fn parse_ok() {
|
|||
fn parse_err() {
|
||||
for case in TestCase::list("parser/err") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text, Edition::CURRENT);
|
||||
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);
|
||||
fn parse(entry: TopEntryPoint, text: &str, edition: Edition) -> (String, bool) {
|
||||
let lexed = LexedStr::new(edition, text);
|
||||
let input = lexed.to_input();
|
||||
let output = entry.parse(&input, Edition::CURRENT);
|
||||
let output = entry.parse(&input, edition);
|
||||
|
||||
let mut buf = String::new();
|
||||
let mut errors = Vec::new();
|
||||
|
|
@ -153,9 +153,19 @@ impl TestCase {
|
|||
|
||||
#[track_caller]
|
||||
fn run_and_expect_no_errors(path: &str) {
|
||||
run_and_expect_no_errors_with_edition(path, Edition::CURRENT)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn run_and_expect_errors(path: &str) {
|
||||
run_and_expect_errors_with_edition(path, Edition::CURRENT)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn run_and_expect_no_errors_with_edition(path: &str, edition: Edition) {
|
||||
let path = PathBuf::from(path);
|
||||
let text = std::fs::read_to_string(&path).unwrap();
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text, edition);
|
||||
assert!(!errors, "errors in an OK file {}:\n{actual}", path.display());
|
||||
let mut p = PathBuf::from("..");
|
||||
p.push(path);
|
||||
|
|
@ -164,10 +174,10 @@ fn run_and_expect_no_errors(path: &str) {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
fn run_and_expect_errors(path: &str) {
|
||||
fn run_and_expect_errors_with_edition(path: &str, edition: Edition) {
|
||||
let path = PathBuf::from(path);
|
||||
let text = std::fs::read_to_string(&path).unwrap();
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
|
||||
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text, edition);
|
||||
assert!(errors, "no errors in an ERR file {}:\n{actual}", path.display());
|
||||
let mut p = PathBuf::from("..");
|
||||
p.push(path);
|
||||
|
|
|
|||
|
|
@ -307,6 +307,6 @@ fn expr() {
|
|||
|
||||
#[track_caller]
|
||||
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
|
||||
let (parsed, _errors) = super::parse(entry, input);
|
||||
let (parsed, _errors) = super::parse(entry, input, crate::Edition::CURRENT);
|
||||
expect.assert_eq(&parsed)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
mod ok {
|
||||
use crate::tests::run_and_expect_no_errors;
|
||||
use crate::tests::*;
|
||||
#[test]
|
||||
fn anonymous_const() {
|
||||
run_and_expect_no_errors("test_data/parser/inline/ok/anonymous_const.rs");
|
||||
|
|
@ -267,6 +267,13 @@ mod ok {
|
|||
run_and_expect_no_errors("test_data/parser/inline/ok/function_where_clause.rs");
|
||||
}
|
||||
#[test]
|
||||
fn gen_blocks() {
|
||||
run_and_expect_no_errors_with_edition(
|
||||
"test_data/parser/inline/ok/gen_blocks.rs",
|
||||
crate::Edition::Edition2024,
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn generic_arg() { run_and_expect_no_errors("test_data/parser/inline/ok/generic_arg.rs"); }
|
||||
#[test]
|
||||
fn generic_param_attribute() {
|
||||
|
|
@ -666,7 +673,7 @@ mod ok {
|
|||
fn yield_expr() { run_and_expect_no_errors("test_data/parser/inline/ok/yield_expr.rs"); }
|
||||
}
|
||||
mod err {
|
||||
use crate::tests::run_and_expect_errors;
|
||||
use crate::tests::*;
|
||||
#[test]
|
||||
fn angled_path_without_qual() {
|
||||
run_and_expect_errors("test_data/parser/inline/err/angled_path_without_qual.rs");
|
||||
|
|
@ -708,8 +715,6 @@ mod err {
|
|||
run_and_expect_errors("test_data/parser/inline/err/fn_pointer_type_missing_fn.rs");
|
||||
}
|
||||
#[test]
|
||||
fn gen_blocks() { run_and_expect_errors("test_data/parser/inline/err/gen_blocks.rs"); }
|
||||
#[test]
|
||||
fn gen_fn() { run_and_expect_errors("test_data/parser/inline/err/gen_fn.rs"); }
|
||||
#[test]
|
||||
fn generic_arg_list_recover() {
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
SOURCE_FILE
|
||||
FN
|
||||
VISIBILITY
|
||||
PUB_KW "pub"
|
||||
WHITESPACE " "
|
||||
FN_KW "fn"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "main"
|
||||
PARAM_LIST
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
RECORD_EXPR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "gen"
|
||||
WHITESPACE " "
|
||||
RECORD_EXPR_FIELD_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
STRING "\"\""
|
||||
ERROR
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
ERROR
|
||||
ASYNC_KW "async"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
RECORD_EXPR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "gen"
|
||||
WHITESPACE " "
|
||||
RECORD_EXPR_FIELD_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
ERROR
|
||||
STRING "\"\""
|
||||
ERROR
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
PATH_EXPR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "gen"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
CLOSURE_EXPR
|
||||
MOVE_KW "move"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
ERROR
|
||||
ASYNC_KW "async"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
PATH_EXPR
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "gen"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
CLOSURE_EXPR
|
||||
MOVE_KW "move"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n"
|
||||
error 26: expected identifier
|
||||
error 31: expected COMMA
|
||||
error 32: expected identifier
|
||||
error 34: expected COMMA
|
||||
error 34: expected identifier
|
||||
error 48: expected fn, trait or impl
|
||||
error 55: expected identifier
|
||||
error 60: expected COMMA
|
||||
error 61: expected identifier
|
||||
error 63: expected COMMA
|
||||
error 63: expected identifier
|
||||
error 75: expected SEMICOLON
|
||||
error 80: expected `|`
|
||||
error 80: expected SEMICOLON
|
||||
error 105: expected fn, trait or impl
|
||||
error 109: expected SEMICOLON
|
||||
error 114: expected `|`
|
||||
error 114: expected SEMICOLON
|
||||
101
crates/parser/test_data/parser/inline/ok/gen_blocks.rast
Normal file
101
crates/parser/test_data/parser/inline/ok/gen_blocks.rast
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
SOURCE_FILE
|
||||
FN
|
||||
COMMENT "// 2024"
|
||||
WHITESPACE "\n"
|
||||
VISIBILITY
|
||||
PUB_KW "pub"
|
||||
WHITESPACE " "
|
||||
FN_KW "fn"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "main"
|
||||
PARAM_LIST
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
GEN_KW "gen"
|
||||
WHITESPACE " "
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
ASYNC_KW "async"
|
||||
WHITESPACE " "
|
||||
GEN_KW "gen"
|
||||
WHITESPACE " "
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
GEN_KW "gen"
|
||||
WHITESPACE " "
|
||||
MOVE_KW "move"
|
||||
WHITESPACE " "
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
BLOCK_EXPR
|
||||
ASYNC_KW "async"
|
||||
WHITESPACE " "
|
||||
GEN_KW "gen"
|
||||
WHITESPACE " "
|
||||
MOVE_KW "move"
|
||||
WHITESPACE " "
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE " "
|
||||
EXPR_STMT
|
||||
YIELD_EXPR
|
||||
YIELD_KW "yield"
|
||||
WHITESPACE " "
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
SEMICOLON ";"
|
||||
WHITESPACE " "
|
||||
R_CURLY "}"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n"
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// 2024
|
||||
pub fn main() {
|
||||
gen { yield ""; };
|
||||
async gen { yield ""; };
|
||||
Loading…
Add table
Add a link
Reference in a new issue