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/writer/text_generator.h"
16
17 #include "gtest/gtest.h"
18
19 namespace tint {
20 namespace writer {
21 namespace {
22
TEST(TextGeneratorTest,UniqueIdentifier)23 TEST(TextGeneratorTest, UniqueIdentifier) {
24 Program program(ProgramBuilder{});
25
26 TextGenerator gen(&program);
27
28 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident");
29 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident_1");
30 }
31
TEST(TextGeneratorTest,UniqueIdentifier_ConflictWithExisting)32 TEST(TextGeneratorTest, UniqueIdentifier_ConflictWithExisting) {
33 ProgramBuilder builder;
34 builder.Symbols().Register("ident_1");
35 builder.Symbols().Register("ident_2");
36 Program program(std::move(builder));
37
38 TextGenerator gen(&program);
39
40 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident");
41 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident_3");
42 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident_4");
43 ASSERT_EQ(gen.UniqueIdentifier("ident"), "ident_5");
44 }
45
46 } // namespace
47 } // namespace writer
48 } // namespace tint
49