1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// { dg-options "-std=gnu++20" }
// { dg-do run { target c++20 } }
// { dg-require-namedlocale "fr_FR.ISO8859-15" }
#include <chrono>
#include <sstream>
#include <testsuite_hooks.h>
void
test_ostream()
{
using std::ostringstream;
using namespace std::chrono;
ostringstream ss;
for (int i = 0; i <= 7; ++i)
ss << weekday(i);
VERIFY( ss.str() == "SunMonTueWedThuFriSatSun" );
ss.str("");
ss << weekday(8) << '|' << weekday(99);
VERIFY( ss.str() == "8 is not a valid weekday|99 is not a valid weekday" );
ss.str("");
ss.imbue(std::locale(ISO_8859(15,fr_FR)));
ss << weekday(6);
VERIFY( ss.str() == "sam." );
}
void
test_format()
{
using std::chrono::weekday;
auto s = std::format("{:%a%%%A%t%u%n%w}", std::chrono::Monday);
VERIFY( s == "Mon%Monday\t1\n1" );
auto ws = std::format(L"{:%a%%%A%t%u%n%w}", weekday(7));
VERIFY( ws == L"Sun%Sunday\t7\n0" );
s = std::format("{:%w}", weekday(8));
VERIFY( s == "8" );
try
{
(void) std::format("{:%a}", weekday(8));
VERIFY(false);
}
catch (const std::format_error&)
{
}
s = std::format("{} is OK, but {:L}", weekday(2), weekday(13));
VERIFY( s == "Tue is OK, but 13 is not a valid weekday" );
std::locale loc_fr(ISO_8859(15,fr_FR));
s = std::format("{:%Ow}", weekday(1));
VERIFY( s == "1" );
s = std::format(std::locale::classic(), "{:%Ow}", weekday(1));
VERIFY( s == "1" );
s = std::format(std::locale::classic(), "{:L%Ow}", weekday(1));
VERIFY( s == "1" );
s = std::format(loc_fr, "{:%Ow}", weekday(1));
VERIFY( s == "1" );
s = std::format(loc_fr, "{:L%Ow}", weekday(1));
VERIFY( s == "1" );
// TODO test "{:L%Ow}" with locale that has alternative numeric rep.
s = std::format(loc_fr, "{:%a}", weekday(1));
VERIFY( s == "Mon" );
s = std::format(loc_fr, "{:L%a}", weekday(1));
VERIFY( s == "lun." );
std::string_view specs = "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
std::string_view my_specs = "aAuw";
for (char c : specs)
{
char fmt[] = { '{', ':', '%', c, '}' };
try
{
(void) std::vformat(std::string_view(fmt, 5),
std::make_format_args(weekday(1)));
// The call above should throw for any conversion-spec not in my_specs:
VERIFY(my_specs.find(c) != my_specs.npos);
}
catch (const std::format_error& e)
{
VERIFY(my_specs.find(c) == my_specs.npos);
std::string_view s = e.what();
// Libstdc++-specific message:
VERIFY(s.find("format argument does not contain the information "
"required by the chrono-specs") != s.npos);
}
}
}
int main()
{
test_ostream();
test_format();
// TODO: test_parse();
}
|