Skip to content

Commit 98a85fb

Browse files
committed
#156 - Test CppStringT::partition() with char and wchar_t
Completed. Fixed a typo.
1 parent c7a867b commit 98a85fb

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

cpp-strings-tests/cpp-strings-tests.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,5 +829,52 @@ namespace cppstringstests
829829
Assert::AreEqual(L"a bcd ", L" a bcd "cs.lstrip().c_str());
830830
}
831831

832+
TEST_METHOD(partition)
833+
{
834+
pcs::CppString s("abcd#123efg");
835+
std::vector<CppString> res{ s.partition("#123") };
836+
Assert::AreEqual("abcd", res[0].c_str());
837+
Assert::AreEqual("#123", res[1].c_str());
838+
Assert::AreEqual("efg", res[2].c_str());
839+
840+
s = "abcd#123";
841+
res = s.partition("#123");
842+
Assert::AreEqual("abcd", res[0].c_str());
843+
Assert::AreEqual("#123", res[1].c_str());
844+
Assert::AreEqual("", res[2].c_str());
845+
846+
res = s.partition("XYZ");
847+
Assert::AreEqual("abcd#123", res[0].c_str());
848+
Assert::AreEqual("", res[1].c_str());
849+
Assert::AreEqual("", res[2].c_str());
850+
851+
res = ""cs.partition("A");
852+
Assert::AreEqual("", res[0].c_str());
853+
Assert::AreEqual("", res[1].c_str());
854+
Assert::AreEqual("", res[2].c_str());
855+
856+
pcs::CppWString ws(L"abcd#123efg");
857+
std::vector<CppWString> wres{ ws.partition(L"#123") };
858+
Assert::AreEqual(L"abcd", wres[0].c_str());
859+
Assert::AreEqual(L"#123", wres[1].c_str());
860+
Assert::AreEqual(L"efg", wres[2].c_str());
861+
862+
ws = L"abcd#123";
863+
wres = ws.partition(L"#123");
864+
Assert::AreEqual(L"abcd", wres[0].c_str());
865+
Assert::AreEqual(L"#123", wres[1].c_str());
866+
Assert::AreEqual(L"", wres[2].c_str());
867+
868+
wres = ws.partition(L"XYZ");
869+
Assert::AreEqual(L"abcd#123", wres[0].c_str());
870+
Assert::AreEqual(L"", wres[1].c_str());
871+
Assert::AreEqual(L"", wres[2].c_str());
872+
873+
wres = L""cs.partition(L"A");
874+
Assert::AreEqual(L"", wres[0].c_str());
875+
Assert::AreEqual(L"", wres[1].c_str());
876+
Assert::AreEqual(L"", wres[2].c_str());
877+
}
878+
832879
};
833880
}

cpp-strings/cppstrings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ namespace pcs // i.e. "pythonic c++ strings"
11351135

11361136

11371137
//--- partition() -------------------------------------
1138-
/** Split the string at the first occurrence of sep, and returns a 3-items vector containing the part before the separator, the separator itself, and the part after the separator.
1138+
/** Splits the string at the first occurrence of sep, and returns a 3-items vector containing the part before the separator, the separator itself, and the part after the separator.
11391139
*
11401140
* If the separator is not found, returns a 3-items vector
11411141
* containing the string itself, followed by two empty strings.

0 commit comments

Comments
 (0)