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_day;
23 // template<class charT, class traits>
24 // basic_ostream<charT, traits>&
25 // operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
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_day ymd
) {
46 std::basic_stringstream
<CharT
> sstr
;
51 template <class CharT
>
52 static std::basic_string
<CharT
> stream_fr_FR_locale(std::chrono::year_month_day ymd
) {
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_day ymd
) {
62 std::basic_stringstream
<CharT
> sstr
;
63 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
69 template <class CharT
>
71 TEST_EQUAL(stream_c_locale
<CharT
>(
72 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
73 SV("-32768-01-01 is not a valid date"));
74 TEST_EQUAL(stream_c_locale
<CharT
>(
75 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
76 SV("-32767-00-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
{1}, std::chrono::day
{0}}),
79 SV("-32767-01-00 is not a valid date"));
80 TEST_EQUAL(stream_c_locale
<CharT
>(
81 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
83 TEST_EQUAL(stream_c_locale
<CharT
>(
84 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
85 SV("1999-02-29 is not a valid date"));
86 TEST_EQUAL(stream_c_locale
<CharT
>(
87 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
89 TEST_EQUAL(stream_c_locale
<CharT
>(
90 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
93 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
94 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
95 SV("-32768-01-01 is not a valid date"));
96 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
97 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
98 SV("-32767-00-01 is not a valid date"));
99 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
100 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::day
{0}}),
101 SV("-32767-01-00 is not a valid date"));
102 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
103 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
105 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
106 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
107 SV("1999-02-29 is not a valid date"));
108 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
109 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
111 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(
112 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
115 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
116 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}),
117 SV("-32768-01-01 is not a valid date"));
118 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
119 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{0}, std::chrono::day
{1}}),
120 SV("-32767-00-01 is not a valid date"));
121 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
122 std::chrono::year_month_day
{std::chrono::year
{-32'767}, std::chrono::month
{1}, std::chrono::day
{0}}),
123 SV("-32767-01-00 is not a valid date"));
124 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
125 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}),
127 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
128 std::chrono::year_month_day
{std::chrono::year
{1999}, std::chrono::month
{2}, std::chrono::day
{29}}),
129 SV("1999-02-29 is not a valid date"));
130 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
131 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}),
133 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(
134 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}),
138 int main(int, char**) {
141 #ifndef TEST_HAS_NO_WIDE_CHARACTERS