• 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/test_helper.h"
17 
18 namespace tint {
19 namespace ast {
20 namespace {
21 
22 using MemberAccessorExpressionTest = TestHelper;
23 
TEST_F(MemberAccessorExpressionTest,Creation)24 TEST_F(MemberAccessorExpressionTest, Creation) {
25   auto* str = Expr("structure");
26   auto* mem = Expr("member");
27 
28   auto* stmt = create<MemberAccessorExpression>(str, mem);
29   EXPECT_EQ(stmt->structure, str);
30   EXPECT_EQ(stmt->member, mem);
31 }
32 
TEST_F(MemberAccessorExpressionTest,Creation_WithSource)33 TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
34   auto* stmt = create<MemberAccessorExpression>(
35       Source{Source::Location{20, 2}}, Expr("structure"), Expr("member"));
36   auto src = stmt->source;
37   EXPECT_EQ(src.range.begin.line, 20u);
38   EXPECT_EQ(src.range.begin.column, 2u);
39 }
40 
TEST_F(MemberAccessorExpressionTest,IsMemberAccessor)41 TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
42   auto* stmt =
43       create<MemberAccessorExpression>(Expr("structure"), Expr("member"));
44   EXPECT_TRUE(stmt->Is<MemberAccessorExpression>());
45 }
46 
TEST_F(MemberAccessorExpressionTest,Assert_Null_Struct)47 TEST_F(MemberAccessorExpressionTest, Assert_Null_Struct) {
48   EXPECT_FATAL_FAILURE(
49       {
50         ProgramBuilder b;
51         b.create<MemberAccessorExpression>(nullptr, b.Expr("member"));
52       },
53       "internal compiler error");
54 }
55 
TEST_F(MemberAccessorExpressionTest,Assert_Null_Member)56 TEST_F(MemberAccessorExpressionTest, Assert_Null_Member) {
57   EXPECT_FATAL_FAILURE(
58       {
59         ProgramBuilder b;
60         b.create<MemberAccessorExpression>(b.Expr("struct"), nullptr);
61       },
62       "internal compiler error");
63 }
64 
TEST_F(MemberAccessorExpressionTest,Assert_DifferentProgramID_Struct)65 TEST_F(MemberAccessorExpressionTest, Assert_DifferentProgramID_Struct) {
66   EXPECT_FATAL_FAILURE(
67       {
68         ProgramBuilder b1;
69         ProgramBuilder b2;
70         b1.create<MemberAccessorExpression>(b2.Expr("structure"),
71                                             b1.Expr("member"));
72       },
73       "internal compiler error");
74 }
75 
TEST_F(MemberAccessorExpressionTest,Assert_DifferentProgramID_Member)76 TEST_F(MemberAccessorExpressionTest, Assert_DifferentProgramID_Member) {
77   EXPECT_FATAL_FAILURE(
78       {
79         ProgramBuilder b1;
80         ProgramBuilder b2;
81         b1.create<MemberAccessorExpression>(b1.Expr("structure"),
82                                             b2.Expr("member"));
83       },
84       "internal compiler error");
85 }
86 
87 }  // namespace
88 }  // namespace ast
89 }  // namespace tint
90