• 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 "gtest/gtest-spi.h"
16 #include "src/ast/discard_statement.h"
17 #include "src/ast/if_statement.h"
18 #include "src/ast/test_helper.h"
19 
20 namespace tint {
21 namespace ast {
22 namespace {
23 
24 using BlockStatementTest = TestHelper;
25 
TEST_F(BlockStatementTest,Creation)26 TEST_F(BlockStatementTest, Creation) {
27   auto* d = create<DiscardStatement>();
28   auto* ptr = d;
29 
30   auto* b = create<BlockStatement>(StatementList{d});
31 
32   ASSERT_EQ(b->statements.size(), 1u);
33   EXPECT_EQ(b->statements[0], ptr);
34 }
35 
TEST_F(BlockStatementTest,Creation_WithSource)36 TEST_F(BlockStatementTest, Creation_WithSource) {
37   auto* b = create<BlockStatement>(Source{Source::Location{20, 2}},
38                                    ast::StatementList{});
39   auto src = b->source;
40   EXPECT_EQ(src.range.begin.line, 20u);
41   EXPECT_EQ(src.range.begin.column, 2u);
42 }
43 
TEST_F(BlockStatementTest,IsBlock)44 TEST_F(BlockStatementTest, IsBlock) {
45   auto* b = create<BlockStatement>(ast::StatementList{});
46   EXPECT_TRUE(b->Is<BlockStatement>());
47 }
48 
TEST_F(BlockStatementTest,Assert_Null_Statement)49 TEST_F(BlockStatementTest, Assert_Null_Statement) {
50   EXPECT_FATAL_FAILURE(
51       {
52         ProgramBuilder b;
53         b.create<BlockStatement>(ast::StatementList{nullptr});
54       },
55       "internal compiler error");
56 }
57 
TEST_F(BlockStatementTest,Assert_DifferentProgramID_Statement)58 TEST_F(BlockStatementTest, Assert_DifferentProgramID_Statement) {
59   EXPECT_FATAL_FAILURE(
60       {
61         ProgramBuilder b1;
62         ProgramBuilder b2;
63         b1.create<BlockStatement>(
64             ast::StatementList{b2.create<DiscardStatement>()});
65       },
66       "internal compiler error");
67 }
68 
69 }  // namespace
70 }  // namespace ast
71 }  // namespace tint
72