blob: ebdb6d892751891717dd6850e39f0ad85202bf85 [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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/tint/symbol_table.h"
16
17#include "gtest/gtest-spi.h"
18
19namespace tint {
20namespace {
21
22using SymbolTableTest = testing::Test;
23
24TEST_F(SymbolTableTest, GeneratesSymbolForName) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000025 auto program_id = ProgramID::New();
26 SymbolTable s{program_id};
dan sinclairb353ebe2023-04-18 19:31:21 +000027 EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name"));
28 EXPECT_EQ(Symbol(2, program_id, "another_name"), s.Register("another_name"));
Ryan Harrisondbc13af2022-02-21 15:19:07 +000029}
30
31TEST_F(SymbolTableTest, DeduplicatesNames) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000032 auto program_id = ProgramID::New();
33 SymbolTable s{program_id};
dan sinclairb353ebe2023-04-18 19:31:21 +000034 EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name"));
35 EXPECT_EQ(Symbol(2, program_id, "another_name"), s.Register("another_name"));
36 EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name"));
Ryan Harrisondbc13af2022-02-21 15:19:07 +000037}
38
Ryan Harrisondbc13af2022-02-21 15:19:07 +000039TEST_F(SymbolTableTest, AssertsForBlankString) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000040 EXPECT_FATAL_FAILURE(
41 {
42 auto program_id = ProgramID::New();
43 SymbolTable s{program_id};
44 s.Register("");
45 },
46 "internal compiler error");
Ryan Harrisondbc13af2022-02-21 15:19:07 +000047}
48
49} // namespace
50} // namespace tint