mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Correctly handle #""
in edition <2024
This commit is contained in:
parent
6a67a4d3cd
commit
3b3beaab31
4 changed files with 30 additions and 7 deletions
|
@ -15,11 +15,20 @@ use crate::{Edition, LexedStr, TopEntryPoint};
|
|||
#[path = "../test_data/generated/runner.rs"]
|
||||
mod runner;
|
||||
|
||||
fn infer_edition(file_path: &Path) -> Edition {
|
||||
let file_content = std::fs::read_to_string(file_path).unwrap();
|
||||
if let Some(edition) = file_content.strip_prefix("//@ edition: ") {
|
||||
edition[..4].parse().expect("invalid edition directive")
|
||||
} else {
|
||||
Edition::CURRENT
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lex_ok() {
|
||||
for case in TestCase::list("lexer/ok") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let actual = lex(&case.text);
|
||||
let actual = lex(&case.text, infer_edition(&case.rs));
|
||||
expect_file![case.rast].assert_eq(&actual)
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +37,13 @@ fn lex_ok() {
|
|||
fn lex_err() {
|
||||
for case in TestCase::list("lexer/err") {
|
||||
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
|
||||
let actual = lex(&case.text);
|
||||
let actual = lex(&case.text, infer_edition(&case.rs));
|
||||
expect_file![case.rast].assert_eq(&actual)
|
||||
}
|
||||
}
|
||||
|
||||
fn lex(text: &str) -> String {
|
||||
let lexed = LexedStr::new(Edition::CURRENT, text);
|
||||
fn lex(text: &str, edition: Edition) -> String {
|
||||
let lexed = LexedStr::new(edition, text);
|
||||
|
||||
let mut res = String::new();
|
||||
for i in 0..lexed.len() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue