New tests

This commit is contained in:
Vladislav Shchapov 2021-10-09 23:17:51 +05:00 committed by Victor Zverovich
parent 7911d8d3f5
commit d3d30a46f0
2 changed files with 33 additions and 0 deletions

View File

@ -51,6 +51,7 @@ TEST(chrono_test, format_tm) {
EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm),
"The date is 2016-04-25 11:22:33.");
EXPECT_EQ(fmt::format("{:%Y}", tm), "2016");
EXPECT_EQ(fmt::format("{:%C}", tm), "20");
EXPECT_EQ(fmt::format("{:%e}", tm), "25");
EXPECT_EQ(fmt::format("{:%D}", tm), "04/25/16");
EXPECT_EQ(fmt::format("{:%F}", tm), "2016-04-25");
@ -72,6 +73,7 @@ TEST(chrono_test, format_tm_future) {
EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm),
"The date is 12345-04-25 11:22:33.");
EXPECT_EQ(fmt::format("{:%Y}", tm), "12345");
EXPECT_EQ(fmt::format("{:%C}", tm), "123");
EXPECT_EQ(fmt::format("{:%D}", tm), "04/25/45");
EXPECT_EQ(fmt::format("{:%F}", tm), "12345-04-25");
EXPECT_EQ(fmt::format("{:%T}", tm), "11:22:33");
@ -89,6 +91,10 @@ TEST(chrono_test, format_tm_past) {
"The date is -101-04-25 11:22:33.");
EXPECT_EQ(fmt::format("{:%Y}", tm), "-101");
// macOS %C - "-1"
// Linux %C - "-2"
// EXPECT_EQ(fmt::format("{:%C}", tm), "-1");
// macOS %D - "04/25/01" (%y)
// Linux %D - "04/25/99" (%y)
// EXPECT_EQ(fmt::format("{:%D}", tm), "04/25/01");
@ -160,6 +166,7 @@ TEST(chrono_test, time_point) {
"%w", "%Ow", "%u", "%Ou", "%H", "%OH", "%I", "%OI", "%M", "%OM",
"%S", "%OS", "%c", "%Ec", "%x", "%Ex", "%X", "%EX", "%D", "%F",
"%r", "%R", "%T", "%p", "%z", "%Z"};
spec_list.push_back("%Y-%m-%d %H:%M:%S");
for (const auto& spec : spec_list) {
auto t = std::chrono::system_clock::to_time_t(t1);
auto tm = *std::localtime(&t);

View File

@ -8,6 +8,8 @@
#include "fmt/xchar.h"
#include <complex>
#include <cwchar>
#include <vector>
#include "fmt/chrono.h"
#include "fmt/color.h"
@ -265,6 +267,30 @@ TEST(xchar_test, chrono) {
EXPECT_EQ(fmt::format(L"{:%T}", tm), L"11:22:33");
}
TEST(chrono_test, time_point) {
auto t1 = std::chrono::system_clock::now();
std::vector<std::wstring> spec_list = {
L"%%", L"%n", L"%t", L"%Y", L"%EY", L"%y", L"%Oy", L"%Ey",
L"%C", L"%EC", L"%G", L"%g", L"%b", L"%h", L"%B", L"%m",
L"%Om", L"%U", L"%OU", L"%W", L"%OW", L"%V", L"%OV", L"%j",
L"%d", L"%Od", L"%e", L"%Oe", L"%a", L"%A", L"%w", L"%Ow",
L"%u", L"%Ou", L"%H", L"%OH", L"%I", L"%OI", L"%M", L"%OM",
L"%S", L"%OS", L"%c", L"%Ec", L"%x", L"%Ex", L"%X", L"%EX",
L"%D", L"%F", L"%r", L"%R", L"%T", L"%p", L"%z", L"%Z"};
spec_list.push_back(L"%Y-%m-%d %H:%M:%S");
for (const auto& spec : spec_list) {
auto t = std::chrono::system_clock::to_time_t(t1);
auto tm = *std::localtime(&t);
wchar_t output[1024] = {};
std::wcsftime(output, sizeof(output) / sizeof(wchar_t), spec.c_str(), &tm);
auto fmt_spec = std::wstring(L"{:").append(spec).append(L"}");
EXPECT_EQ(output, fmt::format(fmt_spec, t1));
EXPECT_EQ(output, fmt::format(fmt_spec, tm));
}
}
TEST(xchar_test, color) {
EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), L"rgb(255,20,30) wide"),
L"\x1b[38;2;255;020;030mrgb(255,20,30) wide\x1b[0m");