2020-03-02 20:47:43 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-02-21 15:19:07 +00:00
|
|
|
#include "src/tint/sem/struct.h"
|
|
|
|
#include "src/tint/sem/test_helper.h"
|
2022-12-08 14:14:10 +00:00
|
|
|
#include "src/tint/type/texture.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2022-04-07 16:04:35 +00:00
|
|
|
namespace tint::sem {
|
2020-03-26 15:31:43 +00:00
|
|
|
namespace {
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2022-09-07 22:25:24 +00:00
|
|
|
using namespace tint::number_suffixes; // NOLINT
|
2022-12-08 22:21:24 +00:00
|
|
|
using SemStructTest = TestHelper;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2022-12-08 22:21:24 +00:00
|
|
|
TEST_F(SemStructTest, Creation) {
|
2022-05-01 14:40:55 +00:00
|
|
|
auto name = Sym("S");
|
2022-08-02 17:03:35 +00:00
|
|
|
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
2022-05-01 14:40:55 +00:00
|
|
|
auto* ptr = impl;
|
2022-12-06 20:01:54 +00:00
|
|
|
auto* s = create<sem::Struct>(impl, impl->source, impl->name, utils::Empty, 4u /* align */,
|
|
|
|
8u /* size */, 16u /* size_no_padding */);
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_EQ(s->Declaration(), ptr);
|
|
|
|
EXPECT_EQ(s->Align(), 4u);
|
|
|
|
EXPECT_EQ(s->Size(), 8u);
|
|
|
|
EXPECT_EQ(s->SizeNoPadding(), 16u);
|
2020-03-02 20:47:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 22:21:24 +00:00
|
|
|
TEST_F(SemStructTest, Equals) {
|
2022-08-02 17:03:35 +00:00
|
|
|
auto* a_impl = create<ast::Struct>(Sym("a"), utils::Empty, utils::Empty);
|
2022-12-06 20:01:54 +00:00
|
|
|
auto* a = create<sem::Struct>(a_impl, a_impl->source, a_impl->name, utils::Empty,
|
2022-12-01 16:25:25 +00:00
|
|
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
2022-08-02 17:03:35 +00:00
|
|
|
auto* b_impl = create<ast::Struct>(Sym("b"), utils::Empty, utils::Empty);
|
2022-12-06 20:01:54 +00:00
|
|
|
auto* b = create<sem::Struct>(b_impl, b_impl->source, b_impl->name, utils::Empty,
|
2022-12-01 16:25:25 +00:00
|
|
|
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
|
2022-05-01 14:40:55 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(a->Equals(*a));
|
|
|
|
EXPECT_FALSE(a->Equals(*b));
|
2022-12-08 16:39:59 +00:00
|
|
|
EXPECT_FALSE(a->Equals(type::Void{}));
|
2020-03-02 20:47:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 22:21:24 +00:00
|
|
|
TEST_F(SemStructTest, FriendlyName) {
|
2022-05-01 14:40:55 +00:00
|
|
|
auto name = Sym("my_struct");
|
2022-08-02 17:03:35 +00:00
|
|
|
auto* impl = create<ast::Struct>(name, utils::Empty, utils::Empty);
|
2022-12-06 20:01:54 +00:00
|
|
|
auto* s = create<sem::Struct>(impl, impl->source, impl->name, utils::Empty, 4u /* align */,
|
|
|
|
4u /* size */, 4u /* size_no_padding */);
|
2022-05-01 14:40:55 +00:00
|
|
|
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
|
2021-02-09 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 15:31:43 +00:00
|
|
|
} // namespace
|
2022-04-07 16:04:35 +00:00
|
|
|
} // namespace tint::sem
|