brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · b545909 Raw
98 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710// UNSUPPORTED: no-localization11// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME12 13// TODO FMT This test should not require std::to_chars(floating-point)14// XFAIL: availability-fp_to_chars-missing15 16// REQUIRES: locale.fr_FR.UTF-817// REQUIRES: locale.ja_JP.UTF-818 19// <chrono>20// class year;21 22// template<class charT, class traits>23//   basic_ostream<charT, traits>&24//     operator<<(basic_ostream<charT, traits>& os, const year& year);25 26#include <chrono>27#include <cassert>28#include <sstream>29 30#include "make_string.h"31#include "platform_support.h" // locale name macros32#include "test_macros.h"33#include "assert_macros.h"34#include "concat_macros.h"35 36#define SV(S) MAKE_STRING_VIEW(CharT, S)37 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'));42 43template <class CharT>44static std::basic_string<CharT> stream_c_locale(std::chrono::year year) {45  std::basic_stringstream<CharT> sstr;46  sstr << year;47  return sstr.str();48}49 50template <class CharT>51static 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);54  sstr.imbue(locale);55  sstr << year;56  return sstr.str();57}58 59template <class CharT>60static 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);63  sstr.imbue(locale);64  sstr << year;65  return sstr.str();66}67 68template <class CharT>69static void test() {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"));75 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"));81 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"));87}88 89int main(int, char**) {90  test<char>();91 92#ifndef TEST_HAS_NO_WIDE_CHARACTERS93  test<wchar_t>();94#endif95 96  return 0;97}98