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
22 // template<class charT, class traits>
23 // basic_ostream<charT, traits>&
24 // operator<<(basic_ostream<charT, traits>& os, const year& year);
30 #include "make_string.h"
31 #include "platform_support.h" // locale name macros
32 #include "test_macros.h"
33 #include "assert_macros.h"
34 #include "concat_macros.h"
36 #define SV(S) MAKE_STRING_VIEW(CharT, S)
38 #define TEST_EQUAL(OUT, EXPECTED) \
39 TEST_REQUIRE(OUT == EXPECTED, \
40 TEST_WRITE_CONCATENATED( \
41 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
43 template <class CharT
>
44 static std::basic_string
<CharT
> stream_c_locale(std::chrono::year year
) {
45 std::basic_stringstream
<CharT
> sstr
;
50 template <class CharT
>
51 static std::basic_string
<CharT
> stream_fr_FR_locale(std::chrono::year year
) {
52 std::basic_stringstream
<CharT
> sstr
;
53 const std::locale
locale(LOCALE_fr_FR_UTF_8
);
59 template <class CharT
>
60 static std::basic_string
<CharT
> stream_ja_JP_locale(std::chrono::year year
) {
61 std::basic_stringstream
<CharT
> sstr
;
62 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
68 template <class CharT
>
70 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::year
{-32'768}), SV("-32768 is not a valid year"));
71 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::year
{-32'767}), SV("-32767"));
72 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::year
{0}), SV("0000"));
73 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::year
{1970}), SV("1970"));
74 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::year
{32'767}), SV("32767"));
76 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::year
{-32'768}), SV("-32768 is not a valid year"));
77 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::year
{-32'767}), SV("-32767"));
78 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::year
{0}), SV("0000"));
79 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::year
{1970}), SV("1970"));
80 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::year
{32'767}), SV("32767"));
82 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::year
{-32'768}), SV("-32768 is not a valid year"));
83 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::year
{-32'767}), SV("-32767"));
84 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::year
{0}), SV("0000"));
85 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::year
{1970}), SV("1970"));
86 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::year
{32'767}), SV("32767"));
89 int main(int, char**) {
92 #ifndef TEST_HAS_NO_WIDE_CHARACTERS