• 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/ast/variable_decl_statement.h"
16 
17 #include "gtest/gtest-spi.h"
18 #include "src/ast/test_helper.h"
19 
20 namespace tint {
21 namespace ast {
22 namespace {
23 
24 using VariableDeclStatementTest = TestHelper;
25 
TEST_F(VariableDeclStatementTest,Creation)26 TEST_F(VariableDeclStatementTest, Creation) {
27   auto* var = Var("a", ty.f32(), StorageClass::kNone);
28 
29   auto* stmt = create<VariableDeclStatement>(var);
30   EXPECT_EQ(stmt->variable, var);
31 }
32 
TEST_F(VariableDeclStatementTest,Creation_WithSource)33 TEST_F(VariableDeclStatementTest, Creation_WithSource) {
34   auto* var = Var("a", ty.f32(), StorageClass::kNone);
35 
36   auto* stmt =
37       create<VariableDeclStatement>(Source{Source::Location{20, 2}}, var);
38   auto src = stmt->source;
39   EXPECT_EQ(src.range.begin.line, 20u);
40   EXPECT_EQ(src.range.begin.column, 2u);
41 }
42 
TEST_F(VariableDeclStatementTest,IsVariableDecl)43 TEST_F(VariableDeclStatementTest, IsVariableDecl) {
44   auto* var = Var("a", ty.f32(), StorageClass::kNone);
45 
46   auto* stmt = create<VariableDeclStatement>(var);
47   EXPECT_TRUE(stmt->Is<VariableDeclStatement>());
48 }
49 
TEST_F(VariableDeclStatementTest,Assert_Null_Variable)50 TEST_F(VariableDeclStatementTest, Assert_Null_Variable) {
51   EXPECT_FATAL_FAILURE(
52       {
53         ProgramBuilder b;
54         b.create<VariableDeclStatement>(nullptr);
55       },
56       "internal compiler error");
57 }
58 
TEST_F(VariableDeclStatementTest,Assert_DifferentProgramID_Variable)59 TEST_F(VariableDeclStatementTest, Assert_DifferentProgramID_Variable) {
60   EXPECT_FATAL_FAILURE(
61       {
62         ProgramBuilder b1;
63         ProgramBuilder b2;
64         b1.create<VariableDeclStatement>(
65             b2.Var("a", b2.ty.f32(), StorageClass::kNone));
66       },
67       "internal compiler error");
68 }
69 
70 }  // namespace
71 }  // namespace ast
72 }  // namespace tint
73