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
21// class month;
22
23// template<class charT, class traits>
24// basic_ostream<charT, traits>&
25// operator<<(basic_ostream<charT, traits>& os, const month& month);
26
27#include <chrono>
28#include <cassert>
29#include <sstream>
30
31#include "make_string.h"
32#include "platform_support.h" // locale name macros
33#include "test_macros.h"
34#include "assert_macros.h"
35#include "concat_macros.h"
36
37#define SV(S) MAKE_STRING_VIEW(CharT, S)
38
39#define TEST_EQUAL(OUT, EXPECTED) \
40 TEST_REQUIRE(OUT == EXPECTED, \
41 TEST_WRITE_CONCATENATED( \
42 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
43
44template <class CharT>
45static std::basic_string<CharT> stream_c_locale(std::chrono::month month) {
46 std::basic_stringstream<CharT> sstr;
47 sstr << month;
48 return sstr.str();
49}
50
51template <class CharT>
52static std::basic_string<CharT> stream_fr_FR_locale(std::chrono::month month) {
53 std::basic_stringstream<CharT> sstr;
54 const std::locale locale(LOCALE_fr_FR_UTF_8);
55 sstr.imbue(locale);
56 sstr << month;
57 return sstr.str();
58}
59
60template <class CharT>
61static std::basic_string<CharT> stream_ja_JP_locale(std::chrono::month month) {
62 std::basic_stringstream<CharT> sstr;
63 const std::locale locale(LOCALE_ja_JP_UTF_8);
64 sstr.imbue(locale);
65 sstr << month;
66 return sstr.str();
67}
68
69template <class CharT>
70static void test() {
71 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{0}), SV("0 is not a valid month"));
72 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{1}), SV("Jan"));
73 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{2}), SV("Feb"));
74 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{3}), SV("Mar"));
75 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{4}), SV("Apr"));
76 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{5}), SV("May"));
77 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{6}), SV("Jun"));
78 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{7}), SV("Jul"));
79 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{8}), SV("Aug"));
80 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{9}), SV("Sep"));
81 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{10}), SV("Oct"));
82 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{11}), SV("Nov"));
83 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{12}), SV("Dec"));
84 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{13}), SV("13 is not a valid month"));
85 TEST_EQUAL(stream_c_locale<CharT>(std::chrono::month{255}), SV("255 is not a valid month"));
86
87 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{0}), SV("0 is not a valid month"));
88#if defined(__APPLE__)
89 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{1}), SV("jan"));
90 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{2}), SV("fév"));
91 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{3}), SV("mar"));
92 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{4}), SV("avr"));
93 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{5}), SV("mai"));
94 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{6}), SV("jui"));
95 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{7}), SV("jul"));
96 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{8}), SV("aoû"));
97 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{9}), SV("sep"));
98 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{10}), SV("oct"));
99 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{11}), SV("nov"));
100 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{12}), SV("déc"));
101#else // defined(__APPLE__)
102 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{1}), SV("janv."));
103 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{2}), SV("févr."));
104 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{3}), SV("mars"));
105# if defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
106 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{4}), SV("avr."));
107# else
108 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{4}), SV("avril"));
109# endif
110 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{5}), SV("mai"));
111 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{6}), SV("juin"));
112 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{7}), SV("juil."));
113 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{8}), SV("août"));
114 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{9}), SV("sept."));
115 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{10}), SV("oct."));
116 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{11}), SV("nov."));
117 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{12}), SV("déc."));
118#endif // defined(__APPLE__)
119 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{13}), SV("13 is not a valid month"));
120 TEST_EQUAL(stream_fr_FR_locale<CharT>(std::chrono::month{255}), SV("255 is not a valid month"));
121
122 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{0}), SV("0 is not a valid month"));
123#if defined(__APPLE__) || defined(_WIN32)
124# if defined(__APPLE__)
125 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{1}), SV(" 1"));
126 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{2}), SV(" 2"));
127 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{3}), SV(" 3"));
128 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{4}), SV(" 4"));
129 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{5}), SV(" 5"));
130 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{6}), SV(" 6"));
131 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{7}), SV(" 7"));
132 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{8}), SV(" 8"));
133 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{9}), SV(" 9"));
134# else // defined(__APPLE__)
135 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{1}), SV("1"));
136 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{2}), SV("2"));
137 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{3}), SV("3"));
138 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{4}), SV("4"));
139 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{5}), SV("5"));
140 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{6}), SV("6"));
141 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{7}), SV("7"));
142 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{8}), SV("8"));
143 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{9}), SV("9"));
144# endif // defined(__APPLE__)
145 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{10}), SV("10"));
146 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{11}), SV("11"));
147 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{12}), SV("12"));
148#else // defined(__APPLE__)|| defined(_WIN32)
149# if defined(_AIX)
150 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{1}), SV("1月"));
151 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{2}), SV("2月"));
152 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{3}), SV("3月"));
153 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{4}), SV("4月"));
154 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{5}), SV("5月"));
155 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{6}), SV("6月"));
156 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{7}), SV("7月"));
157 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{8}), SV("8月"));
158 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{9}), SV("9月"));
159# else // defined(_AIX)
160 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{1}), SV(" 1月"));
161 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{2}), SV(" 2月"));
162 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{3}), SV(" 3月"));
163 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{4}), SV(" 4月"));
164 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{5}), SV(" 5月"));
165 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{6}), SV(" 6月"));
166 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{7}), SV(" 7月"));
167 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{8}), SV(" 8月"));
168 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{9}), SV(" 9月"));
169# endif // defined(_AIX)
170 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{10}), SV("10月"));
171 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{11}), SV("11月"));
172 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{12}), SV("12月"));
173#endif // defined(__APPLE__)|| defined(_WIN32)
174 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{13}), SV("13 is not a valid month"));
175 TEST_EQUAL(stream_ja_JP_locale<CharT>(std::chrono::month{255}), SV("255 is not a valid month"));
176}
177
178int main(int, char**) {
179 test<char>();
180
181#ifndef TEST_HAS_NO_WIDE_CHARACTERS
182 test<wchar_t>();
183#endif
184
185 return 0;
186}
187

source code of libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/ostream.pass.cpp