1 // Copyright 2021 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/transform/add_empty_entry_point.h"
16
17 #include <utility>
18
19 #include "src/transform/test_helper.h"
20
21 namespace tint {
22 namespace transform {
23 namespace {
24
25 using AddEmptyEntryPointTest = TransformTest;
26
TEST_F(AddEmptyEntryPointTest,EmptyModule)27 TEST_F(AddEmptyEntryPointTest, EmptyModule) {
28 auto* src = R"()";
29
30 auto* expect = R"(
31 [[stage(compute), workgroup_size(1)]]
32 fn unused_entry_point() {
33 }
34 )";
35
36 auto got = Run<AddEmptyEntryPoint>(src);
37
38 EXPECT_EQ(expect, str(got));
39 }
40
TEST_F(AddEmptyEntryPointTest,ExistingEntryPoint)41 TEST_F(AddEmptyEntryPointTest, ExistingEntryPoint) {
42 auto* src = R"(
43 [[stage(fragment)]]
44 fn main() {
45 }
46 )";
47
48 auto* expect = src;
49
50 auto got = Run<AddEmptyEntryPoint>(src);
51
52 EXPECT_EQ(expect, str(got));
53 }
54
TEST_F(AddEmptyEntryPointTest,NameClash)55 TEST_F(AddEmptyEntryPointTest, NameClash) {
56 auto* src = R"(var<private> unused_entry_point : f32;)";
57
58 auto* expect = R"(
59 [[stage(compute), workgroup_size(1)]]
60 fn unused_entry_point_1() {
61 }
62
63 var<private> unused_entry_point : f32;
64 )";
65
66 auto got = Run<AddEmptyEntryPoint>(src);
67
68 EXPECT_EQ(expect, str(got));
69 }
70
71 } // namespace
72 } // namespace transform
73 } // namespace tint
74