brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.8 KiB · 67085a2 Raw
117 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;21 22// template<class charT, class traits>23//   basic_ostream<charT, traits>&24//     operator<<(basic_ostream<charT, traits>& os, const weekday& wd);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 weekday) {38  std::basic_stringstream<CharT> sstr;39  sstr << weekday;40  return sstr.str();41}42 43template <class CharT>44static std::basic_string<CharT> stream_fr_FR_locale(std::chrono::weekday weekday) {45  std::basic_stringstream<CharT> sstr;46  const std::locale locale(LOCALE_fr_FR_UTF_8);47  sstr.imbue(locale);48  sstr << weekday;49  return sstr.str();50}51 52template <class CharT>53static std::basic_string<CharT> stream_ja_JP_locale(std::chrono::weekday weekday) {54  std::basic_stringstream<CharT> sstr;55  const std::locale locale(LOCALE_ja_JP_UTF_8);56  sstr.imbue(locale);57  sstr << weekday;58  return sstr.str();59}60 61template <class CharT>62static void test() {63  assert(stream_c_locale<CharT>(std::chrono::weekday(0)) == SV("Sun"));64  assert(stream_c_locale<CharT>(std::chrono::weekday(1)) == SV("Mon"));65  assert(stream_c_locale<CharT>(std::chrono::weekday(2)) == SV("Tue"));66  assert(stream_c_locale<CharT>(std::chrono::weekday(3)) == SV("Wed"));67  assert(stream_c_locale<CharT>(std::chrono::weekday(4)) == SV("Thu"));68  assert(stream_c_locale<CharT>(std::chrono::weekday(5)) == SV("Fri"));69  assert(stream_c_locale<CharT>(std::chrono::weekday(6)) == SV("Sat"));70  assert(stream_c_locale<CharT>(std::chrono::weekday(7)) == SV("Sun"));71  assert(stream_c_locale<CharT>(std::chrono::weekday(8)) == SV("8 is not a valid weekday"));72  assert(stream_c_locale<CharT>(std::chrono::weekday(255)) == SV("255 is not a valid weekday"));73 74#if defined(__APPLE__)75  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(0)) == SV("Dim"));76  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(1)) == SV("Lun"));77  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(2)) == SV("Mar"));78  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(3)) == SV("Mer"));79  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(4)) == SV("Jeu"));80  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(5)) == SV("Ven"));81  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(6)) == SV("Sam"));82  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(7)) == SV("Dim"));83#else84  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(0)) == SV("dim."));85  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(1)) == SV("lun."));86  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(2)) == SV("mar."));87  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(3)) == SV("mer."));88  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(4)) == SV("jeu."));89  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(5)) == SV("ven."));90  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(6)) == SV("sam."));91  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(7)) == SV("dim."));92#endif93  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(8)) == SV("8 is not a valid weekday"));94  assert(stream_fr_FR_locale<CharT>(std::chrono::weekday(255)) == SV("255 is not a valid weekday"));95 96  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(0)) == SV("日"));97  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(1)) == SV("月"));98  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(2)) == SV("火"));99  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(3)) == SV("水"));100  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(4)) == SV("木"));101  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(5)) == SV("金"));102  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(6)) == SV("土"));103  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(7)) == SV("日"));104  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(8)) == SV("8 is not a valid weekday"));105  assert(stream_ja_JP_locale<CharT>(std::chrono::weekday(255)) == SV("255 is not a valid weekday"));106}107 108int main(int, char**) {109  test<char>();110 111#ifndef TEST_HAS_NO_WIDE_CHARACTERS112  test<wchar_t>();113#endif114 115  return 0;116}117