1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // NetBSD does not support LC_MONETARY at the moment
13 // REQUIRES: locale.zh_CN.UTF-8
17 // class money_put<charT, OutputIterator>
19 // iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
20 // long double units) const;
22 // TODO For zh_CN GLIBC puts the negative sign after the currency symbol.
29 #include "test_iterators.h"
31 #include "platform_support.h" // locale name macros
33 typedef std::money_put<char, output_iterator<char*> > Fn;
39 explicit my_facet(std::size_t refs = 0)
43 typedef std::money_put<wchar_t, output_iterator<wchar_t*> > Fw;
49 explicit my_facetw(std::size_t refs = 0)
56 std::string loc_name(LOCALE_zh_CN_UTF_8);
57 ios.imbue(std::locale(ios.getloc(),
58 new std::moneypunct_byname<char, false>(loc_name)));
59 ios.imbue(std::locale(ios.getloc(),
60 new std::moneypunct_byname<char, true>(loc_name)));
61 ios.imbue(std::locale(ios.getloc(),
62 new std::moneypunct_byname<wchar_t, false>(loc_name)));
63 ios.imbue(std::locale(ios.getloc(),
64 new std::moneypunct_byname<wchar_t, true>(loc_name)));
71 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
73 std::string ex(str, iter.base());
79 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
81 std::string ex(str, iter.base());
82 assert(ex == "-0.01");
85 long double v = 123456789;
87 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
89 std::string ex(str, iter.base());
90 assert(ex == "1,234,567.89");
93 long double v = -123456789;
95 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
97 std::string ex(str, iter.base());
98 assert(ex == "-1,234,567.89");
104 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
106 std::string ex(str, iter.base());
107 assert(ex == "\xEF\xBF\xA5""0.00");
109 { // negative one, showbase
113 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
115 std::string ex(str, iter.base());
116 assert(ex == "\xEF\xBF\xA5""-0.01");
118 { // positive, showbase
119 long double v = 123456789;
122 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
124 std::string ex(str, iter.base());
125 assert(ex == "\xEF\xBF\xA5""1,234,567.89");
127 { // negative, showbase
128 long double v = -123456789;
131 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
133 std::string ex(str, iter.base());
134 assert(ex == "\xEF\xBF\xA5""-1,234,567.89");
136 { // negative, showbase, left
137 long double v = -123456789;
142 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
144 std::string ex(str, iter.base());
145 assert(ex == "\xEF\xBF\xA5""-1,234,567.89 ");
146 assert(ios.width() == 0);
148 { // negative, showbase, internal
149 long double v = -123456789;
154 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
156 std::string ex(str, iter.base());
157 assert(ex == "\xEF\xBF\xA5""- 1,234,567.89");
158 assert(ios.width() == 0);
160 { // negative, showbase, right
161 long double v = -123456789;
166 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
168 std::string ex(str, iter.base());
169 assert(ex == " \xEF\xBF\xA5""-1,234,567.89");
170 assert(ios.width() == 0);
173 // char, international
175 ios.unsetf(std::ios_base::adjustfield);
179 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
181 std::string ex(str, iter.base());
182 assert(ex == "0.00");
187 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
189 std::string ex(str, iter.base());
190 assert(ex == "-0.01");
193 long double v = 123456789;
195 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
197 std::string ex(str, iter.base());
198 assert(ex == "1,234,567.89");
201 long double v = -123456789;
203 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
205 std::string ex(str, iter.base());
206 assert(ex == "-1,234,567.89");
212 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
214 std::string ex(str, iter.base());
215 assert(ex == "CNY 0.00");
217 { // negative one, showbase
221 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
223 std::string ex(str, iter.base());
224 assert(ex == "CNY -0.01");
226 { // positive, showbase
227 long double v = 123456789;
230 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
232 std::string ex(str, iter.base());
233 assert(ex == "CNY 1,234,567.89");
235 { // negative, showbase
236 long double v = -123456789;
239 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
241 std::string ex(str, iter.base());
242 assert(ex == "CNY -1,234,567.89");
244 { // negative, showbase, left
245 long double v = -123456789;
250 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
252 std::string ex(str, iter.base());
253 assert(ex == "CNY -1,234,567.89 ");
254 assert(ios.width() == 0);
256 { // negative, showbase, internal
257 long double v = -123456789;
262 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
264 std::string ex(str, iter.base());
265 assert(ex == "CNY - 1,234,567.89");
266 assert(ios.width() == 0);
268 { // negative, showbase, right
269 long double v = -123456789;
274 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
276 std::string ex(str, iter.base());
277 assert(ex == " CNY -1,234,567.89");
278 assert(ios.width() == 0);
282 const my_facetw f(1);
285 ios.unsetf(std::ios_base::adjustfield);
289 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
291 std::wstring ex(str, iter.base());
292 assert(ex == L"0.00");
297 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
299 std::wstring ex(str, iter.base());
300 assert(ex == L"-0.01");
303 long double v = 123456789;
305 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
307 std::wstring ex(str, iter.base());
308 assert(ex == L"1,234,567.89");
311 long double v = -123456789;
313 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
315 std::wstring ex(str, iter.base());
316 assert(ex == L"-1,234,567.89");
322 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
324 std::wstring ex(str, iter.base());
325 assert(ex == L"\xFFE5""0.00");
327 { // negative one, showbase
331 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
333 std::wstring ex(str, iter.base());
334 assert(ex == L"\xFFE5""-0.01");
336 { // positive, showbase
337 long double v = 123456789;
340 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
342 std::wstring ex(str, iter.base());
343 assert(ex == L"\xFFE5""1,234,567.89");
345 { // negative, showbase
346 long double v = -123456789;
349 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
351 std::wstring ex(str, iter.base());
352 assert(ex == L"\xFFE5""-1,234,567.89");
354 { // negative, showbase, left
355 long double v = -123456789;
360 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
362 std::wstring ex(str, iter.base());
363 assert(ex == L"\xFFE5""-1,234,567.89 ");
364 assert(ios.width() == 0);
366 { // negative, showbase, internal
367 long double v = -123456789;
372 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
374 std::wstring ex(str, iter.base());
375 assert(ex == L"\xFFE5""- 1,234,567.89");
376 assert(ios.width() == 0);
378 { // negative, showbase, right
379 long double v = -123456789;
384 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
386 std::wstring ex(str, iter.base());
387 assert(ex == L" \xFFE5""-1,234,567.89");
388 assert(ios.width() == 0);
391 // wchar_t, international
393 ios.unsetf(std::ios_base::adjustfield);
397 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
399 std::wstring ex(str, iter.base());
400 assert(ex == L"0.00");
405 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
407 std::wstring ex(str, iter.base());
408 assert(ex == L"-0.01");
411 long double v = 123456789;
413 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
415 std::wstring ex(str, iter.base());
416 assert(ex == L"1,234,567.89");
419 long double v = -123456789;
421 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
423 std::wstring ex(str, iter.base());
424 assert(ex == L"-1,234,567.89");
430 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
432 std::wstring ex(str, iter.base());
433 assert(ex == L"CNY 0.00");
435 { // negative one, showbase
439 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
441 std::wstring ex(str, iter.base());
442 assert(ex == L"CNY -0.01");
444 { // positive, showbase
445 long double v = 123456789;
448 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
450 std::wstring ex(str, iter.base());
451 assert(ex == L"CNY 1,234,567.89");
453 { // negative, showbase
454 long double v = -123456789;
457 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
459 std::wstring ex(str, iter.base());
460 assert(ex == L"CNY -1,234,567.89");
462 { // negative, showbase, left
463 long double v = -123456789;
468 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
470 std::wstring ex(str, iter.base());
471 assert(ex == L"CNY -1,234,567.89 ");
472 assert(ios.width() == 0);
474 { // negative, showbase, internal
475 long double v = -123456789;
480 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
482 std::wstring ex(str, iter.base());
483 assert(ex == L"CNY - 1,234,567.89");
484 assert(ios.width() == 0);
486 { // negative, showbase, right
487 long double v = -123456789;
492 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
494 std::wstring ex(str, iter.base());
495 assert(ex == L" CNY -1,234,567.89");
496 assert(ios.width() == 0);