Add missing relational_expression.post.unary_expression checks.

This CL adds the missing checks and tests for `==` and `!=` into
the `relational_expression.post.unary_expression` grammar elements.

Bug: tint:1633
Change-Id: Ib5fbb42994ea12af133ca531989421fddc2393f2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99940
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-08-22 19:23:24 +00:00 committed by Dawn LUCI CQ
parent a838e34954
commit 08d735e6a9
2 changed files with 54 additions and 0 deletions

View File

@ -3174,6 +3174,10 @@ Expect<const ast::Expression*> ParserImpl::expect_relational_expression_post_una
op = ast::BinaryOp::kLessThanEqual;
} else if (t.Is(Token::Type::kGreaterThanEqual)) {
op = ast::BinaryOp::kGreaterThanEqual;
} else if (t.Is(Token::Type::kEqualEqual)) {
op = ast::BinaryOp::kEqual;
} else if (t.Is(Token::Type::kNotEqual)) {
op = ast::BinaryOp::kNotEqual;
}
auto& next = peek();

View File

@ -244,6 +244,56 @@ TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_GreaterThanEqual) {
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_Equal) {
auto p = parser("a == true");
auto lhs = p->unary_expression();
auto e = p->expect_relational_expression_post_unary_expression(lhs.value);
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->source.range.begin.line, 1u);
EXPECT_EQ(e->source.range.begin.column, 3u);
EXPECT_EQ(e->source.range.end.line, 1u);
EXPECT_EQ(e->source.range.end.column, 5u);
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
auto* rel = e->As<ast::BinaryExpression>();
EXPECT_EQ(ast::BinaryOp::kEqual, rel->op);
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_NotEqual) {
auto p = parser("a != true");
auto lhs = p->unary_expression();
auto e = p->expect_relational_expression_post_unary_expression(lhs.value);
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->source.range.begin.line, 1u);
EXPECT_EQ(e->source.range.begin.column, 3u);
EXPECT_EQ(e->source.range.end.line, 1u);
EXPECT_EQ(e->source.range.end.column, 5u);
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
auto* rel = e->As<ast::BinaryExpression>();
EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op);
ASSERT_TRUE(rel->lhs->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_PostUnary_InvalidRHS) {
auto p = parser("true < if (a) {}");
auto lhs = p->unary_expression();