Prepare fixtures

This commit is contained in:
dkanus 2026-07-14 20:27:09 +07:00
commit 9c94356263
6021 changed files with 722805 additions and 22 deletions

View file

@ -11,56 +11,118 @@ use rottlib::diagnostics::Diagnostic;
use rottlib::lexer::TokenizedFile;
use rottlib::parser::Parser;
#[derive(Clone, Copy, Debug)]
enum ParseMode {
Expression,
SourceFile,
}
const PARSE_MODE: ParseMode = ParseMode::SourceFile;
const TEST_CASES: &[(&str, &str)] = &[
// P0057 - VarEditorSpecifierExpected
("files/P0057_01.uc", "var(Category,) int A;\n"),
("files/P0057_02.uc", "var(,) int A;\n"),
(
"files/P0057_01.uc",
concat!("class Test extends Actor;\n", "var(Category,) int A;\n"),
),
(
"files/P0057_02.uc",
concat!("class Test extends Actor;\n", "var(,) int A;\n"),
),
(
"files/P0057_03.uc",
"var(\n ,\n ,\n Category\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n ,\n ,\n Category\n) int A;\n"
),
),
(
"files/P0057_04.uc",
"var(\n Category,\n\n\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category,\n\n\n) int A;\n"
),
),
// P0058 - VarEditorSpecifierListMissingSeparator
("files/P0058_01.uc", "var(Category DisplayName) int A;\n"),
("files/P0058_02.uc", "var(\"Display\" \"Tooltip\") int A;\n"),
(
"files/P0058_01.uc",
concat!(
"class Test extends Actor;\n",
"var(Category DisplayName) int A;\n"
),
),
(
"files/P0058_02.uc",
concat!(
"class Test extends Actor;\n",
"var(\"Display\" \"Tooltip\") int A;\n"
),
),
(
"files/P0058_03.uc",
"var(\n Category\n DisplayName\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category\n DisplayName\n) int A;\n"
),
),
(
"files/P0058_04.uc",
"var(\n Category\n\n \"Display Name\",\n Advanced\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category\n\n \"Display Name\",\n Advanced\n) int A;\n"
),
),
// P0059 - VarEditorSpecifierListExpectedCommaOrClosingParenthesis
("files/P0059_01.uc", "var(Category :) int A;\n"),
("files/P0059_02.uc", "var(\"Display\" *) int A;\n"),
(
"files/P0059_01.uc",
concat!("class Test extends Actor;\n", "var(Category :) int A;\n"),
),
(
"files/P0059_02.uc",
concat!(
"class Test extends Actor;\n",
"var(\"Display\" *) int A;\n"
),
),
(
"files/P0059_03.uc",
"var(\n Category\n [\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category\n [\n) int A;\n"
),
),
(
"files/P0059_04.uc",
"var(\n \"Display Name\"\n\n ]\n) int A;\n",
concat!(
"class Test extends Actor;\n",
"var(\n \"Display Name\"\n\n ]\n) int A;\n"
),
),
// P0060 - VarEditorSpecifierListMissingClosingParenthesis
("files/P0060_01.uc", "var(Category\n"),
(
"files/P0060_01.uc",
concat!("class Test extends Actor;\n", "var(Category\n"),
),
(
"files/P0060_02.uc",
"var(\n Category,\n \"Display Name\"\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category,\n \"Display Name\"\n"
),
),
(
"files/P0060_03.uc",
"var(\n\n\n",
concat!("class Test extends Actor;\n", "var(\n\n\n"),
),
(
"files/P0060_04.uc",
"var(\n Category,\n\n \"Display Name\"\n\n",
concat!(
"class Test extends Actor;\n",
"var(\n Category,\n\n \"Display Name\"\n\n"
),
),
];
@ -183,11 +245,25 @@ fn main() {
if RUN_PARSER {
let mut parser = Parser::new(&tf, &arena);
let expr = parser.parse_expression();
if PRINT_PARSED_EXPR {
println!("Parsed expression:");
println!("{expr:#?}");
match PARSE_MODE {
ParseMode::Expression => {
let expr = parser.parse_expression();
if PRINT_PARSED_EXPR {
println!("Parsed expression:");
println!("{expr:#?}");
}
}
ParseMode::SourceFile => {
if let Err(error) = parser.parse_source_file() {
parser.report_error(error);
}
if PRINT_PARSED_EXPR {
println!("Parsed source file: <not printed>");
}
}
}
if parser.diagnostics.is_empty() {
@ -224,4 +300,4 @@ fn render_diagnostic(
_colors: bool,
) {
diag.render(file, file_name.unwrap_or("<default>"));
}
}