1//===- unittest/Support/RemarksStrTabParsingTest.cpp - StrTab 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//===----------------------------------------------------------------------===//
8
9#include "llvm/Remarks/Remark.h"
10#include "llvm/Remarks/RemarkParser.h"
11#include "gtest/gtest.h"
12
13using namespace llvm;
14
15TEST(RemarksStrTab, ParsingEmpty) {
16 StringRef Empty("", 0);
17 remarks::ParsedStringTable StrTab(Empty);
18 Expected<StringRef> Nothing = StrTab[0];
19 EXPECT_FALSE(static_cast<bool>(Nothing));
20 EXPECT_EQ(toString(Nothing.takeError()),
21 "String with index 0 is out of bounds (size = 0).");
22}
23
24TEST(RemarksStrTab, ParsingGood) {
25 StringRef Strings("str1\0str2\0str3\0str4", 20);
26 remarks::ParsedStringTable StrTab(Strings);
27 Expected<StringRef> Result = StrTab[0];
28 EXPECT_TRUE(static_cast<bool>(Result));
29 EXPECT_EQ(*Result, "str1");
30 Result = StrTab[1];
31 EXPECT_TRUE(static_cast<bool>(Result));
32 EXPECT_EQ(*Result, "str2");
33 Result = StrTab[2];
34 EXPECT_TRUE(static_cast<bool>(Result));
35 EXPECT_EQ(*Result, "str3");
36 Result = StrTab[3];
37 EXPECT_TRUE(static_cast<bool>(Result));
38 EXPECT_EQ(*Result, "str4");
39}
40

source code of llvm/unittests/Remarks/RemarksStrTabParsingTest.cpp