forked from jeremy-rifkin/cpptrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utils.cpp
More file actions
92 lines (76 loc) · 2.48 KB
/
string_utils.cpp
File metadata and controls
92 lines (76 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <gtest/gtest.h>
#include <gtest/gtest-matchers.h>
#include <gmock/gmock.h>
#include <gmock/gmock-matchers.h>
#include "utils/utils.hpp"
using testing::ElementsAre;
using cpptrace::detail::split;
using cpptrace::detail::join;
using cpptrace::detail::trim;
using cpptrace::detail::starts_with;
namespace {
TEST(SplitTest, SplitBySingleDelimiter) {
std::string input = "hello,world";
auto tokens = split(input, ",");
EXPECT_THAT(tokens, ElementsAre("hello", "world"));
}
TEST(SplitTest, SplitByMultipleDelimiters) {
std::string input = "hello,world;test";
auto tokens = split(input, ",;");
EXPECT_THAT(tokens, ElementsAre("hello", "world", "test"));
}
TEST(SplitTest, HandlesNoDelimiterFound) {
std::string input = "nodellimitershere";
auto tokens = split(input, ", ");
EXPECT_THAT(tokens, ElementsAre("nodellimitershere"));
}
TEST(SplitTest, HandlesEmptyString) {
std::string input = "";
auto tokens = split(input, ",");
EXPECT_THAT(tokens, ElementsAre(""));
}
TEST(SplitTest, HandlesConsecutiveDelimiters) {
std::string input = "one,,two,,,three";
auto tokens = split(input, ",");
EXPECT_THAT(tokens, ElementsAre("one", "", "two", "", "", "three"));
}
TEST(SplitTest, HandlesTrailingDelimiter) {
std::string input = "abc,";
auto tokens = split(input, ",");
EXPECT_THAT(tokens, ElementsAre("abc", ""));
}
TEST(SplitTest, HandlesLeadingDelimiter) {
std::string input = ",abc";
auto tokens = split(input, ",");
EXPECT_THAT(tokens, ElementsAre("", "abc"));
}
TEST(JoinTest, EmptyContainer) {
std::vector<std::string> vec;
EXPECT_EQ(join(vec, ","), "");
}
TEST(JoinTest, SingleElements) {
std::vector<std::string> vec = {"one"};
EXPECT_EQ(join(vec, ","), "one");
}
TEST(JoinTest, MultipleElements) {
std::vector<std::string> vec = {"one", "two", "three"};
EXPECT_EQ(join(vec, ","), "one,two,three");
}
TEST(TrimTest, Basic) {
EXPECT_EQ(trim(""), "");
EXPECT_EQ(trim("test"), "test");
EXPECT_EQ(trim(" test "), "test");
EXPECT_EQ(trim(" test\n "), "test");
EXPECT_EQ(trim("\t test\n "), "test");
}
TEST(StartsWith, Basic) {
EXPECT_TRUE(starts_with("", ""));
EXPECT_TRUE(starts_with("abc", ""));
EXPECT_FALSE(starts_with("", "abc"));
EXPECT_FALSE(starts_with("ab", "abc"));
EXPECT_TRUE(starts_with("test", "test"));
EXPECT_TRUE(starts_with("hello_world", "hello"));
EXPECT_FALSE(starts_with("hello_world", "world"));
EXPECT_FALSE(starts_with("abcd", "abce"));
}
}