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