Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
d3d30a46
Commit
d3d30a46
authored
Oct 09, 2021
by
Vladislav Shchapov
Committed by
Victor Zverovich
Oct 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New tests
parent
7911d8d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
test/chrono-test.cc
test/chrono-test.cc
+7
-0
test/xchar-test.cc
test/xchar-test.cc
+26
-0
No files found.
test/chrono-test.cc
View file @
d3d30a46
...
...
@@ -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
);
...
...
test/xchar-test.cc
View file @
d3d30a46
...
...
@@ -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"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment