blob: af224a8cd4fbe1ed583728f332c9f2b3e39fee21 [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}
George Liuecf1a312025-08-25 10:43:12 +080056
57TEST(SplitTest, NormalSplit)
58{
59 auto result = split("a,b,c", ',');
60 std::vector<std::string> expected = {"a", "b", "c"};
61 EXPECT_EQ(result, expected);
62}
63
64TEST(SplitTest, ConsecutiveDelimiters)
65{
66 auto result = split("a,,b", ',');
67 std::vector<std::string> expected = {"a", "", "b"};
68 EXPECT_EQ(result, expected);
69}
70
71TEST(SplitTest, LeadingDelimiter)
72{
73 auto result = split(",a,b", ',');
74 std::vector<std::string> expected = {"", "a", "b"};
75 EXPECT_EQ(result, expected);
76}
77
78TEST(SplitTest, TrailingDelimiter)
79{
80 auto result = split("a,b,", ',');
81 std::vector<std::string> expected = {"a", "b", ""};
82 EXPECT_EQ(result, expected);
83}
84
85TEST(SplitTest, NoDelimiter)
86{
87 auto result = split("abc", ',');
88 std::vector<std::string> expected = {"abc"};
89 EXPECT_EQ(result, expected);
90}
91
92TEST(SplitTest, EmptyString)
93{
94 auto result = split("", ',');
95 std::vector<std::string> expected = {""};
96 EXPECT_EQ(result, expected);
97}