Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Ziy1-Tan <[email protected]>
  • Loading branch information
Ziy1-Tan committed Nov 17, 2023
1 parent 78e2343 commit 65533bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ inline void LTrim(std::string &s) {
// trim from end (in place)
inline void RTrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
[](const char &c) { return !std::isspace(c); })
[](const char &ch) { return !std::isspace(ch); })
.base(),
s.end());
}
Expand Down
28 changes: 18 additions & 10 deletions test/common/string_util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,44 @@ TEST(Common, StringToUll) {
ASSERT_FALSE(StringToUll(str, &out));
}

TEST(StringUtilTest, ltrim) {
TEST(StringUtilTest, LTrim) {
std::array<std::array<std::string, 2>, 4> cases = {
std::array<std::string, 2>{"hello", "hello"},
std::array<std::string, 2>{"", ""}, std::array<std::string, 2>{" ", ""},
std::array<std::string, 2>{" hello", "hello"}};
std::array<std::string, 2>{"hello", "hello"},
std::array<std::string, 2>{"", ""},
std::array<std::string, 2>{" ", ""},
std::array<std::string, 2>{" hello", "hello"},
};

for (auto &c : cases) {
curve::common::LTrim(c[0]);
EXPECT_EQ(c[0], c[1]);
}
}

TEST(StringUtilTest, rtrim) {
TEST(StringUtilTest, RTrim) {
std::array<std::array<std::string, 2>, 4> cases = {
std::array<std::string, 2>{"hello", "hello"},
std::array<std::string, 2>{"", ""}, std::array<std::string, 2>{" ", ""},
std::array<std::string, 2>{"hello ", "hello"}};
std::array<std::string, 2>{"hello", "hello"},
std::array<std::string, 2>{"", ""},
std::array<std::string, 2>{" ", ""},
std::array<std::string, 2>{"hello ", "hello"},
};

for (auto &c : cases) {
curve::common::RTrim(c[0]);
EXPECT_EQ(c[0], c[1]);
}
}

TEST(StringUtilTest, trim) {
std::array<std::array<std::string, 2>, 6> cases = {
TEST(StringUtilTest, Trim) {
std::array<std::array<std::string, 2>, 10> cases = {
std::array<std::string, 2>{"hello", "hello"},
std::array<std::string, 2>{" hello", "hello"},
std::array<std::string, 2>{"hello ", "hello"},
std::array<std::string, 2>{" hello ", "hello"},
std::array<std::string, 2>{"S3 Browser", "S3 Browser"},
std::array<std::string, 2>{"S3 Browser ", "S3 Browser"},
std::array<std::string, 2>{" S3 Browser", "S3 Browser"},
std::array<std::string, 2>{" S3 Browser ", "S3 Browser"},
std::array<std::string, 2>{" ", ""},
std::array<std::string, 2>{"", ""},
};
Expand Down

0 comments on commit 65533bd

Please sign in to comment.