aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
authorRahul Joshi <rjoshi@nvidia.com>2024-08-22 14:44:35 -0700
committerGitHub <noreply@github.com>2024-08-22 14:44:35 -0700
commit911e246fe8fd35bd82fc11db001513a1e2f6990c (patch)
tree685bbd231d621ddfeedde3b48b1f9b405358e5bc /llvm/unittests/ADT/StringRefTest.cpp
parentd7fc779aacd4b5538bc42139892812aad8c6d528 (diff)
downloadllvm-911e246fe8fd35bd82fc11db001513a1e2f6990c.zip
llvm-911e246fe8fd35bd82fc11db001513a1e2f6990c.tar.gz
llvm-911e246fe8fd35bd82fc11db001513a1e2f6990c.tar.bz2
[NFC][ADT] Add reverse iterators and `value_type` to StringRef (#105579)
- Add reverse iterators and `value_type` to StringRef. - Add unit test for all 4 iterator flavors. - This prepares StringRef to be used with `SequenceToOffsetTable`.
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) {