| 33 | |
| 34 | namespace { |
| 35 | TEST(SymbolTableTest, SymbolTableAccess) { |
| 36 | SymbolTable table; |
| 37 | |
| 38 | const SymbolId foo_id = table.registerSymbol("foo"); |
| 39 | EXPECT_NE(foo_id, BadSymbolId); |
| 40 | |
| 41 | const SymbolId bar_id = table.registerSymbol("bar"); |
| 42 | EXPECT_NE(foo_id, bar_id); |
| 43 | |
| 44 | // Attempting to register the same symbol will result in original ID. |
| 45 | EXPECT_EQ(table.registerSymbol("foo"), foo_id); |
| 46 | EXPECT_EQ(table.registerSymbol("bar"), bar_id); |
| 47 | |
| 48 | // Retrieve symbol-ID by text string |
| 49 | EXPECT_EQ(table.getId("foo"), foo_id); |
| 50 | EXPECT_EQ(table.getId("bar"), bar_id); |
| 51 | EXPECT_EQ(table.getId("baz"), BadSymbolId); // no-exist |
| 52 | |
| 53 | // Retrieve text symbol by ID |
| 54 | EXPECT_EQ(table.getSymbol(foo_id), "foo"); |
| 55 | EXPECT_EQ(table.getSymbol(bar_id), "bar"); |
| 56 | EXPECT_EQ(table.getSymbol(SymbolId(42, BadRawSymbol)), |
| 57 | SymbolTable::getBadSymbol()); // no-exist |
| 58 | |
| 59 | // For now, symbols returned in getSymbols() always contain bad symbol as |
| 60 | // first element (though this is an implementation detail and might change). |
| 61 | EXPECT_THAT(table.getSymbols(), |
| 62 | ElementsAre(SymbolTable::getBadSymbol(), "foo", "bar")); |
| 63 | } |
| 64 | |
| 65 | TEST(SymbolTableTest, SymbolStringsAreStable) { |
| 66 | SymbolTable table; |
nothing calls this directly
no test coverage detected