Skip to content

Commit aba3db6

Browse files
committed
#152 - Test CppStringT::join() with char and wchar_t
Completed. Fixed bugs.
1 parent 43f92f7 commit aba3db6

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,46 @@ namespace cppstringstests
713713
}
714714
}
715715

716+
TEST_METHOD(join)
717+
{
718+
pcs::CppString s("##");
719+
std::array<CppString, 2> arr{ "abcd", "efg" };
720+
Assert::AreEqual(pcs::CppString("abcd##efg").c_str(), s.join(arr).c_str());
721+
Assert::AreEqual(pcs::CppString("abcd##efg##123456789").c_str(), s.join(std::array<CppString, 3>{ "abcd", "efg", "123456789" }).c_str());
722+
723+
pcs::CppWString ws(L"##");
724+
std::array<CppWString, 2> warr{ L"abcd", L"efg" };
725+
Assert::AreEqual(pcs::CppWString(L"abcd##efg").c_str(), ws.join(warr).c_str());
726+
Assert::AreEqual(pcs::CppWString(L"abcd##efg##123456789").c_str(), ws.join(std::array<CppWString, 3>{ L"abcd", L"efg", L"123456789" }).c_str());
727+
728+
std::vector<CppString> vec{ "abcd", "efg" };
729+
Assert::AreEqual(pcs::CppString("abcd##efg").c_str(), s.join(vec).c_str());
730+
vec.push_back("123456789");
731+
Assert::AreEqual(pcs::CppString("abcd##efg##123456789").c_str(), s.join(vec).c_str());
732+
733+
std::vector<CppWString> wvec{ L"abcd", L"efg" };
734+
Assert::AreEqual(pcs::CppWString(L"abcd##efg").c_str(), ws.join(wvec).c_str());
735+
wvec.push_back(L"123456789");
736+
Assert::AreEqual(pcs::CppWString(L"abcd##efg##123456789").c_str(), ws.join(wvec).c_str());
737+
738+
Assert::AreEqual(pcs::CppString("abcd##efg").c_str(), s.join(pcs::CppString("abcd"), pcs::CppString("efg")).c_str());
739+
Assert::AreEqual(pcs::CppString("abcd##efg##123456789").c_str(), s.join(pcs::CppString("abcd"), pcs::CppString("efg"), pcs::CppString("123456789")).c_str());
740+
Assert::AreEqual(pcs::CppString("abcd##efg##123456789##0").c_str(), s.join("abcd", "efg", "123456789", "0").c_str());
741+
Assert::AreEqual(pcs::CppString("abcd# #efg# #123456789# #0").c_str(), "# #"cs.join("abcd", "efg", "123456789", "0").c_str());
742+
Assert::AreEqual("abcdE", "##"cs.join("abcdE").c_str());
743+
Assert::AreEqual("##", "##"cs.join().c_str());
744+
Assert::AreEqual("", "##"cs.join("").c_str());
745+
746+
Assert::AreEqual(pcs::CppWString(L"abcd##efg").c_str(), ws.join(pcs::CppWString(L"abcd"), pcs::CppWString(L"efg")).c_str());
747+
Assert::AreEqual(pcs::CppWString(L"abcd##efg##123456789").c_str(), ws.join(pcs::CppWString(L"abcd"), pcs::CppWString(L"efg"), pcs::CppWString(L"123456789")).c_str());
748+
Assert::AreEqual(pcs::CppWString(L"abcd##efg##123456789##0").c_str(), ws.join(L"abcd"cs, L"efg"cs, L"123456789"cs, L"0"cs).c_str());
749+
Assert::AreEqual(pcs::CppWString(L"abcd# #efg# #123456789# #0").c_str(), L"# #"csv.join(L"abcd", L"efg"cs, L"123456789"cs, L"0"cs).c_str());
750+
Assert::AreEqual(pcs::CppWString(L"abcdE").c_str(), L"##"cs.join(L"abcdE").c_str());
751+
Assert::AreEqual(pcs::CppWString(L"##").c_str(), L"##"cs.join().c_str());
752+
Assert::AreEqual(pcs::CppWString(L"").c_str(), L"##"cs.join(L"").c_str());
753+
754+
}
755+
716756

717757

718758
};

cpp-strings-tests/pch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ namespace cppstringstests
665665
}
666666
};
667667

668+
668669
//===== PART 4 ========================================
669670

670671

