1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/reader/wgsl/parser_impl_test_helper.h"
16
17 namespace tint {
18 namespace reader {
19 namespace wgsl {
20 namespace {
21
TEST_F(ParserImplTest,ParenRhsStmt)22 TEST_F(ParserImplTest, ParenRhsStmt) {
23 auto p = parser("(a + b)");
24 auto e = p->expect_paren_rhs_stmt();
25 ASSERT_FALSE(p->has_error()) << p->error();
26 ASSERT_FALSE(e.errored);
27 ASSERT_NE(e.value, nullptr);
28 ASSERT_TRUE(e->Is<ast::BinaryExpression>());
29 }
30
TEST_F(ParserImplTest,ParenRhsStmt_MissingLeftParen)31 TEST_F(ParserImplTest, ParenRhsStmt_MissingLeftParen) {
32 auto p = parser("true)");
33 auto e = p->expect_paren_rhs_stmt();
34 ASSERT_TRUE(p->has_error());
35 ASSERT_TRUE(e.errored);
36 ASSERT_EQ(e.value, nullptr);
37 EXPECT_EQ(p->error(), "1:1: expected '('");
38 }
39
TEST_F(ParserImplTest,ParenRhsStmt_MissingRightParen)40 TEST_F(ParserImplTest, ParenRhsStmt_MissingRightParen) {
41 auto p = parser("(true");
42 auto e = p->expect_paren_rhs_stmt();
43 ASSERT_TRUE(p->has_error());
44 ASSERT_TRUE(e.errored);
45 ASSERT_EQ(e.value, nullptr);
46 EXPECT_EQ(p->error(), "1:6: expected ')'");
47 }
48
TEST_F(ParserImplTest,ParenRhsStmt_InvalidExpression)49 TEST_F(ParserImplTest, ParenRhsStmt_InvalidExpression) {
50 auto p = parser("(if (a() {})");
51 auto e = p->expect_paren_rhs_stmt();
52 ASSERT_TRUE(p->has_error());
53 ASSERT_TRUE(e.errored);
54 ASSERT_EQ(e.value, nullptr);
55 EXPECT_EQ(p->error(), "1:2: unable to parse expression");
56 }
57
TEST_F(ParserImplTest,ParenRhsStmt_MissingExpression)58 TEST_F(ParserImplTest, ParenRhsStmt_MissingExpression) {
59 auto p = parser("()");
60 auto e = p->expect_paren_rhs_stmt();
61 ASSERT_TRUE(p->has_error());
62 ASSERT_TRUE(e.errored);
63 ASSERT_EQ(e.value, nullptr);
64 EXPECT_EQ(p->error(), "1:2: unable to parse expression");
65 }
66
67 } // namespace
68 } // namespace wgsl
69 } // namespace reader
70 } // namespace tint
71