From fdd2ff11455b9c628e7b9383e5cabe1825878c55 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 19 Oct 2022 20:28:34 +0000 Subject: [PATCH] Add tests to show correct handling of mixed && and ||. This CL adds tests to verify the new parser handles the mixing of && and || correctly. Bug: tint:1599 Change-Id: I1a73d041a00118ed649522ae07fc1489021c4b41 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106461 Kokoro: Kokoro Auto-Submit: Dan Sinclair Commit-Queue: Dan Sinclair Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton --- .../wgsl/parser_impl_expression_test.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/tint/reader/wgsl/parser_impl_expression_test.cc b/src/tint/reader/wgsl/parser_impl_expression_test.cc index e3e53fc8f1..389999fcde 100644 --- a/src/tint/reader/wgsl/parser_impl_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_expression_test.cc @@ -250,6 +250,25 @@ TEST_F(ParserImplTest, Expression_InvalidRelational) { EXPECT_EQ(p->error(), "1:6: unable to parse right side of <= expression"); } +TEST_F(ParserImplTest, Expression_Associativity) { + auto p = parser("1 < 2 || 2 < 3"); + auto e = p->expression(); + EXPECT_TRUE(e.matched); + EXPECT_FALSE(e.errored); + EXPECT_FALSE(p->has_error()) << p->error(); + ASSERT_NE(e.value, nullptr); +} + +TEST_F(ParserImplTest, Expression_InvalidAssociativity) { + auto p = parser("1 < 2 && 2 < 3 || 3 < 4"); + auto e = p->expression(); + EXPECT_FALSE(e.matched); + EXPECT_TRUE(e.errored); + EXPECT_TRUE(p->has_error()); + EXPECT_EQ(e.value, nullptr); + EXPECT_EQ(p->error(), R"(1:7: mixing '&&' and '||' requires parenthesis)"); +} + namespace mixing_binary_ops { struct BinaryOperatorInfo {