137 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 weekday_indexed;21 22// template<class charT, class traits>23// basic_ostream<charT, traits>&24// operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);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 34#define SV(S) MAKE_STRING_VIEW(CharT, S)35 36template <class CharT>37static std::basic_string<CharT> stream_c_locale(std::chrono::weekday_indexed wdi) {38 std::basic_stringstream<CharT> sstr;39 sstr << wdi;40 return sstr.str();41}42 43template <class CharT>44static std::basic_string<CharT> stream_fr_FR_locale(std::chrono::weekday_indexed wdi) {45 std::basic_stringstream<CharT> sstr;46 const std::locale locale(LOCALE_fr_FR_UTF_8);47 sstr.imbue(locale);48 sstr << wdi;49 return sstr.str();50}51 52template <class CharT>53static std::basic_string<CharT> stream_ja_JP_locale(std::chrono::weekday_indexed wdi) {54 std::basic_stringstream<CharT> sstr;55 const std::locale locale(LOCALE_ja_JP_UTF_8);56 sstr.imbue(locale);57 sstr << wdi;58 return sstr.str();59}60 61template <class CharT>62static void test() {63 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(0), 1}) == SV("Sun[1]"));64 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(1), 2}) == SV("Mon[2]"));65 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(2), 3}) == SV("Tue[3]"));66 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(3), 4}) == SV("Wed[4]"));67 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(4), 5}) == SV("Thu[5]"));68 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(5), 0}) ==69 SV("Fri[0 is not a valid index]"));70 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(6), 6}) ==71 SV("Sat[6 is not a valid index]"));72 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(7), 7}) ==73 SV("Sun[7 is not a valid index]"));74 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(8), 0}) ==75 SV("8 is not a valid weekday[0 is not a valid index]"));76 assert(stream_c_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(255), 1}) ==77 SV("255 is not a valid weekday[1]"));78 79#if defined(__APPLE__)80 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(0), 1}) == SV("Dim[1]"));81 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(1), 2}) == SV("Lun[2]"));82 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(2), 3}) == SV("Mar[3]"));83 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(3), 4}) == SV("Mer[4]"));84 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(4), 5}) == SV("Jeu[5]"));85 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(5), 0}) ==86 SV("Ven[0 is not a valid index]"));87 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(6), 6}) ==88 SV("Sam[6 is not a valid index]"));89 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(7), 7}) ==90 SV("Dim[7 is not a valid index]"));91 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(255), 1}) ==92 SV("255 is not a valid weekday[1]"));93#else // defined(__APPLE__)94 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(0), 1}) == SV("dim.[1]"));95 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(1), 2}) == SV("lun.[2]"));96 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(2), 3}) == SV("mar.[3]"));97 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(3), 4}) == SV("mer.[4]"));98 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(4), 5}) == SV("jeu.[5]"));99 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(5), 0}) ==100 SV("ven.[0 is not a valid index]"));101 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(6), 6}) ==102 SV("sam.[6 is not a valid index]"));103 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(7), 7}) ==104 SV("dim.[7 is not a valid index]"));105#endif // defined(__APPLE__)106 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(8), 0}) ==107 SV("8 is not a valid weekday[0 is not a valid index]"));108 assert(stream_fr_FR_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(255), 1}) ==109 SV("255 is not a valid weekday[1]"));110 111 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(0), 1}) == SV("日[1]"));112 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(1), 2}) == SV("月[2]"));113 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(2), 3}) == SV("火[3]"));114 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(3), 4}) == SV("水[4]"));115 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(4), 5}) == SV("木[5]"));116 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(5), 0}) ==117 SV("金[0 is not a valid index]"));118 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(6), 6}) ==119 SV("土[6 is not a valid index]"));120 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(7), 7}) ==121 SV("日[7 is not a valid index]"));122 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(8), 0}) ==123 SV("8 is not a valid weekday[0 is not a valid index]"));124 assert(stream_ja_JP_locale<CharT>(std::chrono::weekday_indexed{std::chrono::weekday(255), 1}) ==125 SV("255 is not a valid weekday[1]"));126}127 128int main(int, char**) {129 test<char>();130 131#ifndef TEST_HAS_NO_WIDE_CHARACTERS132 test<wchar_t>();133#endif134 135 return 0;136}137