[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.cal / time.cal.ymd / time.cal.ymd.nonmembers / ostream.pass.cpp
blobffc737fcad5dd26e266a20a780f30987b4b43574
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 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);
30 #include <chrono>
31 #include <cassert>
32 #include <sstream>
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;
50 sstr << ymd;
51 return sstr.str();
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);
58 sstr.imbue(locale);
59 sstr << ymd;
60 return sstr.str();
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);
67 sstr.imbue(locale);
68 sstr << ymd;
69 return sstr.str();
72 template <class CharT>
73 static void test() {
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}}),
85 SV("1970-01-01"));
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}}),
91 SV("2000-02-29"));
93 #if defined(_AIX)
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}}),
96 SV("+32767-12-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}}),
100 SV(""));
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}}),
104 SV("32767-12-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}}),
118 SV("1970-01-01"));
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}}),
124 SV("2000-02-29"));
125 #if defined(_AIX)
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}}),
128 SV("+32767-12-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}}),
132 SV(""));
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}}),
136 SV("32767-12-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}}),
150 SV("1970-01-01"));
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}}),
156 SV("2000-02-29"));
157 #if defined(_AIX)
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}}),
160 SV("+32767-12-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}}),
164 SV(""));
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}}),
168 SV("32767-12-31"));
169 #endif // defined(_AIX)
172 int main(int, char**) {
173 test<char>();
175 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
176 test<wchar_t>();
177 #endif
179 return 0;