[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.clock / time.clock.system / sys_date.ostream.pass.cpp
blob7af3ebf7768072ef03263d4791ad771b23bdb90a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
16 // TODO FMT Investigate Windows issues.
17 // XFAIL: msvc
19 // REQUIRES: locale.fr_FR.UTF-8
20 // REQUIRES: locale.ja_JP.UTF-8
22 // <chrono>
24 // class system_Clock;
26 // template<class charT, class traits>
27 // basic_ostream<charT, traits>&
28 // operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
30 #include <cassert>
31 #include <chrono>
32 #include <ratio>
33 #include <sstream>
35 #include "make_string.h"
36 #include "platform_support.h" // locale name macros
37 #include "test_macros.h"
38 #include "assert_macros.h"
39 #include "concat_macros.h"
41 #define SV(S) MAKE_STRING_VIEW(CharT, S)
43 #define TEST_EQUAL(OUT, EXPECTED) \
44 TEST_REQUIRE(OUT == EXPECTED, \
45 TEST_WRITE_CONCATENATED( \
46 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
48 template <class CharT>
49 static std::basic_string<CharT> stream_c_locale(const std::chrono::sys_days& dp) {
50 std::basic_stringstream<CharT> sstr;
51 sstr << dp;
52 return sstr.str();
55 template <class CharT>
56 static std::basic_string<CharT> stream_fr_FR_locale(const std::chrono::sys_days& dp) {
57 std::basic_stringstream<CharT> sstr;
58 const std::locale locale(LOCALE_fr_FR_UTF_8);
59 sstr.imbue(locale);
60 sstr << dp;
61 return sstr.str();
64 template <class CharT>
65 static std::basic_string<CharT> stream_ja_JP_locale(const std::chrono::sys_days& dp) {
66 std::basic_stringstream<CharT> sstr;
67 const std::locale locale(LOCALE_ja_JP_UTF_8);
68 sstr.imbue(locale);
69 sstr << dp;
70 return sstr.str();
73 template <class CharT>
74 static void test() {
75 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
76 std::chrono::year_month_day{std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::day{1}}}),
77 SV("-32768-01-01 is not a valid date"));
78 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
79 std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{1}}}),
80 SV("1970-01-01"));
81 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
82 std::chrono::year_month_day{std::chrono::year{2000}, std::chrono::month{2}, std::chrono::day{29}}}),
83 SV("2000-02-29"));
85 #if defined(_AIX)
86 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
87 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
88 SV("+32767-12-31"));
89 #elif defined(_WIN32) // defined(_AIX)
90 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
91 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
92 SV(""));
93 #else // defined(_AIX)
94 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_days{
95 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
96 SV("32767-12-31"));
97 #endif // defined(_AIX)
99 // multiples of days are considered days.
100 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_time<std::chrono::weeks>{std::chrono::weeks{3}}),
101 SV("1970-01-22"));
102 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::sys_time<std::chrono::duration<int, std::ratio<30 * 86400>>>{
103 std::chrono::duration<int, std::ratio<30 * 86400>>{1}}),
104 SV("1970-01-31"));
106 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
107 std::chrono::year_month_day{std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::day{1}}}),
108 SV("-32768-01-01 is not a valid date"));
109 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
110 std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{1}}}),
111 SV("1970-01-01"));
112 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
113 std::chrono::year_month_day{std::chrono::year{2000}, std::chrono::month{2}, std::chrono::day{29}}}),
114 SV("2000-02-29"));
115 #if defined(_AIX)
116 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
117 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
118 SV("+32767-12-31"));
119 #elif defined(_WIN32) // defined(_AIX)
120 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
121 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
122 SV(""));
123 #else // defined(_AIX)
124 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_days{
125 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
126 SV("32767-12-31"));
127 #endif // defined(_AIX)
129 // multiples of days are considered days.
130 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_time<std::chrono::weeks>{std::chrono::weeks{3}}),
131 SV("1970-01-22"));
132 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::sys_time<std::chrono::duration<int, std::ratio<30 * 86400>>>{
133 std::chrono::duration<int, std::ratio<30 * 86400>>{1}}),
134 SV("1970-01-31"));
136 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
137 std::chrono::year_month_day{std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::day{1}}}),
138 SV("-32768-01-01 is not a valid date"));
139 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
140 std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{1}}}),
141 SV("1970-01-01"));
142 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
143 std::chrono::year_month_day{std::chrono::year{2000}, std::chrono::month{2}, std::chrono::day{29}}}),
144 SV("2000-02-29"));
145 #if defined(_AIX)
146 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
147 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
148 SV("+32767-12-31"));
149 #elif defined(_WIN32) // defined(_AIX)
150 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
151 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
152 SV(""));
153 #else // defined(_AIX)
154 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_days{
155 std::chrono::year_month_day{std::chrono::year{32'767}, std::chrono::month{12}, std::chrono::day{31}}}),
156 SV("32767-12-31"));
157 #endif // defined(_AIX)
159 // multiples of days are considered days.
160 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_time<std::chrono::weeks>{std::chrono::weeks{3}}),
161 SV("1970-01-22"));
162 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::sys_time<std::chrono::duration<int, std::ratio<30 * 86400>>>{
163 std::chrono::duration<int, std::ratio<30 * 86400>>{1}}),
164 SV("1970-01-31"));
167 int main(int, char**) {
168 test<char>();
170 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
171 test<wchar_t>();
172 #endif
174 return 0;