[gcov] Bump default version to 11.1
[llvm-project.git] / llvm / unittests / ADT / StringTableTest.cpp
blob0fc4ba7b50b804e82bcd6a252ab35ee0a1ef2ed5
1 //===- llvm/unittest/ADT/StringTableTest.cpp - StringTable tests ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringTable.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
12 #include <cstdlib>
14 using namespace llvm;
16 namespace {
18 using ::testing::Eq;
19 using ::testing::StrEq;
21 TEST(StringTableTest, Basic) {
22 static constexpr char InputTable[] = "\0test\0";
23 constexpr StringTable T = InputTable;
25 // We support some limited constexpr operations, check those first.
26 static_assert(T.size() == sizeof(InputTable));
27 static_assert(T[0].empty());
28 static_assert(T[StringTable::Offset()].empty());
29 static_assert(T[1].size() == 4);
31 // And use normal Google Test runtime assertions to check the contents and
32 // give more complete error messages.
33 EXPECT_THAT(T[0], Eq(""));
34 EXPECT_THAT(T[StringTable::Offset()], Eq(""));
35 EXPECT_THAT(T[1], Eq("test"));
37 // Also check that this is a valid C-string.
38 EXPECT_THAT(T[1].data(), StrEq("test"));
41 } // anonymous namespace