[llvm] 7a19194 - [NFC][ADT] Add unit test for llvm::mismatch. (#105459)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 04:25:29 PDT 2024


Author: Rahul Joshi
Date: 2024-08-21T04:25:26-07:00
New Revision: 7a19194d0ac0110e5dae43538423293b67a27466

URL: https://github.com/llvm/llvm-project/commit/7a19194d0ac0110e5dae43538423293b67a27466
DIFF: https://github.com/llvm/llvm-project/commit/7a19194d0ac0110e5dae43538423293b67a27466.diff

LOG: [NFC][ADT] Add unit test for llvm::mismatch. (#105459)

- Add basic unit test for llvm::mismatch.

Added: 
    

Modified: 
    llvm/unittests/ADT/STLExtrasTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 3927bc59c031a3..b7dc15bf60af51 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1349,6 +1349,33 @@ TEST(STLExtrasTest, LessSecond) {
   }
 }
 
+TEST(STLExtrasTest, Mismatch) {
+  {
+    const int MMIndex = 5;
+    StringRef First = "FooBar";
+    StringRef Second = "FooBaz";
+    auto [MMFirst, MMSecond] = mismatch(First, Second);
+    EXPECT_EQ(MMFirst, First.begin() + MMIndex);
+    EXPECT_EQ(MMSecond, Second.begin() + MMIndex);
+  }
+
+  {
+    SmallVector<int> First = {0, 1, 2};
+    SmallVector<int> Second = {0, 1, 2, 3};
+    auto [MMFirst, MMSecond] = mismatch(First, Second);
+    EXPECT_EQ(MMFirst, First.end());
+    EXPECT_EQ(MMSecond, Second.begin() + 3);
+  }
+
+  {
+    SmallVector<int> First = {0, 1};
+    SmallVector<int> Empty;
+    auto [MMFirst, MMEmpty] = mismatch(First, Empty);
+    EXPECT_EQ(MMFirst, First.begin());
+    EXPECT_EQ(MMEmpty, Empty.begin());
+  }
+}
+
 struct Foo;
 struct Bar {};
 


        


More information about the llvm-commits mailing list