| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
| // UNSUPPORTED: no-localization | ||
| // UNSUPPORTED: libcpp-has-no-incomplete-format | ||
|
|
||
| // TODO FMT Investigate Windows issues. | ||
| // UNSUPPORTED: msvc, target={{.+}}-windows-gnu | ||
|
|
||
| // TODO FMT It seems GCC uses too much memory in the CI and fails. | ||
| // UNSUPPORTED: gcc-12 | ||
|
|
||
| // REQUIRES: locale.fr_FR.UTF-8 | ||
| // REQUIRES: locale.ja_JP.UTF-8 | ||
|
|
||
| // <chrono> | ||
|
|
||
| // class year_month_weekday_last; | ||
|
|
||
| // template<class charT, class traits> | ||
| // basic_ostream<charT, traits>& | ||
| // operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl); | ||
|
|
||
| #include <chrono> | ||
| #include <cassert> | ||
| #include <sstream> | ||
|
|
||
| #include "make_string.h" | ||
| #include "platform_support.h" // locale name macros | ||
| #include "test_macros.h" | ||
|
|
||
| #define SV(S) MAKE_STRING_VIEW(CharT, S) | ||
|
|
||
| template <class CharT> | ||
| static std::basic_string<CharT> stream_c_locale(std::chrono::year_month_weekday_last ymwdl) { | ||
| std::basic_stringstream<CharT> sstr; | ||
| sstr << ymwdl; | ||
| return sstr.str(); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static std::basic_string<CharT> stream_fr_FR_locale(std::chrono::year_month_weekday_last ymwdl) { | ||
| std::basic_stringstream<CharT> sstr; | ||
| const std::locale locale(LOCALE_fr_FR_UTF_8); | ||
| sstr.imbue(locale); | ||
| sstr << ymwdl; | ||
| return sstr.str(); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static std::basic_string<CharT> stream_ja_JP_locale(std::chrono::year_month_weekday_last ymwdl) { | ||
| std::basic_stringstream<CharT> sstr; | ||
| const std::locale locale(LOCALE_ja_JP_UTF_8); | ||
| sstr.imbue(locale); | ||
| sstr << ymwdl; | ||
| return sstr.str(); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test() { | ||
| assert(stream_c_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/Jan/Sun[last]")); | ||
| assert(stream_c_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/Sun[last]")); | ||
| assert(stream_c_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/Jan/8 is not a valid weekday[last]")); | ||
| assert(stream_c_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/Jan/Sun[last]")); | ||
|
|
||
| assert(stream_c_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/Jan/Sun[last]")); | ||
|
|
||
| #if defined(__APPLE__) | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/jan/Dim[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/Dim[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/jan/8 is not a valid weekday[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/jan/Dim[last]")); | ||
|
|
||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/jan/Dim[last]")); | ||
| #else // defined(__APPLE__) | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/janv./dim.[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/dim.[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/janv./8 is not a valid weekday[last]")); | ||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/janv./dim.[last]")); | ||
|
|
||
| assert(stream_fr_FR_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/janv./dim.[last]")); | ||
| #endif // defined(__APPLE__) | ||
|
|
||
| #if defined(__APPLE__) | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/ 1/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/ 1/8 is not a valid weekday[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/ 1/日[last]")); | ||
|
|
||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/ 1/日[last]")); | ||
| #else // defined(__APPLE__) | ||
| # if defined(_WIN32) || defined(_AIX) | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/1月/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/1月/8 is not a valid weekday[last]")); | ||
|
|
||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/1月/日[last]")); | ||
|
|
||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/1月/日[last]")); | ||
| # else // defined(_WIN32) || defined(_AIX) | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32768 is not a valid year/ 1月/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/0 is not a valid month/日[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}) == | ||
| SV("-32767/ 1月/8 is not a valid weekday[last]")); | ||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32'767}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("-32767/ 1月/日[last]")); | ||
|
|
||
| assert(stream_ja_JP_locale<CharT>(std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{0}}}) == | ||
| SV("1970/ 1月/日[last]")); | ||
| # endif // defined(_WIN32) || defined(_AIX) | ||
| #endif // defined(__APPLE__) | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test<char>(); | ||
|
|
||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,311 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
| // UNSUPPORTED: no-localization | ||
| // UNSUPPORTED: libcpp-has-no-incomplete-format | ||
|
|
||
| // TODO FMT Investigate Windows issues. | ||
| // UNSUPPORTED: msvc, target={{.+}}-windows-gnu | ||
|
|
||
| // TODO FMT It seems GCC uses too much memory in the CI and fails. | ||
| // UNSUPPORTED: gcc-12 | ||
|
|
||
| // REQUIRES: locale.fr_FR.UTF-8 | ||
| // REQUIRES: locale.ja_JP.UTF-8 | ||
|
|
||
| // <chrono> | ||
|
|
||
| // template<class charT> struct formatter<chrono::weekday_last, charT>; | ||
|
|
||
| #include <chrono> | ||
| #include <format> | ||
|
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <locale> | ||
| #include <iostream> | ||
| #include <type_traits> | ||
|
|
||
| #include "formatter_tests.h" | ||
| #include "make_string.h" | ||
| #include "platform_support.h" // locale name macros | ||
| #include "test_macros.h" | ||
|
|
||
| template <class CharT> | ||
| static void test_no_chrono_specs() { | ||
| using namespace std::literals::chrono_literals; | ||
|
|
||
| // Valid day | ||
| check(SV("Sun[last]"), SV("{}"), std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
|
|
||
| // Invalid day | ||
| check(SV("8 is not a valid weekday[last]"), SV("{}"), std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test_valid_values() { | ||
| constexpr std::basic_string_view<CharT> fmt = | ||
| SV("{:%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%t%%a='%a'%t%%A='%A'%n}"); | ||
| constexpr std::basic_string_view<CharT> lfmt = | ||
| SV("{:L%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%t%%a='%a'%t%%A='%A'%n}"); | ||
|
|
||
| const std::locale loc(LOCALE_ja_JP_UTF_8); | ||
| std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); | ||
|
|
||
| // Non localized output using C-locale | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Sun'\t%A='Sunday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='Mon'\t%A='Monday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(1)}); | ||
| check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='Tue'\t%A='Tuesday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(2)}); | ||
| check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='Wed'\t%A='Wednesday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(3)}); | ||
| check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='Thu'\t%A='Thursday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(4)}); | ||
| check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='Fri'\t%A='Friday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(5)}); | ||
| check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='Sat'\t%A='Saturday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(6)}); | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Sun'\t%A='Sunday'\n"), | ||
| fmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(7)}); | ||
|
|
||
| // Use the global locale (fr_FR) | ||
| #if defined(__APPLE__) | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Dim'\t%A='Dimanche'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='Lun'\t%A='Lundi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(1)}); | ||
| check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='Mar'\t%A='Mardi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(2)}); | ||
| check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='Mer'\t%A='Mercredi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(3)}); | ||
| check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='Jeu'\t%A='Jeudi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(4)}); | ||
| check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='Ven'\t%A='Vendredi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(5)}); | ||
| check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='Sam'\t%A='Samedi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(6)}); | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Dim'\t%A='Dimanche'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(7)}); | ||
| #else // defined(__APPLE__) | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='dim.'\t%A='dimanche'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='lun.'\t%A='lundi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(1)}); | ||
| check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='mar.'\t%A='mardi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(2)}); | ||
| check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='mer.'\t%A='mercredi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(3)}); | ||
| check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='jeu.'\t%A='jeudi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(4)}); | ||
| check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='ven.'\t%A='vendredi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(5)}); | ||
| check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='sam.'\t%A='samedi'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(6)}); | ||
| check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='dim.'\t%A='dimanche'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(7)}); | ||
| #endif // defined(__APPLE__) | ||
|
|
||
| // Use supplied locale (ja_JP). | ||
| // This locale has a different alternate, but not on all platforms | ||
| #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) | ||
| check(loc, | ||
| SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='日'\t%A='日曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check(loc, | ||
| SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='月'\t%A='月曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(1)}); | ||
| check(loc, | ||
| SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='火'\t%A='火曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(2)}); | ||
| check(loc, | ||
| SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='水'\t%A='水曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(3)}); | ||
| check(loc, | ||
| SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='木'\t%A='木曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(4)}); | ||
| check(loc, | ||
| SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='金'\t%A='金曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(5)}); | ||
| check(loc, | ||
| SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='土'\t%A='土曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(6)}); | ||
| check(loc, | ||
| SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='日'\t%A='日曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(7)}); | ||
| #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) | ||
| check(loc, | ||
| SV("%u='7'\t%Ou='七'\t%w='0'\t%Ow='〇'\t%a='日'\t%A='日曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check(loc, | ||
| SV("%u='1'\t%Ou='一'\t%w='1'\t%Ow='一'\t%a='月'\t%A='月曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(1)}); | ||
| check(loc, | ||
| SV("%u='2'\t%Ou='二'\t%w='2'\t%Ow='二'\t%a='火'\t%A='火曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(2)}); | ||
| check(loc, | ||
| SV("%u='3'\t%Ou='三'\t%w='3'\t%Ow='三'\t%a='水'\t%A='水曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(3)}); | ||
| check(loc, | ||
| SV("%u='4'\t%Ou='四'\t%w='4'\t%Ow='四'\t%a='木'\t%A='木曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(4)}); | ||
| check(loc, | ||
| SV("%u='5'\t%Ou='五'\t%w='5'\t%Ow='五'\t%a='金'\t%A='金曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(5)}); | ||
| check(loc, | ||
| SV("%u='6'\t%Ou='六'\t%w='6'\t%Ow='六'\t%a='土'\t%A='土曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(6)}); | ||
| check(loc, | ||
| SV("%u='7'\t%Ou='七'\t%w='0'\t%Ow='〇'\t%a='日'\t%A='日曜日'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(7)}); | ||
| #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) | ||
|
|
||
| std::locale::global(std::locale::classic()); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test_invalid_values() { | ||
| // Test that %a and %A throw an exception. | ||
| check_exception("formatting a weekday name needs a valid weekday", | ||
| SV("{:%a}"), | ||
| std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check_exception("formatting a weekday name needs a valid weekday", | ||
| SV("{:%a}"), | ||
| std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
| check_exception("formatting a weekday name needs a valid weekday", | ||
| SV("{:%A}"), | ||
| std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check_exception("formatting a weekday name needs a valid weekday", | ||
| SV("{:%A}"), | ||
| std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| constexpr std::basic_string_view<CharT> fmt = SV("{:%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}"); | ||
| constexpr std::basic_string_view<CharT> lfmt = SV("{:L%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}"); | ||
|
|
||
| const std::locale loc(LOCALE_ja_JP_UTF_8); | ||
| std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); | ||
|
|
||
| #if defined(__APPLE__) | ||
| // Non localized output using C-locale | ||
| check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use the global locale (fr_FR) | ||
| check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use supplied locale (ja_JP). This locale has a different alternate. | ||
| check(loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(loc, | ||
| SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"), | ||
| lfmt, | ||
| std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
| #elif defined(_AIX) // defined(__APPLE__) | ||
| // Non localized output using C-locale | ||
| check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use the global locale (fr_FR) | ||
| check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use supplied locale (ja_JP). This locale has a different alternate. | ||
| check(loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(loc, SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
| #else // defined(__APPLE__) | ||
| // Non localized output using C-locale | ||
| check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), fmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use the global locale (fr_FR) | ||
| check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
|
|
||
| // Use supplied locale (ja_JP). This locale has a different alternate. | ||
| check(loc, SV("%u='1'\t%Ou='一'\t%w='8'\t%Ow='八'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(8)}); | ||
| check(loc, SV("%u='3'\t%Ou='三'\t%w='255'\t%Ow='255'\n"), lfmt, std::chrono::weekday_last{std::chrono::weekday(255)}); | ||
| #endif // defined(__APPLE__) | ||
|
|
||
| std::locale::global(std::locale::classic()); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test() { | ||
| test_no_chrono_specs<CharT>(); | ||
| test_valid_values<CharT>(); | ||
| test_invalid_values<CharT>(); | ||
| check_invalid_types<CharT>({SV("a"), SV("A"), SV("t"), SV("u"), SV("w"), SV("Ou"), SV("Ow")}, | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
|
|
||
| check_exception( | ||
| "Expected '%' or '}' in the chrono format-string", SV("{:A"), std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check_exception("The chrono-specs contains a '{'", SV("{:%%{"), std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check_exception("End of input while parsing the modifier chrono conversion-spec", | ||
| SV("{:%"), | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check_exception( | ||
| "End of input while parsing the modifier E", SV("{:%E"), std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| check_exception( | ||
| "End of input while parsing the modifier O", SV("{:%O"), std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
|
|
||
| // Precision not allowed | ||
| check_exception("Expected '%' or '}' in the chrono format-string", | ||
| SV("{:.3}"), | ||
| std::chrono::weekday_last{std::chrono::weekday(0)}); | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test<char>(); | ||
|
|
||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,288 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
| // UNSUPPORTED: no-localization | ||
| // UNSUPPORTED: libcpp-has-no-incomplete-format | ||
|
|
||
| // TODO FMT It seems GCC uses too much memory in the CI and fails. | ||
| // UNSUPPORTED: gcc-12 | ||
|
|
||
| // REQUIRES: locale.fr_FR.UTF-8 | ||
| // REQUIRES: locale.ja_JP.UTF-8 | ||
|
|
||
| // <chrono> | ||
|
|
||
| // template<class charT> struct formatter<chrono::year_month, charT>; | ||
|
|
||
| #include <chrono> | ||
| #include <format> | ||
|
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <locale> | ||
| #include <iostream> | ||
| #include <type_traits> | ||
|
|
||
| #include "formatter_tests.h" | ||
| #include "make_string.h" | ||
| #include "platform_support.h" // locale name macros | ||
| #include "string_literal.h" | ||
| #include "test_macros.h" | ||
|
|
||
| template <class CharT> | ||
| static void test_no_chrono_specs() { | ||
| // Valid month | ||
| check(SV("1970/Jan"), SV("{}"), std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{1}}); | ||
| check(SV("*1970/Jan*"), SV("{:*^10}"), std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{1}}); | ||
| check(SV("*1970/Jan"), SV("{:*>9}"), std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{1}}); | ||
|
|
||
| // Invalid month_day | ||
| check(SV("1970/0 is not a valid month"), | ||
| SV("{}"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{0}}); | ||
| check(SV("*1970/0 is not a valid month*"), | ||
| SV("{:*^29}"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{0}}); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test_invalid_values() { | ||
| // Test that %b and %B throw an exception. | ||
| check_exception("formatting a month name from an invalid month number", | ||
| SV("{:%b}"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{0}}); | ||
|
|
||
| check_exception("formatting a month name from an invalid month number", | ||
| SV("{:%B}"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::month{0}}); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test_valid_values() { | ||
| constexpr std::basic_string_view<CharT> fmt = SV( | ||
| "{:" | ||
| "%%b='%b'%t" | ||
| "%%B='%B'%t" | ||
| "%%C='%C'%t" | ||
| "%%h='%h'%t" | ||
| "%%y='%y'%t" | ||
| "%%Y='%Y'%t" | ||
| "%%EC='%EC'%t" | ||
| "%%Ey='%Ey'%t" | ||
| "%%EY='%EY'%t" | ||
| "%%Oy='%Oy'%t" | ||
| "%n}"); | ||
|
|
||
| constexpr std::basic_string_view<CharT> lfmt = SV( | ||
| "{:L" | ||
| "%%b='%b'%t" | ||
| "%%B='%B'%t" | ||
| "%%C='%C'%t" | ||
| "%%h='%h'%t" | ||
| "%%y='%y'%t" | ||
| "%%Y='%Y'%t" | ||
| "%%EC='%EC'%t" | ||
| "%%Ey='%Ey'%t" | ||
| "%%EY='%EY'%t" | ||
| "%%Oy='%Oy'%t" | ||
| "%n}"); | ||
|
|
||
| const std::locale loc(LOCALE_ja_JP_UTF_8); | ||
| std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); | ||
|
|
||
| // Non localized output using C-locale | ||
| check(SV("%b='Jan'\t" | ||
| "%B='January'\t" | ||
| "%C='19'\t" | ||
| "%h='Jan'\t" | ||
| "%y='70'\t" | ||
| "%Y='1970'\t" | ||
| "%EC='19'\t" | ||
| "%Ey='70'\t" | ||
| "%EY='1970'\t" | ||
| "%Oy='70'\t" | ||
| "\n"), | ||
| fmt, | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
|
|
||
| check(SV("%b='May'\t" | ||
| "%B='May'\t" | ||
| "%C='20'\t" | ||
| "%h='May'\t" | ||
| "%y='04'\t" | ||
| "%Y='2004'\t" | ||
| "%EC='20'\t" | ||
| "%Ey='04'\t" | ||
| "%EY='2004'\t" | ||
| "%Oy='04'\t" | ||
| "\n"), | ||
| fmt, | ||
| std::chrono::year_month{std::chrono::year{2004}, std::chrono::May}); | ||
|
|
||
| // Use the global locale (fr_FR) | ||
| check(SV( | ||
| #if defined(__APPLE__) | ||
| "%b='jan'\t" | ||
| #else | ||
| "%b='janv.'\t" | ||
| #endif | ||
| "%B='janvier'\t" | ||
| "%C='19'\t" | ||
| #if defined(__APPLE__) | ||
| "%h='jan'\t" | ||
| #else | ||
| "%h='janv.'\t" | ||
| #endif | ||
| "%y='70'\t" | ||
| "%Y='1970'\t" | ||
| "%EC='19'\t" | ||
| "%Ey='70'\t" | ||
| "%EY='1970'\t" | ||
| "%Oy='70'\t" | ||
| "\n"), | ||
| lfmt, | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
|
|
||
| check(SV("%b='mai'\t" | ||
| "%B='mai'\t" | ||
| "%C='20'\t" | ||
| "%h='mai'\t" | ||
| "%y='04'\t" | ||
| "%Y='2004'\t" | ||
| "%EC='20'\t" | ||
| "%Ey='04'\t" | ||
| "%EY='2004'\t" | ||
| "%Oy='04'\t" | ||
| "\n"), | ||
| lfmt, | ||
| std::chrono::year_month{std::chrono::year{2004}, std::chrono::May}); | ||
|
|
||
| // Use supplied locale (ja_JP) | ||
| check(loc, | ||
| SV( | ||
| #if defined(_WIN32) | ||
| "%b='1'\t" | ||
| #elif defined(_AIX) // defined(_WIN32) | ||
| "%b='1月'\t" | ||
| #elif defined(__APPLE__) // defined(_WIN32) | ||
| "%b=' 1'\t" | ||
| #else // defined(_WIN32) | ||
| "%b=' 1月'\t" | ||
| #endif // defined(_WIN32) | ||
| "%B='1月'\t" | ||
| "%C='19'\t" | ||
| #if defined(_WIN32) | ||
| "%h='1'\t" | ||
| #elif defined(_AIX) // defined(_WIN32) | ||
| "%h='1月'\t" | ||
| #elif defined(__APPLE__) // defined(_WIN32) | ||
| "%h=' 1'\t" | ||
| #else // defined(_WIN32) | ||
| "%h=' 1月'\t" | ||
| #endif // defined(_WIN32) | ||
| "%y='70'\t" | ||
| "%Y='1970'\t" | ||
| #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "%EC='19'\t" | ||
| "%Ey='70'\t" | ||
| "%EY='1970'\t" | ||
| "%Oy='70'\t" | ||
| #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "%EC='昭和'\t" | ||
| "%Ey='45'\t" | ||
| "%EY='昭和45年'\t" | ||
| "%Oy='七十'\t" | ||
| #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "\n"), | ||
| lfmt, | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
|
|
||
| check(loc, | ||
| SV( | ||
|
|
||
| #if defined(_WIN32) | ||
| "%b='5'\t" | ||
| #elif defined(_AIX) // defined(_WIN32) | ||
| "%b='5月'\t" | ||
| #elif defined(__APPLE__) // defined(_WIN32) | ||
| "%b=' 5'\t" | ||
| #else // defined(_WIN32) | ||
| "%b=' 5月'\t" | ||
| #endif // defined(_WIN32) | ||
| "%B='5月'\t" | ||
| "%C='20'\t" | ||
| #if defined(_WIN32) | ||
| "%h='5'\t" | ||
| #elif defined(_AIX) // defined(_WIN32) | ||
| "%h='5月'\t" | ||
| #elif defined(__APPLE__) // defined(_WIN32) | ||
| "%h=' 5'\t" | ||
| #else // defined(_WIN32) | ||
| "%h=' 5月'\t" | ||
| #endif // defined(_WIN32) | ||
| "%y='04'\t" | ||
| "%Y='2004'\t" | ||
| #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "%EC='20'\t" | ||
| "%Ey='04'\t" | ||
| "%EY='2004'\t" | ||
| "%Oy='04'\t" | ||
| #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "%EC='平成'\t" | ||
| "%Ey='16'\t" | ||
| "%EY='平成16年'\t" | ||
| "%Oy='四'\t" | ||
| #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) | ||
| "\n"), | ||
| lfmt, | ||
| std::chrono::year_month{std::chrono::year{2004}, std::chrono::May}); | ||
|
|
||
| std::locale::global(std::locale::classic()); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test() { | ||
| test_no_chrono_specs<CharT>(); | ||
| test_invalid_values<CharT>(); | ||
| test_valid_values<CharT>(); | ||
|
|
||
| check_invalid_types<CharT>( | ||
| {SV("b"), SV("B"), SV("C"), SV("EC"), SV("Ey"), SV("EY"), SV("h"), SV("m"), SV("Om"), SV("Oy"), SV("y"), SV("Y")}, | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
|
|
||
| check_exception("Expected '%' or '}' in the chrono format-string", | ||
| SV("{:A"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
| check_exception("The chrono-specs contains a '{'", | ||
| SV("{:%%{"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
| check_exception("End of input while parsing the modifier chrono conversion-spec", | ||
| SV("{:%"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
| check_exception("End of input while parsing the modifier E", | ||
| SV("{:%E"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
| check_exception("End of input while parsing the modifier O", | ||
| SV("{:%O"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
|
|
||
| // Precision not allowed | ||
| check_exception("Expected '%' or '}' in the chrono format-string", | ||
| SV("{:.3}"), | ||
| std::chrono::year_month{std::chrono::year{1970}, std::chrono::January}); | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test<char>(); | ||
|
|
||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
| // UNSUPPORTED: no-localization | ||
| // UNSUPPORTED: libcpp-has-no-incomplete-format | ||
|
|
||
| // TODO FMT It seems GCC uses too much memory in the CI and fails. | ||
| // UNSUPPORTED: gcc-12 | ||
|
|
||
| // REQUIRES: locale.fr_FR.UTF-8 | ||
| // REQUIRES: locale.ja_JP.UTF-8 | ||
|
|
||
| // <chrono> | ||
|
|
||
| // template<class charT> struct formatter<chrono::year_month_weekday_last, charT>; | ||
|
|
||
| #include <chrono> | ||
| #include <format> | ||
|
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <locale> | ||
| #include <iostream> | ||
| #include <type_traits> | ||
|
|
||
| #include "formatter_tests.h" | ||
| #include "make_string.h" | ||
| #include "platform_support.h" // locale name macros | ||
| #include "string_literal.h" | ||
| #include "test_macros.h" | ||
|
|
||
| template <class CharT> | ||
| static void test_no_chrono_specs() { | ||
| // Valid | ||
| check(SV("1970/Jan/Mon[last]"), | ||
| SV("{}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("*1970/Jan/Mon[last]*"), | ||
| SV("{:*^20}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("*1970/Jan/Mon[last]"), | ||
| SV("{:*>19}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Invalid | ||
| check(SV("1970/Jan/8 is not a valid weekday[last]"), | ||
| SV("{}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check(SV("1970/0 is not a valid month/Mon[last]"), | ||
| SV("{}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("-32768 is not a valid year/Jan/Mon[last]"), | ||
| SV("{}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test_invalid_values() { | ||
| // *** Invalid weekday *** | ||
|
|
||
| // Weekday name conversion | ||
| check_exception( | ||
| "formatting a weekday name needs a valid weekday", | ||
| SV("{:%a}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check_exception( | ||
| "formatting a weekday name needs a valid weekday", | ||
| SV("{:%A}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
|
|
||
| // Weekday conversion | ||
| check_exception( | ||
| "formatting a weekday needs a valid weekday", | ||
| SV("{:%u}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check_exception( | ||
| "formatting a weekday needs a valid weekday", | ||
| SV("{:%w}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check_exception( | ||
| "formatting a weekday needs a valid weekday", | ||
| SV("{:%Ou}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check_exception( | ||
| "formatting a weekday needs a valid weekday", | ||
| SV("{:%Ow}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
|
|
||
| // Day of year field | ||
| check_exception( | ||
| "formatting a day of year needs a valid date", | ||
| SV("{:%j}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
|
|
||
| // Month name conversion | ||
| check(SV("Jan"), | ||
| SV("{:%b}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check(SV("Jan"), | ||
| SV("{:%h}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
| check(SV("January"), | ||
| SV("{:%B}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}}); | ||
|
|
||
| // *** Invalid month *** | ||
|
|
||
| // Weekday name conversion | ||
| check(SV("Mon"), | ||
| SV("{:%a}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("Monday"), | ||
| SV("{:%A}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| // Weekday conversion | ||
| check(SV("1"), | ||
| SV("{:%u}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%w}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%Ou}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%Ow}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Day of year field | ||
| check_exception( | ||
| "formatting a day of year needs a valid date", | ||
| SV("{:%j}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Month name conversion | ||
| check_exception( | ||
| "formatting a month name from an invalid month number", | ||
| SV("{:%b}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check_exception( | ||
| "formatting a month name from an invalid month number", | ||
| SV("{:%h}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check_exception( | ||
| "formatting a month name from an invalid month number", | ||
| SV("{:%B}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // *** Invalid year *** | ||
|
|
||
| // Weekday name conversion | ||
| check(SV("Mon"), | ||
| SV("{:%a}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("Monday"), | ||
| SV("{:%A}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Weekday conversion | ||
| check(SV("1"), | ||
| SV("{:%u}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%w}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%Ou}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("1"), | ||
| SV("{:%Ow}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Day of year field | ||
| check_exception( | ||
| "formatting a day of year needs a valid date", | ||
| SV("{:%j}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
|
|
||
| // Month name conversion | ||
| check(SV("Jan"), | ||
| SV("{:%b}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("Jan"), | ||
| SV("{:%h}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| check(SV("January"), | ||
| SV("{:%B}"), | ||
| std::chrono::year_month_weekday_last{ | ||
| std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}}); | ||
| } | ||
|
|
||
| template <class CharT> | ||
| static void test() { | ||
| test_no_chrono_specs<CharT>(); | ||
| test_invalid_values<CharT>(); | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test<char>(); | ||
|
|
||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |