blob: 7c67e9b4fb87bf89ba31e78733a0846370be83d2 [file] [log] [blame]
George Liuce8d1d02025-08-25 08:58:25 +08001#include "utils.hpp"
2
3#include <gtest/gtest.h>
4
Ed Tanousc5a2af92025-08-25 08:58:25 +08005constexpr std::string_view helloWorld = "Hello World";
6
George Liuce8d1d02025-08-25 08:58:25 +08007TEST(IfindFirstTest, BasicMatch)
8{
Ed Tanousc5a2af92025-08-25 08:58:25 +08009 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 Liuce8d1d02025-08-25 08:58:25 +080013}
14
15TEST(IfindFirstTest, CaseInsensitiveMatch)
16{
Ed Tanousc5a2af92025-08-25 08:58:25 +080017 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 Liuce8d1d02025-08-25 08:58:25 +080021}
22
23TEST(IfindFirstTest, NoMatch)
24{
Ed Tanousc5a2af92025-08-25 08:58:25 +080025 auto match = iFindFirst(helloWorld, "Planet");
26 EXPECT_FALSE(match);
George Liuce8d1d02025-08-25 08:58:25 +080027}
28
29TEST(IfindFirstTest, MatchAtStart)
30{
Ed Tanousc5a2af92025-08-25 08:58:25 +080031 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 Liuce8d1d02025-08-25 08:58:25 +080035}
36
37TEST(IfindFirstTest, MatchAtEnd)
38{
Ed Tanousc5a2af92025-08-25 08:58:25 +080039 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 Liuce8d1d02025-08-25 08:58:25 +080043}
44
45TEST(IfindFirstTest, EmptySubstring)
46{
Ed Tanousc5a2af92025-08-25 08:58:25 +080047 auto match = iFindFirst(helloWorld, "");
48 EXPECT_FALSE(match);
George Liuce8d1d02025-08-25 08:58:25 +080049}
50
51TEST(IfindFirstTest, EmptyString)
52{
Ed Tanousc5a2af92025-08-25 08:58:25 +080053 auto match = iFindFirst("", "Hello");
54 EXPECT_FALSE(match);
George Liuce8d1d02025-08-25 08:58:25 +080055}