diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 13a8b64f48..99abd60a0e 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -3174,6 +3174,10 @@ Expect 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(); diff --git a/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc b/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc index 1c47f879b6..59cddc6bf5 100644 --- a/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_relational_expression_test.cc @@ -244,6 +244,56 @@ TEST_F(ParserImplTest, RelationalExpression_PostUnary_Parses_GreaterThanEqual) { ASSERT_TRUE(rel->rhs->As()->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()); + auto* rel = e->As(); + EXPECT_EQ(ast::BinaryOp::kEqual, rel->op); + + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); + + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->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()); + auto* rel = e->As(); + EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op); + + ASSERT_TRUE(rel->lhs->Is()); + auto* ident = rel->lhs->As(); + EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); + + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); +} + TEST_F(ParserImplTest, RelationalExpression_PostUnary_InvalidRHS) { auto p = parser("true < if (a) {}"); auto lhs = p->unary_expression();