Skip to content

Commit 2532802

Browse files
committed
Add test cases for string divider
1 parent c75f5c0 commit 2532802

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

test/test.cc

+72
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,76 @@ TEST(TrimTests, TrimStringTests) {
116116
EXPECT_TRUE(detail::trim_copy("").empty());
117117
}
118118

119+
TEST(DivideTest, DivideStringTests) {
120+
auto divide = [](const std::string &str, char d) {
121+
std::string lhs;
122+
std::string rhs;
123+
124+
detail::divide(str, d,
125+
[&](const char *lhs_data, std::size_t lhs_size,
126+
const char *rhs_data, std::size_t rhs_size) {
127+
lhs.assign(lhs_data, lhs_size);
128+
rhs.assign(rhs_data, rhs_size);
129+
});
130+
131+
return std::make_pair(std::move(lhs), std::move(rhs));
132+
};
133+
134+
{
135+
const auto res = divide("", '=');
136+
EXPECT_EQ(res.first, "");
137+
EXPECT_EQ(res.second, "");
138+
}
139+
140+
{
141+
const auto res = divide("=", '=');
142+
EXPECT_EQ(res.first, "");
143+
EXPECT_EQ(res.second, "");
144+
}
145+
146+
{
147+
const auto res = divide(" ", '=');
148+
EXPECT_EQ(res.first, " ");
149+
EXPECT_EQ(res.second, "");
150+
}
151+
152+
{
153+
const auto res = divide("a", '=');
154+
EXPECT_EQ(res.first, "a");
155+
EXPECT_EQ(res.second, "");
156+
}
157+
158+
{
159+
const auto res = divide("a=", '=');
160+
EXPECT_EQ(res.first, "a");
161+
EXPECT_EQ(res.second, "");
162+
}
163+
164+
{
165+
const auto res = divide("=b", '=');
166+
EXPECT_EQ(res.first, "");
167+
EXPECT_EQ(res.second, "b");
168+
}
169+
170+
{
171+
const auto res = divide("a=b", '=');
172+
EXPECT_EQ(res.first, "a");
173+
EXPECT_EQ(res.second, "b");
174+
}
175+
176+
{
177+
const auto res = divide("a=b=", '=');
178+
EXPECT_EQ(res.first, "a");
179+
EXPECT_EQ(res.second, "b=");
180+
}
181+
182+
{
183+
const auto res = divide("a=b=c", '=');
184+
EXPECT_EQ(res.first, "a");
185+
EXPECT_EQ(res.second, "b=c");
186+
}
187+
}
188+
119189
TEST(SplitTest, ParseQueryString) {
120190
string s = "key1=val1&key2=val2&key3=val3";
121191
Params dic;
@@ -170,7 +240,9 @@ TEST(ParseQueryTest, ParseQueryString) {
170240
{
171241
std::string s = "key1&key2=val1&key3=val1=val2&key4=val1=val2=val3";
172242
Params dic;
243+
173244
detail::parse_query_text(s, dic);
245+
174246
EXPECT_EQ("", dic.find("key1")->second);
175247
EXPECT_EQ("val1", dic.find("key2")->second);
176248
EXPECT_EQ("val1=val2", dic.find("key3")->second);

0 commit comments

Comments
 (0)