Correctly handle #"" in edition <2024

This commit is contained in:
Chayim Refael Friedman 2024-10-27 00:47:13 +03:00
parent 6a67a4d3cd
commit 3b3beaab31
4 changed files with 30 additions and 7 deletions

View file

@ -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() {