cpp-strings/cppstrings.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ namespace pcs // i.e. "pythonic c++ strings"
5454

5555
// litteral operators
5656
#pragma warning(disable: 4455)
57-
inline const CppString operator""cs(const char* str, std::size_t len); //!< Forms a CppString literal.
58-
inline const CppString operator""csv(const char* str, std::size_t len); //!< Forms a CppString view literal.
59-
inline const CppWString operator""cs(const wchar_t* str, std::size_t len); //!< Forms a CppWString literal.
60-
inline const CppWString operator""csv(const wchar_t* str, std::size_t len); //!< Forms a CppWString view literal.
57+
inline CppString operator""cs(const char* str, std::size_t len); //!< Forms a CppString literal.
58+
inline CppString operator""csv(const char* str, std::size_t len); //!< Forms a CppString view literal.
59+
inline CppWString operator""cs(const wchar_t* str, std::size_t len); //!< Forms a CppWString literal.
60+
inline CppWString operator""csv(const wchar_t* str, std::size_t len); //!< Forms a CppWString view literal.
6161

6262
// chars classifications -- not to be directly called, see respective specializations at the very end of this module.
6363
template<class CharT>
@@ -1016,12 +1016,12 @@ namespace pcs // i.e. "pythonic c++ strings"
10161016
* The separator between elements is the string to which this method is applied.
10171017
*/
10181018
template<const std::size_t N>
1019-
inline CppStringT join(const std::array<CppStringT, N>& strs) const noexcept
1019+
CppStringT join(const std::array<CppStringT, N>& strs) const noexcept
10201020
{
1021-
auto str_it = strs.cbegin();
1022-
if (str_it == strs.cend())
1021+
if (strs.empty())
10231022
return CppStringT();
10241023

1024+
auto str_it = strs.cbegin();
10251025
CppStringT res{ *str_it++ };
10261026
while (str_it != strs.cend())
10271027
res += *this + *str_it++;
@@ -1034,10 +1034,10 @@ namespace pcs // i.e. "pythonic c++ strings"
10341034
*/
10351035
CppStringT join(const std::vector<CppStringT>& strs) const noexcept
10361036
{
1037-
auto str_it = strs.cbegin();
1038-
if (str_it == strs.cend())
1037+
if (strs.empty())
10391038
return CppStringT();
10401039

1040+
auto str_it = strs.cbegin();
10411041
CppStringT res{ *str_it++ };
10421042
while (str_it != strs.cend())
10431043
res += *this + *str_it++;
@@ -1056,7 +1056,7 @@ namespace pcs // i.e. "pythonic c++ strings"
10561056
}
10571057

10581058
/** \brief Single parameter signature. Returns a copy of this parameter. */
1059-
inline const CppStringT join(const CppStringT& s) const noexcept
1059+
inline CppStringT join(const CppStringT& s) const noexcept
10601060
{
10611061
return s;
10621062
}
@@ -1928,26 +1928,26 @@ namespace pcs // i.e. "pythonic c++ strings"
19281928

19291929
//===== litteral operators ============================
19301930
/** \brief Forms a CppString literal. */
1931-
inline const CppString operator""cs(const char* str, std::size_t len)
1931+
inline CppString operator""cs(const char* str, std::size_t len)
19321932
{
19331933
return CppString(CppString::MyBaseClass(str, len));
19341934
}
19351935

19361936
/** \brief Forms a CppString view literal. */
1937-
inline const CppString operator""csv(const char* str, std::size_t len)
1937+
inline CppString operator""csv(const char* str, std::size_t len)
19381938
{
19391939
//return CppString(CppString::MyStringView(str, len));
19401940
return CppString(str, len);
19411941
}
19421942

19431943
/** \brief Forms a CppWString literal. */
1944-
inline const CppWString operator""cs(const wchar_t* str, std::size_t len)
1944+
inline CppWString operator""cs(const wchar_t* str, std::size_t len)
19451945
{
19461946
return CppWString(CppWString::MyBaseClass(str, len));
19471947
}
19481948

19491949
/** \brief Forms a CppWString view literal. */
1950-
inline const CppWString operator""csv(const wchar_t* str, std::size_t len)
1950+
inline CppWString operator""csv(const wchar_t* str, std::size_t len)
19511951
{
19521952
//return CppWString(CppWString::MyStringView(str, len));
19531953
return CppWString(str, len);

0 commit comments

Comments
 (0)