diff options
author | Luke Lau <luke@igalia.com> | 2024-01-11 01:22:41 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 01:22:41 +0700 |
commit | 1c209322e462c1d1675cc4b9947712dcceac93b5 (patch) | |
tree | d733a984b7e3ff85434e8062b3d0449652769110 /llvm/unittests/ADT/StringRefTest.cpp | |
parent | cd7eaaa6db0dc9a00a097ba8e6ebad6fb2dec56a (diff) | |
download | llvm-1c209322e462c1d1675cc4b9947712dcceac93b5.zip llvm-1c209322e462c1d1675cc4b9947712dcceac93b5.tar.gz llvm-1c209322e462c1d1675cc4b9947712dcceac93b5.tar.bz2 |
[ADT] Make StringRef std::string_view conversion operator constexpr. NFC (#77506)
This would allow us to compare StringRefs via std::string_view, avoiding
having
to make the existing StringRef compare machinery constexpr for now.
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringRefTest.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index a208527..8df71e8 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -59,6 +59,7 @@ TEST(StringRefTest, Construction) { TEST(StringRefTest, Conversion) { EXPECT_EQ("hello", std::string(StringRef("hello"))); EXPECT_EQ("hello", std::string_view(StringRef("hello"))); + static_assert(std::string_view(StringRef("hello")) == "hello"); } TEST(StringRefTest, EmptyInitializerList) { @@ -78,9 +79,22 @@ TEST(StringRefTest, Iteration) { TEST(StringRefTest, StringOps) { const char *p = "hello"; + EXPECT_EQ(p, StringRef(p, 0).data()); + static_assert(StringRef("hello").data()[0] == 'h'); + static_assert(StringRef("hello").data()[1] == 'e'); + static_assert(StringRef("hello").data()[2] == 'l'); + static_assert(StringRef("hello").data()[3] == 'l'); + static_assert(StringRef("hello").data()[4] == 'o'); + static_assert(StringRef("hello").data()[5] == '\0'); + EXPECT_TRUE(StringRef().empty()); + static_assert(StringRef("").empty()); + static_assert(!StringRef("hello").empty()); + EXPECT_EQ((size_t) 5, StringRef("hello").size()); + static_assert(StringRef("hello").size() == 5); + EXPECT_GT( 0, StringRef("aab").compare("aad")); EXPECT_EQ( 0, StringRef("aab").compare("aab")); EXPECT_LT( 0, StringRef("aab").compare("aaa")); |