Francis Visoiu Mistrih | 7fee2b8 | 2019-04-24 00:06:24 +0000 | [diff] [blame] | 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 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | TEST(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 | |
| 24 | TEST(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 | } |