aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index a0529b0..ec9cdc1 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -57,9 +57,17 @@ TEST(StringRefTest, EmptyInitializerList) {
TEST(StringRefTest, Iteration) {
StringRef S("hello");
- const char *p = "hello";
- for (const char *it = S.begin(), *ie = S.end(); it != ie; ++it, ++p)
- EXPECT_EQ(*it, *p);
+ constexpr StringLiteral CS("hello");
+
+ // Note: Cannot use literal strings in equal() as iteration over a literal
+ // string includes the null terminator.
+ const std::string_view RefFwd("hello");
+ const std::string_view RefRev("olleh");
+
+ EXPECT_TRUE(equal(S, RefFwd));
+ EXPECT_TRUE(equal(CS, RefFwd));
+ EXPECT_TRUE(equal(make_range(S.rbegin(), S.rend()), RefRev));
+ EXPECT_TRUE(equal(make_range(CS.rbegin(), CS.rend()), RefRev));
}
TEST(StringRefTest, StringOps) {