| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 1 | #include "utils.hpp" | 
|  | 2 |  | 
|  | 3 | #include <gtest/gtest.h> | 
|  | 4 |  | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 5 | constexpr std::string_view helloWorld = "Hello World"; | 
|  | 6 |  | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 7 | TEST(IfindFirstTest, BasicMatch) | 
|  | 8 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 9 | auto match = iFindFirst(helloWorld, "World"); | 
|  | 10 | EXPECT_TRUE(match); | 
|  | 11 | EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 6); | 
|  | 12 | EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 13 | } | 
|  | 14 |  | 
|  | 15 | TEST(IfindFirstTest, CaseInsensitiveMatch) | 
|  | 16 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 17 | auto match = iFindFirst(helloWorld, "world"); | 
|  | 18 | EXPECT_TRUE(match); | 
|  | 19 | EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 6); | 
|  | 20 | EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 21 | } | 
|  | 22 |  | 
|  | 23 | TEST(IfindFirstTest, NoMatch) | 
|  | 24 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 25 | auto match = iFindFirst(helloWorld, "Planet"); | 
|  | 26 | EXPECT_FALSE(match); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
|  | 29 | TEST(IfindFirstTest, MatchAtStart) | 
|  | 30 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 31 | auto match = iFindFirst(helloWorld, "HeLLo"); | 
|  | 32 | EXPECT_TRUE(match); | 
|  | 33 | EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 0); | 
|  | 34 | EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 5); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
|  | 37 | TEST(IfindFirstTest, MatchAtEnd) | 
|  | 38 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 39 | auto match = iFindFirst(helloWorld, "LD"); | 
|  | 40 | EXPECT_TRUE(match); | 
|  | 41 | EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 9); | 
|  | 42 | EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
|  | 45 | TEST(IfindFirstTest, EmptySubstring) | 
|  | 46 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 47 | auto match = iFindFirst(helloWorld, ""); | 
|  | 48 | EXPECT_FALSE(match); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
|  | 51 | TEST(IfindFirstTest, EmptyString) | 
|  | 52 | { | 
| Ed Tanous | c5a2af9 | 2025-08-25 08:58:25 +0800 | [diff] [blame^] | 53 | auto match = iFindFirst("", "Hello"); | 
|  | 54 | EXPECT_FALSE(match); | 
| George Liu | ce8d1d0 | 2025-08-25 08:58:25 +0800 | [diff] [blame] | 55 | } |