1 //===- llvm/unittest/ADT/StringTableTest.cpp - StringTable tests ----------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringTable.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
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