Improve switch's diagnostics
This commit is contained in:
parent
e29ffb2a9c
commit
f695f8a52e
17 changed files with 2702 additions and 231 deletions
|
|
@ -16,43 +16,163 @@ use rottlib::parser::Parser;
|
|||
/// Keep these small: the goal is to inspect lexer diagnostics and delimiter
|
||||
/// recovery behavior, not full parser behavior.
|
||||
const TEST_CASES: &[(&str, &str)] = &[
|
||||
// P0031 - FunctionCallArgumentMissingComma
|
||||
// P0034 - SwitchMissingBody
|
||||
("files/P0034_01.uc", "switch(A) local\n"),
|
||||
("files/P0034_02.uc", "switch\n(A)\nvar"),
|
||||
("files/P0034_03.uc", "switch(\n A\n)\n"),
|
||||
("files/P0034_04.uc", "switch\n(\n A\n)\n"),
|
||||
("files/P0034_05.uc", "switch(A)\ncase 1:\n"),
|
||||
|
||||
// P0035 - SwitchTopLevelItemNotCase
|
||||
("files/P0035_01.uc", "switch(A) {\n Log(\"bad\");\n}\n"),
|
||||
(
|
||||
"files/P0031_01.uc",
|
||||
"{\n Func(A B);\n Log(\"after\");\n}\n",
|
||||
"files/P0035_02.uc",
|
||||
"switch\n(A)\n{\n Log(\"bad\");\n Log(\"worse\");\n case 1:\n}\n",
|
||||
),
|
||||
("files/P0035_03.uc", "switch(A) {\n 123;\n default:\n}\n"),
|
||||
(
|
||||
"files/P0035_04.uc",
|
||||
"switch\n(\n A\n)\n{\n if (A) {}\n case 1:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0031_02.uc",
|
||||
"{\n Func\n (A 123);\n Log(\"after\");\n}\n",
|
||||
"files/P0035_05.uc",
|
||||
"switch(A) {\n {\n Log(\"nested\");\n }\n case 1:\n}\n",
|
||||
),
|
||||
|
||||
// P0036 - SwitchCaseMissingColon
|
||||
(
|
||||
"files/P0036_01.uc",
|
||||
"switch(A) {\n case 1\n case 2:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0031_03.uc",
|
||||
"{\n Func(\n A\n new SomeClass\n );\n Log(\"after\");\n}\n",
|
||||
),
|
||||
// P0032 - FunctionCallMissingClosingParenthesis
|
||||
("files/P0032_01.uc", "Func("),
|
||||
("files/P0032_02.uc", "Func\n(\n A,"),
|
||||
("files/P0032_03.uc", "Func(A,\n B,"),
|
||||
(
|
||||
"files/P0032_04.uc",
|
||||
"{\n Func\n (\n A,\n B,\n",
|
||||
),
|
||||
// P0033 - FunctionCallUnexpectedTokenInArgumentList
|
||||
(
|
||||
"files/P0033_01.uc",
|
||||
"{\n Func(A #, B);\n Log(\"after\");\n}\n",
|
||||
"files/P0036_02.uc",
|
||||
"switch\n(A)\n{\n case\n 1\n default:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_02.uc",
|
||||
"{\n Func\n (A\n :,\n B);\n Log(\"after\");\n}\n",
|
||||
"files/P0036_03.uc",
|
||||
"switch(A) {\n case (A)\n case B:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_03.uc",
|
||||
"{\n Func(\n A ?\n , B\n );\n Log(\"after\");\n}\n",
|
||||
"files/P0036_04.uc",
|
||||
"switch\n(\n A\n)\n{\n case\n A + B\n default\n :\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_04.uc",
|
||||
"{\n Func\n (\n A\n #,\n B\n );\n Log(\"after\");\n}\n",
|
||||
"files/P0036_05.uc",
|
||||
"switch(A) {\n case Foo.Bar(Baz)\n case Other:\n}\n",
|
||||
),
|
||||
|
||||
// P0037 - SwitchDefaultMissingColon
|
||||
(
|
||||
"files/P0037_01.uc",
|
||||
"switch(A) {\n default\n if (A) {}\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0037_02.uc",
|
||||
"switch\n(A)\n{\n default\n while (A) {}\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0037_03.uc",
|
||||
"switch(A) {\n default\n for (;;) {}\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0037_04.uc",
|
||||
"switch\n(\n A\n)\n{\n default\n switch(B) {\n case 1:\n }\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0037_05.uc",
|
||||
"switch(A) {\n default\n case 1:\n}\n",
|
||||
),
|
||||
|
||||
// P0038 - SwitchDuplicateDefault
|
||||
(
|
||||
"files/P0038_01.uc",
|
||||
"switch(A) {\n default:\n default:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0038_02.uc",
|
||||
"switch\n(A)\n{\n default\n :\n default\n :\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0038_03.uc",
|
||||
"switch(A) {\n default:\n default:\n default:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0038_04.uc",
|
||||
"switch\n(\n A\n)\n{\n default:\n Log(\"first\");\n default:\n Log(\"second\");\n}\n",
|
||||
),
|
||||
|
||||
// P0039 - SwitchCasesAfterDefault
|
||||
(
|
||||
"files/P0039_01.uc",
|
||||
"switch(A) {\n default:\n case 1:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0039_02.uc",
|
||||
"switch\n(A)\n{\n default\n :\n case\n 1\n :\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0039_03.uc",
|
||||
"switch(A) {\n default:\n case 1:\n case 2:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0039_04.uc",
|
||||
"switch\n(\n A\n)\n{\n default:\n case 1:\n Log(\"one\");\n case 2:\n Log(\"two\");\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0039_05.uc",
|
||||
"switch(A) {\n default:\n Log(\"done\");\n case 1:\n case 2:\n Log(\"stacked\");\n}\n",
|
||||
),
|
||||
|
||||
// P0040 - SwitchMissingClosingBrace
|
||||
("files/P0040_01.uc", "switch(A) {\n"),
|
||||
("files/P0040_02.uc", "switch(A) {\n case 1:\n"),
|
||||
("files/P0040_03.uc", "switch\n(A)\n{\n default:\n"),
|
||||
(
|
||||
"files/P0040_04.uc",
|
||||
"switch\n(\n A\n)\n{\n case 1:\n case 2:\n",
|
||||
),
|
||||
(
|
||||
"files/P0040_05.uc",
|
||||
"switch(A) {\n case 1:\n Log(\"body\");\n",
|
||||
),
|
||||
|
||||
// P0041 - SwitchCaseMissingExpression
|
||||
("files/P0041_01.uc", "switch(A) {\n case:\n}\n"),
|
||||
("files/P0041_02.uc", "switch\n(A)\n{\n case\n :\n}\n"),
|
||||
("files/P0041_03.uc", "switch(A) {\n case:\n default:\n}\n"),
|
||||
(
|
||||
"files/P0041_04.uc",
|
||||
"switch\n(\n A\n)\n{\n case\n :\n case 1:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0041_05.uc",
|
||||
"switch(A) {\n case\n :\n default:\n}\n",
|
||||
),
|
||||
|
||||
// P0042 - SwitchCaseExpressionInvalidStart
|
||||
("files/P0042_01.uc", "switch(A) {\n case *:\n}\n"),
|
||||
(
|
||||
"files/P0042_02.uc",
|
||||
"switch\n(A)\n{\n case\n =\n :\n}\n",
|
||||
),
|
||||
("files/P0042_03.uc", "switch(A) {\n case &&:\n default:\n}\n"),
|
||||
(
|
||||
"files/P0042_04.uc",
|
||||
"switch\n(\n A\n)\n{\n case\n .\n :\n case 1:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0042_05.uc",
|
||||
"switch(A) {\n case ]:\n}\n",
|
||||
),
|
||||
|
||||
// Mixed / intentional cascades
|
||||
(
|
||||
"files/P0042_cascade_01.uc",
|
||||
"switch(A) {\n case *\n case 1:\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0042_cascade_02.uc",
|
||||
"switch\n(\n A\n)\n{\n case\n =\n default:\n}\n",
|
||||
),
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue