Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 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/tint/symbol_table.h" |
| 16 | |
| 17 | #include "gtest/gtest-spi.h" |
| 18 | |
| 19 | namespace tint { |
| 20 | namespace { |
| 21 | |
| 22 | using SymbolTableTest = testing::Test; |
| 23 | |
| 24 | TEST_F(SymbolTableTest, GeneratesSymbolForName) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 25 | auto program_id = ProgramID::New(); |
| 26 | SymbolTable s{program_id}; |
dan sinclair | b353ebe | 2023-04-18 19:31:21 +0000 | [diff] [blame] | 27 | EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name")); |
| 28 | EXPECT_EQ(Symbol(2, program_id, "another_name"), s.Register("another_name")); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | TEST_F(SymbolTableTest, DeduplicatesNames) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 32 | auto program_id = ProgramID::New(); |
| 33 | SymbolTable s{program_id}; |
dan sinclair | b353ebe | 2023-04-18 19:31:21 +0000 | [diff] [blame] | 34 | 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 Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 39 | TEST_F(SymbolTableTest, AssertsForBlankString) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 40 | EXPECT_FATAL_FAILURE( |
| 41 | { |
| 42 | auto program_id = ProgramID::New(); |
| 43 | SymbolTable s{program_id}; |
| 44 | s.Register(""); |
| 45 | }, |
| 46 | "internal compiler error"); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } // namespace |
| 50 | } // namespace tint |