1 //===----------------------------------------------------------------------===//
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
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 // REQUIRES: locale.fr_FR.UTF-8
17 // REQUIRES: locale.ja_JP.UTF-8
21 // class year_month_weekday;
23 // template<class charT, class traits>
24 // basic_ostream<charT, traits>&
25 // operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd);
31 #include "make_string.h"
32 #include "platform_support.h" // locale name macros
33 #include "test_macros.h"
34 #include "assert_macros.h"
35 #include "concat_macros.h"
37 #define SV(S) MAKE_STRING_VIEW(CharT, S)
39 #define TEST_EQUAL(OUT, EXPECTED) \
40 TEST_REQUIRE(OUT == EXPECTED, \
41 TEST_WRITE_CONCATENATED( \
42 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
44 template <class CharT
>
45 static std::basic_string
<CharT
> stream_c_locale(std::chrono::year_month_weekday ymwd
) {
46 std::basic_stringstream
<CharT
> sstr
;
51 template <class CharT
>
52 static std::basic_string
<CharT
> stream_fr_FR_locale(std::chrono::year_month_weekday ymwd
) {
53 std::basic_stringstream
<CharT
> sstr
;
54 const std::locale
locale(LOCALE_fr_FR_UTF_8
);
60 template <class CharT
>
61 static std::basic_string
<CharT
> stream_ja_JP_locale(std::chrono::year_month_weekday ymwd
) {
62 std::basic_stringstream
<CharT
> sstr
;
63 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
69 template <class CharT
>
72 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
73 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
74 SV("-32768 is not a valid year/Jan/Sun[1]"));
76 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
77 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
78 SV("-32767/0 is not a valid month/Sun[1]"));
80 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
81 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
82 SV("-32767/Jan/8 is not a valid weekday[1]"));
84 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
85 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
86 SV("-32767/Jan/Sun[0 is not a valid index]")); // note 0 is a valid index here...
88 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
89 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
90 SV("-32767/Jan/Sun[1]"));
93 stream_c_locale
<CharT
>(std::chrono::year_month_weekday
{
94 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
95 SV("1970/Jan/Sun[1]"));
97 #if defined(__APPLE__)
99 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
100 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
101 SV("-32768 is not a valid year/jan/Dim[1]"));
103 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
104 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
105 SV("-32767/0 is not a valid month/Dim[1]"));
107 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
108 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
109 SV("-32767/jan/8 is not a valid weekday[1]"));
111 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
112 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
113 SV("-32767/jan/Dim[0 is not a valid index]")); // note 0 is a valid index here...
115 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
116 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
117 SV("-32767/jan/Dim[1]"));
120 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
121 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
122 SV("1970/jan/Dim[1]"));
123 #else // defined(__APPLE__)
125 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
126 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
127 SV("-32768 is not a valid year/janv./dim.[1]"));
129 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
130 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
131 SV("-32767/0 is not a valid month/dim.[1]"));
133 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
134 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
135 SV("-32767/janv./8 is not a valid weekday[1]"));
137 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
138 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
139 SV("-32767/janv./dim.[0 is not a valid index]")); // note 0 is a valid index here...
141 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
142 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
143 SV("-32767/janv./dim.[1]"));
146 stream_fr_FR_locale
<CharT
>(std::chrono::year_month_weekday
{
147 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
148 SV("1970/janv./dim.[1]"));
149 #endif // defined(__APPLE__)
151 #if defined(__APPLE__)
153 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
154 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
155 SV("-32768 is not a valid year/ 1/日[1]"));
157 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
158 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
159 SV("-32767/0 is not a valid month/日[1]"));
161 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
162 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
163 SV("-32767/ 1/8 is not a valid weekday[1]"));
165 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
166 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
167 SV("-32767/ 1/日[0 is not a valid index]")); // note 0 is a valid index here...
169 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
170 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
171 SV("-32767/ 1/日[1]"));
173 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
174 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
176 #elif defined(_WIN32) // defined(__APPLE__)
178 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
179 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
180 SV("-32768 is not a valid year/1/日[1]"));
182 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
183 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
184 SV("-32767/0 is not a valid month/日[1]"));
186 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
187 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
188 SV("-32767/1/8 is not a valid weekday[1]"));
190 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
191 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
192 SV("-32767/1/日[0 is not a valid index]")); // note 0 is a valid index here...
194 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
195 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
196 SV("-32767/1/日[1]"));
199 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
200 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
202 #elif defined(_AIX) // defined(__APPLE__)
204 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
205 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
206 SV("-32768 is not a valid year/1月/日[1]"));
208 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
209 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
210 SV("-32767/0 is not a valid month/日[1]"));
212 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
213 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
214 SV("-32767/1月/8 is not a valid weekday[1]"));
217 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
218 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
219 SV("-32767/1月/日[0 is not a valid index]")); // note 0 is a valid index here...
221 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
222 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
223 SV("-32767/1月/日[1]"));
226 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
227 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
229 #else // defined(__APPLE__)
231 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
232 std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
233 SV("-32768 is not a valid year/ 1月/日[1]"));
235 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
236 std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
237 SV("-32767/0 is not a valid month/日[1]"));
239 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
240 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(8), 1}}),
241 SV("-32767/ 1月/8 is not a valid weekday[1]"));
243 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
244 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 0}}),
245 SV("-32767/ 1月/日[0 is not a valid index]")); // note 0 is a valid index here...
247 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
248 std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
249 SV("-32767/ 1月/日[1]"));
252 stream_ja_JP_locale
<CharT
>(std::chrono::year_month_weekday
{
253 std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::weekday_indexed
{std::chrono::weekday(0), 1}}),
254 SV("1970/ 1月/日[1]"));
255 #endif // defined(__APPLE__)
258 int main(int, char**) {
261 #ifndef TEST_HAS_NO_WIDE_CHARACTERS