| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | // UNSUPPORTED: no-localization |
| 11 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 12 | |
| 13 | // TODO FMT This test should not require std::to_chars(floating-point) |
| 14 | // XFAIL: availability-fp_to_chars-missing |
| 15 | |
| 16 | // REQUIRES: locale.fr_FR.UTF-8 |
| 17 | // REQUIRES: locale.ja_JP.UTF-8 |
| 18 | |
| 19 | // <chrono> |
| 20 | |
| 21 | // class year_month_weekday; |
| 22 | |
| 23 | // template<class charT, class traits> |
| 24 | // basic_ostream<charT, traits>& |
| 25 | // operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd); |
| 26 | |
| 27 | #include <chrono> |
| 28 | #include <cassert> |
| 29 | #include <sstream> |
| 30 | |
| 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" |
| 36 | |
| 37 | #define SV(S) MAKE_STRING_VIEW(CharT, S) |
| 38 | |
| 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')); |
| 43 | |
| 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; |
| 47 | sstr << ymwd; |
| 48 | return sstr.str(); |
| 49 | } |
| 50 | |
| 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); |
| 55 | sstr.imbue(locale); |
| 56 | sstr << ymwd; |
| 57 | return sstr.str(); |
| 58 | } |
| 59 | |
| 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); |
| 64 | sstr.imbue(locale); |
| 65 | sstr << ymwd; |
| 66 | return sstr.str(); |
| 67 | } |
| 68 | |
| 69 | template <class CharT> |
| 70 | static void test() { |
| 71 | TEST_EQUAL( |
| 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]" )); |
| 75 | TEST_EQUAL( |
| 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]" )); |
| 79 | TEST_EQUAL( |
| 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]" )); |
| 83 | TEST_EQUAL( |
| 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... |
| 87 | TEST_EQUAL( |
| 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]" )); |
| 91 | |
| 92 | TEST_EQUAL( |
| 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]" )); |
| 96 | |
| 97 | #if defined(__APPLE__) |
| 98 | TEST_EQUAL( |
| 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]" )); |
| 102 | TEST_EQUAL( |
| 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]" )); |
| 106 | TEST_EQUAL( |
| 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]" )); |
| 110 | TEST_EQUAL( |
| 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... |
| 114 | TEST_EQUAL( |
| 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]" )); |
| 118 | |
| 119 | TEST_EQUAL( |
| 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__) |
| 124 | TEST_EQUAL( |
| 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]" )); |
| 128 | TEST_EQUAL( |
| 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]" )); |
| 132 | TEST_EQUAL( |
| 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]" )); |
| 136 | TEST_EQUAL( |
| 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... |
| 140 | TEST_EQUAL( |
| 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]" )); |
| 144 | |
| 145 | TEST_EQUAL( |
| 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__) |
| 150 | |
| 151 | #if defined(__APPLE__) |
| 152 | TEST_EQUAL( |
| 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]" )); |
| 156 | TEST_EQUAL( |
| 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]" )); |
| 160 | TEST_EQUAL( |
| 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]" )); |
| 164 | TEST_EQUAL( |
| 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... |
| 168 | TEST_EQUAL( |
| 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]" )); |
| 172 | TEST_EQUAL( |
| 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}}), |
| 175 | SV("1970/ 1/日[1]" )); |
| 176 | #elif defined(_WIN32) // defined(__APPLE__) |
| 177 | TEST_EQUAL( |
| 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]" )); |
| 181 | TEST_EQUAL( |
| 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]" )); |
| 185 | TEST_EQUAL( |
| 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]" )); |
| 189 | TEST_EQUAL( |
| 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... |
| 193 | TEST_EQUAL( |
| 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]" )); |
| 197 | |
| 198 | TEST_EQUAL( |
| 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}}), |
| 201 | SV("1970/1/日[1]" )); |
| 202 | #elif defined(_AIX) // defined(__APPLE__) |
| 203 | TEST_EQUAL( |
| 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]" )); |
| 207 | TEST_EQUAL( |
| 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]" )); |
| 211 | TEST_EQUAL( |
| 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]" )); |
| 215 | |
| 216 | TEST_EQUAL( |
| 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... |
| 220 | TEST_EQUAL( |
| 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]" )); |
| 224 | |
| 225 | TEST_EQUAL( |
| 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}}), |
| 228 | SV("1970/1月/日[1]" )); |
| 229 | #else // defined(__APPLE__) |
| 230 | TEST_EQUAL( |
| 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]" )); |
| 234 | TEST_EQUAL( |
| 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]" )); |
| 238 | TEST_EQUAL( |
| 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]" )); |
| 242 | TEST_EQUAL( |
| 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... |
| 246 | TEST_EQUAL( |
| 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]" )); |
| 250 | |
| 251 | TEST_EQUAL( |
| 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__) |
| 256 | } |
| 257 | |
| 258 | int main(int, char**) { |
| 259 | test<char>(); |
| 260 | |
| 261 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 262 | test<wchar_t>(); |
| 263 | #endif |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |