wsgl parser: Fix tests that have multiple errors
A number of tests check the first encountered error is correct.
As the parser currently aborts after the first error, later errors are ignored.
Once the parser supports resynchronization, we'll emit multiple error messages, and these tests will start to fail. Fix them now.
Bug: tint:282
Change-Id: If8d0c41f030c652500b2e3b7284297b7a448d23e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32282
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/reader/wgsl/parser_impl_error_msg_test.cc b/src/reader/wgsl/parser_impl_error_msg_test.cc
index 9f6bffe..e72a80e 100644
--- a/src/reader/wgsl/parser_impl_error_msg_test.cc
+++ b/src/reader/wgsl/parser_impl_error_msg_test.cc
@@ -238,9 +238,9 @@
}
TEST_F(ParserImplErrorTest, ForLoopMissingLBrace) {
- EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) } }",
+ EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) }",
"test.wgsl:1:54 error: expected '{' for for loop\n"
- "fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) } }\n"
+ "fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) }\n"
" ^\n");
}
@@ -715,31 +715,31 @@
}
TEST_F(ParserImplErrorTest, GlobalDeclStructMemberOffsetMissingLParen) {
- EXPECT("struct S { [[offset 1)]] i : i32 };",
+ EXPECT("struct S { [[offset 1)]] i : i32; };",
"test.wgsl:1:21 error: expected '(' for offset decoration\n"
- "struct S { [[offset 1)]] i : i32 };\n"
+ "struct S { [[offset 1)]] i : i32; };\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclStructMemberOffsetMissingRParen) {
- EXPECT("struct S { [[offset(1]] i : i32 };",
+ EXPECT("struct S { [[offset(1]] i : i32; };",
"test.wgsl:1:22 error: expected ')' for offset decoration\n"
- "struct S { [[offset(1]] i : i32 };\n"
+ "struct S { [[offset(1]] i : i32; };\n"
" ^^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclStructMemberOffsetInvaldValue) {
- EXPECT("struct S { [[offset(x)]] i : i32 };",
+ EXPECT("struct S { [[offset(x)]] i : i32; };",
"test.wgsl:1:21 error: expected signed integer literal for offset "
"decoration\n"
- "struct S { [[offset(x)]] i : i32 };\n"
+ "struct S { [[offset(x)]] i : i32; };\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclStructMemberOffsetNegativeValue) {
- EXPECT("struct S { [[offset(-2)]] i : i32 };",
+ EXPECT("struct S { [[offset(-2)]] i : i32; };",
"test.wgsl:1:21 error: offset decoration must be positive\n"
- "struct S { [[offset(-2)]] i : i32 };\n"
+ "struct S { [[offset(-2)]] i : i32; };\n"
" ^^\n");
}
@@ -1127,9 +1127,9 @@
}
TEST_F(ParserImplErrorTest, LoopMissingLBrace) {
- EXPECT("fn f() -> void { loop } }",
+ EXPECT("fn f() -> void { loop }",
"test.wgsl:1:23 error: expected '{' for loop\n"
- "fn f() -> void { loop } }\n"
+ "fn f() -> void { loop }\n"
" ^\n");
}
@@ -1219,9 +1219,9 @@
}
TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingLBrace) {
- EXPECT("fn f() -> void { switch(1) { case 1: } } }",
+ EXPECT("fn f() -> void { switch(1) { case 1: } }",
"test.wgsl:1:38 error: expected '{' for case statement\n"
- "fn f() -> void { switch(1) { case 1: } } }\n"
+ "fn f() -> void { switch(1) { case 1: } }\n"
" ^\n");
}
diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc
index ae1e2d3..cc4d257 100644
--- a/src/reader/wgsl/parser_impl_function_header_test.cc
+++ b/src/reader/wgsl/parser_impl_function_header_test.cc
@@ -39,7 +39,7 @@
}
TEST_F(ParserImplTest, FunctionHeader_MissingIdent) {
- auto* p = parser("fn () ->");
+ auto* p = parser("fn () -> void");
auto f = p->function_header();
EXPECT_FALSE(f.matched);
EXPECT_TRUE(f.errored);