• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,ElseStmt)22 TEST_F(ParserImplTest, ElseStmt) {
23   auto p = parser("else { a = b; c = d; }");
24   auto e = p->else_stmt();
25   EXPECT_TRUE(e.matched);
26   EXPECT_FALSE(e.errored);
27   EXPECT_FALSE(p->has_error()) << p->error();
28   ASSERT_NE(e.value, nullptr);
29   ASSERT_TRUE(e->Is<ast::ElseStatement>());
30   ASSERT_EQ(e->condition, nullptr);
31   EXPECT_EQ(e->body->statements.size(), 2u);
32 }
33 
TEST_F(ParserImplTest,ElseStmt_InvalidBody)34 TEST_F(ParserImplTest, ElseStmt_InvalidBody) {
35   auto p = parser("else { fn main() {}}");
36   auto e = p->else_stmt();
37   EXPECT_FALSE(e.matched);
38   EXPECT_TRUE(e.errored);
39   EXPECT_EQ(e.value, nullptr);
40   EXPECT_TRUE(p->has_error());
41   EXPECT_EQ(p->error(), "1:8: expected '}'");
42 }
43 
TEST_F(ParserImplTest,ElseStmt_MissingBody)44 TEST_F(ParserImplTest, ElseStmt_MissingBody) {
45   auto p = parser("else");
46   auto e = p->else_stmt();
47   EXPECT_FALSE(e.matched);
48   EXPECT_TRUE(e.errored);
49   EXPECT_EQ(e.value, nullptr);
50   EXPECT_TRUE(p->has_error());
51   EXPECT_EQ(p->error(), "1:5: expected '{'");
52 }
53 
54 }  // namespace
55 }  // namespace wgsl
56 }  // namespace reader
57 }  // namespace tint
58