summaryrefslogtreecommitdiff
path: root/core/fxcrt/widestring_unittest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-11-21 18:07:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-21 18:07:00 +0000
commit135c6601bd9d12bd935371d3122f8e75391de75b (patch)
tree185227ece2aa6cceb58911d2b25871dab4860251 /core/fxcrt/widestring_unittest.cpp
parentf276e78e190e04b25c3f05b35a28ecdd30bdcf21 (diff)
downloadpdfium-135c6601bd9d12bd935371d3122f8e75391de75b.tar.xz
Add {Byte/Wide}String::Trim().
So callers no longer have to call str.TrimLeft(); str.TrimRight(); Change-Id: If931eaa8d891f487b9618ebbeee5ee294e807846 Reviewed-on: https://pdfium-review.googlesource.com/18990 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/widestring_unittest.cpp')
-rw-r--r--core/fxcrt/widestring_unittest.cpp120
1 files changed, 77 insertions, 43 deletions
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index aaa6d9cae7..39337aa7a7 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -628,41 +628,75 @@ TEST(WideString, UpperLower) {
EXPECT_EQ(L"", empty);
}
-TEST(WideString, TrimRight) {
+TEST(WideString, Trim) {
WideString fred(L" FRED ");
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
- fred.TrimRight(L'E');
- EXPECT_EQ(L" FRED", fred);
- fred.TrimRight(L'D');
- EXPECT_EQ(L" FRE", fred);
- fred.TrimRight(L"ERP");
- EXPECT_EQ(L" F", fred);
+ fred.Trim();
+ EXPECT_EQ(L"FRED", fred);
+ fred.Trim(L'E');
+ EXPECT_EQ(L"FRED", fred);
+ fred.Trim(L'F');
+ EXPECT_EQ(L"RED", fred);
+ fred.Trim(L"ERP");
+ EXPECT_EQ(L"D", fred);
WideString blank(L" ");
- blank.TrimRight(L"ERP");
+ blank.Trim(L"ERP");
EXPECT_EQ(L" ", blank);
- blank.TrimRight(L'E');
+ blank.Trim(L'E');
EXPECT_EQ(L" ", blank);
- blank.TrimRight();
+ blank.Trim();
EXPECT_EQ(L"", blank);
WideString empty;
- empty.TrimRight(L"ERP");
+ empty.Trim(L"ERP");
EXPECT_EQ(L"", empty);
- empty.TrimRight(L'E');
+ empty.Trim(L'E');
EXPECT_EQ(L"", empty);
- empty.TrimRight();
+ empty.Trim();
EXPECT_EQ(L"", empty);
+
+ WideString abc(L" ABCCBA ");
+ abc.Trim(L"A");
+ EXPECT_EQ(L" ABCCBA ", abc);
+ abc.Trim(L" A");
+ EXPECT_EQ(L"BCCB", abc);
}
-TEST(WideString, TrimRightCopies) {
+TEST(WideString, TrimLeft) {
+ WideString fred(L" FRED ");
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
+ fred.TrimLeft(L'E');
+ EXPECT_EQ(L"FRED ", fred);
+ fred.TrimLeft(L'F');
+ EXPECT_EQ(L"RED ", fred);
+ fred.TrimLeft(L"ERP");
+ EXPECT_EQ(L"D ", fred);
+
+ WideString blank(L" ");
+ blank.TrimLeft(L"ERP");
+ EXPECT_EQ(L" ", blank);
+ blank.TrimLeft(L'E');
+ EXPECT_EQ(L" ", blank);
+ blank.TrimLeft();
+ EXPECT_EQ(L"", blank);
+
+ WideString empty;
+ empty.TrimLeft(L"ERP");
+ EXPECT_EQ(L"", empty);
+ empty.TrimLeft(L'E');
+ EXPECT_EQ(L"", empty);
+ empty.TrimLeft();
+ EXPECT_EQ(L"", empty);
+}
+
+TEST(WideString, TrimLeftCopies) {
{
// With a single reference, no copy takes place.
WideString fred(L" FRED ");
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -670,8 +704,8 @@ TEST(WideString, TrimRightCopies) {
WideString fred(L" FRED ");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
EXPECT_EQ(L" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -680,48 +714,48 @@ TEST(WideString, TrimRightCopies) {
WideString fred(L"FRED");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
+ fred.TrimLeft();
EXPECT_EQ(L"FRED", fred);
EXPECT_EQ(L"FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
}
-TEST(WideString, TrimLeft) {
+TEST(WideString, TrimRight) {
WideString fred(L" FRED ");
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
- fred.TrimLeft(L'E');
- EXPECT_EQ(L"FRED ", fred);
- fred.TrimLeft(L'F');
- EXPECT_EQ(L"RED ", fred);
- fred.TrimLeft(L"ERP");
- EXPECT_EQ(L"D ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
+ fred.TrimRight(L'E');
+ EXPECT_EQ(L" FRED", fred);
+ fred.TrimRight(L'D');
+ EXPECT_EQ(L" FRE", fred);
+ fred.TrimRight(L"ERP");
+ EXPECT_EQ(L" F", fred);
WideString blank(L" ");
- blank.TrimLeft(L"ERP");
+ blank.TrimRight(L"ERP");
EXPECT_EQ(L" ", blank);
- blank.TrimLeft(L'E');
+ blank.TrimRight(L'E');
EXPECT_EQ(L" ", blank);
- blank.TrimLeft();
+ blank.TrimRight();
EXPECT_EQ(L"", blank);
WideString empty;
- empty.TrimLeft(L"ERP");
+ empty.TrimRight(L"ERP");
EXPECT_EQ(L"", empty);
- empty.TrimLeft(L'E');
+ empty.TrimRight(L'E');
EXPECT_EQ(L"", empty);
- empty.TrimLeft();
+ empty.TrimRight();
EXPECT_EQ(L"", empty);
}
-TEST(WideString, TrimLeftCopies) {
+TEST(WideString, TrimRightCopies) {
{
// With a single reference, no copy takes place.
WideString fred(L" FRED ");
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -729,8 +763,8 @@ TEST(WideString, TrimLeftCopies) {
WideString fred(L" FRED ");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
EXPECT_EQ(L" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -739,7 +773,7 @@ TEST(WideString, TrimLeftCopies) {
WideString fred(L"FRED");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
+ fred.TrimRight();
EXPECT_EQ(L"FRED", fred);
EXPECT_EQ(L"FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
@@ -894,7 +928,7 @@ TEST(WideString, UTF16LE_Encode) {
struct UTF16LEEncodeCase {
WideString ws;
ByteString bs;
- } utf16le_encode_cases[] = {
+ } const utf16le_encode_cases[] = {
{L"", ByteString("\0\0", 2)},
{L"abc", ByteString("a\0b\0c\0\0\0", 8)},
{L"abcdef", ByteString("a\0b\0c\0d\0e\0f\0\0\0", 14)},