From 65533bde86181352a210b401ed79d7894bf11735 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Fri, 17 Nov 2023 11:58:43 +0800 Subject: [PATCH] add more test cases Signed-off-by: Ziy1-Tan --- src/common/string_util.h | 2 +- test/common/string_util_test.cpp | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/common/string_util.h b/src/common/string_util.h index 0209b8af94..7f568207f9 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -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()); } diff --git a/test/common/string_util_test.cpp b/test/common/string_util_test.cpp index 40239f7291..d72d6493f1 100644 --- a/test/common/string_util_test.cpp +++ b/test/common/string_util_test.cpp @@ -60,11 +60,13 @@ TEST(Common, StringToUll) { ASSERT_FALSE(StringToUll(str, &out)); } -TEST(StringUtilTest, ltrim) { +TEST(StringUtilTest, LTrim) { std::array, 4> cases = { - std::array{"hello", "hello"}, - std::array{"", ""}, std::array{" ", ""}, - std::array{" hello", "hello"}}; + std::array{"hello", "hello"}, + std::array{"", ""}, + std::array{" ", ""}, + std::array{" hello", "hello"}, + }; for (auto &c : cases) { curve::common::LTrim(c[0]); @@ -72,11 +74,13 @@ TEST(StringUtilTest, ltrim) { } } -TEST(StringUtilTest, rtrim) { +TEST(StringUtilTest, RTrim) { std::array, 4> cases = { - std::array{"hello", "hello"}, - std::array{"", ""}, std::array{" ", ""}, - std::array{"hello ", "hello"}}; + std::array{"hello", "hello"}, + std::array{"", ""}, + std::array{" ", ""}, + std::array{"hello ", "hello"}, + }; for (auto &c : cases) { curve::common::RTrim(c[0]); @@ -84,12 +88,16 @@ TEST(StringUtilTest, rtrim) { } } -TEST(StringUtilTest, trim) { - std::array, 6> cases = { +TEST(StringUtilTest, Trim) { + std::array, 10> cases = { std::array{"hello", "hello"}, std::array{" hello", "hello"}, std::array{"hello ", "hello"}, std::array{" hello ", "hello"}, + std::array{"S3 Browser", "S3 Browser"}, + std::array{"S3 Browser ", "S3 Browser"}, + std::array{" S3 Browser", "S3 Browser"}, + std::array{" S3 Browser ", "S3 Browser"}, std::array{" ", ""}, std::array{"", ""}, };