improve recovery on top level declarations

This commit is contained in:
Vexu
2020-05-13 20:42:18 +03:00
parent afab095b61
commit 23c5ff94e9
4 changed files with 127 additions and 69 deletions

View File

@@ -1,4 +1,4 @@
test "zig fmt: fault tolerant parsing" {
test "recovery: top level" {
try testError(
\\test "" {inline}
\\test "" {inline}
@@ -6,6 +6,9 @@ test "zig fmt: fault tolerant parsing" {
.ExpectedInlinable,
.ExpectedInlinable,
});
}
test "recovery: block statements" {
try testError(
\\test "" {
\\ foo + +;
@@ -15,6 +18,9 @@ test "zig fmt: fault tolerant parsing" {
.InvalidToken,
.ExpectedInlinable,
});
}
test "recovery: missing comma" {
try testError(
\\test "" {
\\ switch (foo) {
@@ -33,6 +39,29 @@ test "zig fmt: fault tolerant parsing" {
});
}
test "recovery: extra qualifier" {
try testError(
\\const a: *const const u8;
\\test ""
, &[_]Error{
.ExtraConstQualifier,
.ExpectedLBrace,
});
}
test "recovery: missing return type" {
try testError(
\\fn foo() {
\\ a && b;
\\}
\\test ""
, &[_]Error{
.ExpectedReturnType,
.InvalidAnd,
.ExpectedLBrace,
});
}
test "zig fmt: top-level fields" {
try testCanonical(
\\a: did_you_know,