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 // TODO FMT Investigate Windows issues.
19 // REQUIRES: locale.fr_FR.UTF-8
20 // REQUIRES: locale.ja_JP.UTF-8
24 // class year_month_day;
26 // template<class charT, class traits>
27 // basic_ostream<charT, traits>&
28 // operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
34 #include "make_string.h"
35 #include "platform_support.h" // locale name macros
36 #include "test_macros.h"
37 #include "assert_macros.h"
38 #include "concat_macros.h"
40 #define SV(S) MAKE_STRING_VIEW(CharT, S)
42 #define TEST_EQUAL(OUT, EXPECTED) \
43 TEST_REQUIRE(OUT == EXPECTED, \
44 TEST_WRITE_CONCATENATED( \
45 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
47 template <class CharT
>
48 static std::basic_string
<CharT
> stream_c_locale(std::chrono::year_month_day ymd
) {
49 std::basic_stringstream
<CharT
> sstr
;
54 template <class CharT
>
55 static std::basic_string
<CharT
> stream_fr_FR_locale(std::chrono::year_month_day ymd
) {
56 std::basic_stringstream
<CharT
> sstr
;
57 const std::locale
locale(LOCALE_fr_FR_UTF_8
);
63 template <class CharT
>
64 static std::basic_string
<CharT
> stream_ja_JP_locale(std::chrono::year_month_day ymd
) {
65 std::basic_stringstream
<CharT
> sstr
;
66 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
72 template <class CharT
>
74 TEST_EQUAL(stream_c_locale
<CharT
>(
75 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
76 SV("-32768-01-01 is not a valid date"));
77 TEST_EQUAL(stream_c_locale
<CharT
>(
78 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
79 SV("-32767-00-01 is not a valid date"));
80 TEST_EQUAL(stream_c_locale
<CharT
>(
81 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::day
{0}}),
82 SV("-32767-01-00 is not a valid date"));
83 TEST_EQUAL(stream_c_locale
<CharT
>(
84 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
86 TEST_EQUAL(stream_c_locale
<CharT
>(
87 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
88 SV("1999-02-29 is not a valid date"));
89 TEST_EQUAL(stream_c_locale
<CharT
>(
90 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
94 TEST_EQUAL(stream_c_locale
<CharT
>(
95 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
97 #elif defined(_WIN32) // defined(_AIX)
98 TEST_EQUAL(stream_c_locale
<CharT
>(
99 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
101 #else // defined(_AIX)
102 TEST_EQUAL(stream_c_locale
<CharT
>(
103 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
105 #endif // defined(_AIX)
107 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
108 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
109 SV("-32768-01-01 is not a valid date"));
110 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
111 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
112 SV("-32767-00-01 is not a valid date"));
113 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
114 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::day
{0}}),
115 SV("-32767-01-00 is not a valid date"));
116 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
117 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
119 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
120 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
121 SV("1999-02-29 is not a valid date"));
122 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
123 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
126 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
127 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
129 #elif defined(_WIN32) // defined(_AIX)
130 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
131 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
133 #else // defined(_AIX)
134 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
135 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
137 #endif // defined(_AIX)
139 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
140 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
141 SV("-32768-01-01 is not a valid date"));
142 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
143 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
144 SV("-32767-00-01 is not a valid date"));
145 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
146 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::day
{0}}),
147 SV("-32767-01-00 is not a valid date"));
148 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
149 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
151 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
152 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
153 SV("1999-02-29 is not a valid date"));
154 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
155 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
158 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
159 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
161 #elif defined(_WIN32) // defined(_AIX)
162 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
163 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
165 #else // defined(_AIX)
166 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
167 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
169 #endif // defined(_AIX)
172 int main(int, char**) {
175 #ifndef TEST_HAS_NO_WIDE_CHARACTERS