Skip to content

Commit bccb85b

Browse files
committed
#205-test method CppStringT::format()
Completed. Validated.
1 parent 18f4f7d commit bccb85b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,26 @@ namespace cppstringstests
25412541

25422542
}
25432543

2544+
TEST_METHOD(format)
2545+
{
2546+
pcs::CppString s;
2547+
s.format("{:d}, {:d}, {:s}", 1, 2, "Abc");
2548+
Assert::AreEqual("1, 2, Abc", s.c_str());
2549+
2550+
const int x{ 5 };
2551+
const unsigned long long y{ 6 };
2552+
const double pi{ 3.141592653529 };
2553+
const std::string t{ "abc." };
2554+
Assert::AreEqual("56 3.1415927abc.", (s.format("{}{}{:10.7f}{:s}", x, y, pi, t)).c_str());
2555+
2556+
pcs::CppWString ws;
2557+
ws.format(L"{:d}, {:d}, {}", 1, 2, L"Abc");
2558+
Assert::AreEqual(L"1, 2, Abc", ws.c_str());
2559+
2560+
const std::wstring wt{ L"abc." };
2561+
Assert::AreEqual(L"56 3.1415927abc.", (ws.format(L"{}{}{:10.7f}{:s}", x, y, pi, wt)).c_str());
2562+
}
2563+
25442564
TEST_METHOD(index_char)
25452565
{
25462566
using string_type = pcs::CppString;

cpp-strings/cppstrings.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ using namespace pcs;
2929
*/
3030
int main()
3131
{
32-
CppString s = "-5.1";
32+
CppString s = "-5.1"cs;
3333
CppWString ws{ L"-5.2"cs };
3434

3535
std::cout << ws.isupper() << std::endl;
3636
std::cout << s.zfill(10).c_str() << std::endl;
3737

38+
s.format("{} {}", 1, 3.14);
39+
ws.format(L"{} abc", 2);
40+
41+
std::cout << s.c_str() << " / ";
42+
std::wcout << ws.c_str() << std::endl;
43+
3844
return 0;
3945
}

0 commit comments

Comments
 (0)