| 1 |
//===- llvm/unittest/StringViewTest.cpp - StringView unit 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/Demangle/StringView.h" |
| 10 |
#include "gtest/gtest.h" |
| 11 |
|
| 12 |
using namespace llvm; |
| 13 |
using llvm::itanium_demangle::StringView; |
| 14 |
|
| 15 |
namespace llvm { |
| 16 |
namespace itanium_demangle { |
| 17 |
|
| 18 |
std::ostream &operator<<(std::ostream &OS, const StringView &S) { |
| 19 |
return OS.write(S.begin(), S.size()); |
| 20 |
} |
| 21 |
|
| 22 |
} // namespace itanium_demangle |
| 23 |
} // namespace llvm |
| 24 |
|
| 25 |
TEST(StringViewTest, EmptyInitializerList) { |
| 26 |
StringView S = {}; |
| 27 |
EXPECT_TRUE(S.empty()); |
| 28 |
|
| 29 |
S = {}; |
| 30 |
EXPECT_TRUE(S.empty()); |
| 31 |
} |
| 32 |
|
| 33 |
TEST(StringViewTest, Substr) { |
| 34 |
StringView S("abcdef"); |
| 35 |
|
| 36 |
EXPECT_EQ("abcdef", S.substr(0)); |
| 37 |
EXPECT_EQ("f", S.substr(5)); |
| 38 |
EXPECT_EQ("", S.substr(6)); |
| 39 |
|
| 40 |
EXPECT_EQ("", S.substr(0, 0)); |
| 41 |
EXPECT_EQ("a", S.substr(0, 1)); |
| 42 |
EXPECT_EQ("abcde", S.substr(0, 5)); |
| 43 |
EXPECT_EQ("abcdef", S.substr(0, 6)); |
| 44 |
EXPECT_EQ("abcdef", S.substr(0, 7)); |
| 45 |
|
| 46 |
EXPECT_EQ("f", S.substr(5, 100)); |
| 47 |
EXPECT_EQ("", S.substr(6, 100)); |
| 48 |
} |