• 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/pointer.h"
16 
17 #include "src/ast/i32.h"
18 #include "src/ast/test_helper.h"
19 
20 namespace tint {
21 namespace ast {
22 namespace {
23 
24 using AstPointerTest = TestHelper;
25 
TEST_F(AstPointerTest,Creation)26 TEST_F(AstPointerTest, Creation) {
27   auto* i32 = create<I32>();
28   auto* p = create<Pointer>(i32, ast::StorageClass::kStorage, Access::kRead);
29   EXPECT_EQ(p->type, i32);
30   EXPECT_EQ(p->storage_class, ast::StorageClass::kStorage);
31   EXPECT_EQ(p->access, Access::kRead);
32 }
33 
TEST_F(AstPointerTest,FriendlyName)34 TEST_F(AstPointerTest, FriendlyName) {
35   auto* i32 = create<I32>();
36   auto* p =
37       create<Pointer>(i32, ast::StorageClass::kWorkgroup, Access::kUndefined);
38   EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<workgroup, i32>");
39 }
40 
TEST_F(AstPointerTest,FriendlyNameWithAccess)41 TEST_F(AstPointerTest, FriendlyNameWithAccess) {
42   auto* i32 = create<I32>();
43   auto* p =
44       create<Pointer>(i32, ast::StorageClass::kStorage, Access::kReadWrite);
45   EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<storage, i32, read_write>");
46 }
47 
48 }  // namespace
49 }  // namespace ast
50 }  // namespace tint
51