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