1
0

feat: add trim in string op opposited with strip

This commit is contained in:
2025-10-01 20:53:43 +08:00
parent 05a80268ab
commit 446f880df4
5 changed files with 153 additions and 7 deletions

View File

@ -86,6 +86,12 @@ namespace yycctest::string::op {
EXPECT_EQ(rv, u8" \taaa");
}
// Full strip
{
auto rv = OP::strip(u8" ", u8" ");
EXPECT_TRUE(rv.empty());
}
// Special strip
{
auto rv = OP::strip(u8"啊啊啊aaaあああ", u8"啊あ");
@ -110,6 +116,32 @@ namespace yycctest::string::op {
}
}
TEST(StringOp, Trim) {
// Normal trim
{
auto rv = OP::trim(u8" \taaa\n", u8" \t\r\n");
EXPECT_EQ(rv, u8"aaa");
}
{
auto rv = OP::ltrim(u8" \taaa\n", u8" \t\r\n");
EXPECT_EQ(rv, u8"aaa\n");
}
{
auto rv = OP::rtrim(u8" \taaa\n", u8" \t\r\n");
EXPECT_EQ(rv, u8" \taaa");
}
// Bad words
{
EXPECT_ANY_THROW(OP::trim(u8"q啊啊啊aaaあああp", u8"p啊q"));
}
// Full trim
{
auto rv = OP::trim(u8" ", u8" ");
EXPECT_TRUE(rv.empty());
}
}
TEST(StringOp, Split) {
// Normal
{