tint/reader/wgsl: Minor cleanups
Change-Id: I3fccb7f5c31c27da5118d9ec6ed86d4a9c3157ed Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105400 Auto-Submit: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
d04c54e178
commit
ae832a2c6a
|
@ -23,6 +23,17 @@ using WhileStmtTest = ParserImplTest;
|
|||
|
||||
// Test an empty while loop.
|
||||
TEST_F(WhileStmtTest, Empty) {
|
||||
auto p = parser("while true { }");
|
||||
auto wl = p->while_statement();
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
EXPECT_FALSE(wl.errored);
|
||||
ASSERT_TRUE(wl.matched);
|
||||
EXPECT_TRUE(Is<ast::Expression>(wl->condition));
|
||||
EXPECT_TRUE(wl->body->Empty());
|
||||
}
|
||||
|
||||
// Test an empty while loop with parentheses.
|
||||
TEST_F(WhileStmtTest, EmptyWithParentheses) {
|
||||
auto p = parser("while (true) { }");
|
||||
auto wl = p->while_statement();
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -46,17 +57,6 @@ TEST_F(WhileStmtTest, Body) {
|
|||
|
||||
// Test a while loop with complex condition.
|
||||
TEST_F(WhileStmtTest, ComplexCondition) {
|
||||
auto p = parser("while ((a + 1 - 2) == 3) { }");
|
||||
auto wl = p->while_statement();
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
EXPECT_FALSE(wl.errored);
|
||||
ASSERT_TRUE(wl.matched);
|
||||
EXPECT_TRUE(Is<ast::Expression>(wl->condition));
|
||||
EXPECT_TRUE(wl->body->Empty());
|
||||
}
|
||||
|
||||
// Test a while loop with no brackets.
|
||||
TEST_F(WhileStmtTest, NoBrackets) {
|
||||
auto p = parser("while (a + 1 - 2) == 3 { }");
|
||||
auto wl = p->while_statement();
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -66,9 +66,20 @@ TEST_F(WhileStmtTest, NoBrackets) {
|
|||
EXPECT_TRUE(wl->body->Empty());
|
||||
}
|
||||
|
||||
// Test a while loop with complex condition, with parentheses.
|
||||
TEST_F(WhileStmtTest, ComplexConditionWithParentheses) {
|
||||
auto p = parser("while ((a + 1 - 2) == 3) { }");
|
||||
auto wl = p->while_statement();
|
||||
EXPECT_FALSE(p->has_error()) << p->error();
|
||||
EXPECT_FALSE(wl.errored);
|
||||
ASSERT_TRUE(wl.matched);
|
||||
EXPECT_TRUE(Is<ast::Expression>(wl->condition));
|
||||
EXPECT_TRUE(wl->body->Empty());
|
||||
}
|
||||
|
||||
class WhileStmtErrorTest : public ParserImplTest {
|
||||
public:
|
||||
void TestForWithError(std::string for_str, std::string error_str) {
|
||||
void TestWhileWithError(std::string for_str, std::string error_str) {
|
||||
auto p_for = parser(for_str);
|
||||
auto e_for = p_for->while_statement();
|
||||
|
||||
|
@ -85,7 +96,7 @@ TEST_F(WhileStmtErrorTest, MissingLeftParen) {
|
|||
std::string while_str = "while bool) { }";
|
||||
std::string error_str = "1:11: expected '(' for type constructor";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with missing condition is invalid.
|
||||
|
@ -93,7 +104,7 @@ TEST_F(WhileStmtErrorTest, MissingFirstSemicolon) {
|
|||
std::string while_str = "while () {}";
|
||||
std::string error_str = "1:8: unable to parse expression";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with missing right parenthesis is invalid.
|
||||
|
@ -101,7 +112,7 @@ TEST_F(WhileStmtErrorTest, MissingRightParen) {
|
|||
std::string while_str = "while (true {}";
|
||||
std::string error_str = "1:13: expected ')'";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with missing left brace is invalid.
|
||||
|
@ -109,7 +120,7 @@ TEST_F(WhileStmtErrorTest, MissingLeftBrace) {
|
|||
std::string while_str = "while (true) }";
|
||||
std::string error_str = "1:14: expected '{'";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a for loop with missing right brace is invalid.
|
||||
|
@ -117,7 +128,7 @@ TEST_F(WhileStmtErrorTest, MissingRightBrace) {
|
|||
std::string while_str = "while (true) {";
|
||||
std::string error_str = "1:15: expected '}'";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with an invalid break condition.
|
||||
|
@ -125,7 +136,7 @@ TEST_F(WhileStmtErrorTest, InvalidBreakConditionAsExpression) {
|
|||
std::string while_str = "while ((0 == 1) { }";
|
||||
std::string error_str = "1:17: expected ')'";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with a break condition not matching
|
||||
|
@ -134,7 +145,7 @@ TEST_F(WhileStmtErrorTest, InvalidBreakConditionMatch) {
|
|||
std::string while_str = "while (var i: i32 = 0) { }";
|
||||
std::string error_str = "1:8: unable to parse expression";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a while loop with an invalid body.
|
||||
|
@ -142,7 +153,7 @@ TEST_F(WhileStmtErrorTest, InvalidBody) {
|
|||
std::string while_str = "while (true) { let x: i32; }";
|
||||
std::string error_str = "1:26: expected '=' for 'let' declaration";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
// Test a for loop with a body not matching statements
|
||||
|
@ -150,7 +161,7 @@ TEST_F(WhileStmtErrorTest, InvalidBodyMatch) {
|
|||
std::string while_str = "while (true) { fn main() {} }";
|
||||
std::string error_str = "1:16: expected '}'";
|
||||
|
||||
TestForWithError(while_str, error_str);
|
||||
TestWhileWithError(while_str, error_str);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue