Add test for let with complex constructor
This CL adds a let unittest with a complex constructor. The test verifies the entire statement is parsed. Bug: tint:1633 Change-Id: I56bb7c009efb5668aa41c9b7ec80dcde65c4ec40 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99863 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
96a7d5a6bd
commit
9284f8ab55
|
@ -153,6 +153,32 @@ TEST_F(ParserImplTest, VariableStmt_Let) {
|
||||||
ASSERT_EQ(e->source.range.end.column, 6u);
|
ASSERT_EQ(e->source.range.end.column, 6u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, VariableStmt_Let_ComplexExpression) {
|
||||||
|
auto p = parser("let x = collide + collide_1;");
|
||||||
|
// Parse as `statement` to validate the `;` at the end so we know we parsed the whole expression
|
||||||
|
auto e = p->statement();
|
||||||
|
EXPECT_TRUE(e.matched);
|
||||||
|
EXPECT_FALSE(e.errored);
|
||||||
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
|
||||||
|
|
||||||
|
auto* decl = e->As<ast::VariableDeclStatement>();
|
||||||
|
ASSERT_NE(decl->variable->constructor, nullptr);
|
||||||
|
|
||||||
|
ASSERT_TRUE(decl->variable->constructor->Is<ast::BinaryExpression>());
|
||||||
|
auto* expr = decl->variable->constructor->As<ast::BinaryExpression>();
|
||||||
|
EXPECT_EQ(expr->op, ast::BinaryOp::kAdd);
|
||||||
|
|
||||||
|
ASSERT_TRUE(expr->lhs->Is<ast::IdentifierExpression>());
|
||||||
|
auto* ident = expr->lhs->As<ast::IdentifierExpression>();
|
||||||
|
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("collide"));
|
||||||
|
|
||||||
|
ASSERT_TRUE(expr->rhs->Is<ast::IdentifierExpression>());
|
||||||
|
ident = expr->rhs->As<ast::IdentifierExpression>();
|
||||||
|
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("collide_1"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
|
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
|
||||||
auto p = parser("let a : i32 1");
|
auto p = parser("let a : i32 1");
|
||||||
auto e = p->variable_statement();
|
auto e = p->variable_statement();
|
||||||
|
|
Loading…
Reference in New Issue