42 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ADT/StringTable.h"10#include "gmock/gmock.h"11#include "gtest/gtest.h"12#include <cstdlib>13 14using namespace llvm;15 16namespace {17 18using ::testing::Eq;19using ::testing::StrEq;20 21TEST(StringTableTest, Basic) {22 static constexpr char InputTable[] = "\0test\0";23 constexpr StringTable T = InputTable;24 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);30 31 // And use normal Google Test runtime assertions to check the contents and32 // 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"));36 37 // Also check that this is a valid C-string.38 EXPECT_THAT(T[1].data(), StrEq("test"));39}40 41} // anonymous namespace42