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/sem/struct.h"
16 #include "src/sem/test_helper.h"
17 #include "src/sem/texture_type.h"
18
19 namespace tint {
20 namespace sem {
21 namespace {
22
23 using StructTest = TestHelper;
24
TEST_F(StructTest,Creation)25 TEST_F(StructTest, Creation) {
26 auto name = Sym("S");
27 auto* impl =
28 create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
29 auto* ptr = impl;
30 auto* s =
31 create<sem::Struct>(impl, impl->name, StructMemberList{}, 4 /* align */,
32 8 /* size */, 16 /* size_no_padding */);
33 EXPECT_EQ(s->Declaration(), ptr);
34 EXPECT_EQ(s->Align(), 4u);
35 EXPECT_EQ(s->Size(), 8u);
36 EXPECT_EQ(s->SizeNoPadding(), 16u);
37 }
38
TEST_F(StructTest,TypeName)39 TEST_F(StructTest, TypeName) {
40 auto name = Sym("my_struct");
41 auto* impl =
42 create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
43 auto* s =
44 create<sem::Struct>(impl, impl->name, StructMemberList{}, 4 /* align */,
45 4 /* size */, 4 /* size_no_padding */);
46 EXPECT_EQ(s->type_name(), "__struct_$1");
47 }
48
TEST_F(StructTest,FriendlyName)49 TEST_F(StructTest, FriendlyName) {
50 auto name = Sym("my_struct");
51 auto* impl =
52 create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
53 auto* s =
54 create<sem::Struct>(impl, impl->name, StructMemberList{}, 4 /* align */,
55 4 /* size */, 4 /* size_no_padding */);
56 EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
57 }
58
59 } // namespace
60 } // namespace sem
61 } // namespace tint
62