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// NetBSD does not support LC_MONETARY at the moment
10// XFAIL: netbsd
11
12// REQUIRES: locale.en_US.UTF-8
13// REQUIRES: locale.fr_FR.UTF-8
14// REQUIRES: locale.ru_RU.UTF-8
15// REQUIRES: locale.zh_CN.UTF-8
16
17// ADDITIONAL_COMPILE_FLAGS: -DFR_MON_THOU_SEP=%{LOCALE_CONV_FR_FR_UTF_8_MON_THOUSANDS_SEP}
18// ADDITIONAL_COMPILE_FLAGS: -DRU_MON_THOU_SEP=%{LOCALE_CONV_RU_RU_UTF_8_MON_THOUSANDS_SEP}
19
20// <locale>
21
22// class moneypunct_byname<charT, International>
23
24// charT thousands_sep() const;
25
26#include <locale>
27#include <limits>
28#include <cassert>
29
30#include "test_macros.h"
31#include "locale_helpers.h"
32#include "platform_support.h" // locale name macros
33
34class Fnf
35 : public std::moneypunct_byname<char, false>
36{
37public:
38 explicit Fnf(const std::string& nm, std::size_t refs = 0)
39 : std::moneypunct_byname<char, false>(nm, refs) {}
40};
41
42class Fnt
43 : public std::moneypunct_byname<char, true>
44{
45public:
46 explicit Fnt(const std::string& nm, std::size_t refs = 0)
47 : std::moneypunct_byname<char, true>(nm, refs) {}
48};
49
50#ifndef TEST_HAS_NO_WIDE_CHARACTERS
51class Fwf
52 : public std::moneypunct_byname<wchar_t, false>
53{
54public:
55 explicit Fwf(const std::string& nm, std::size_t refs = 0)
56 : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
57};
58
59class Fwt
60 : public std::moneypunct_byname<wchar_t, true>
61{
62public:
63 explicit Fwt(const std::string& nm, std::size_t refs = 0)
64 : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
65};
66#endif // TEST_HAS_NO_WIDE_CHARACTERS
67
68int main(int, char**)
69{
70 {
71 Fnf f("C", 1);
72 assert(f.thousands_sep() == std::numeric_limits<char>::max());
73 }
74 {
75 Fnt f("C", 1);
76 assert(f.thousands_sep() == std::numeric_limits<char>::max());
77 }
78#ifndef TEST_HAS_NO_WIDE_CHARACTERS
79 {
80 Fwf f("C", 1);
81 assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
82 }
83 {
84 Fwt f("C", 1);
85 assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
86 }
87#endif
88
89 {
90 Fnf f(LOCALE_en_US_UTF_8, 1);
91 assert(f.thousands_sep() == ',');
92 }
93 {
94 Fnt f(LOCALE_en_US_UTF_8, 1);
95 assert(f.thousands_sep() == ',');
96 }
97#ifndef TEST_HAS_NO_WIDE_CHARACTERS
98 {
99 Fwf f(LOCALE_en_US_UTF_8, 1);
100 assert(f.thousands_sep() == L',');
101 }
102 {
103 Fwt f(LOCALE_en_US_UTF_8, 1);
104 assert(f.thousands_sep() == L',');
105 }
106#endif
107 {
108 Fnf f(LOCALE_fr_FR_UTF_8, 1);
109 assert(f.thousands_sep() == ' ');
110 }
111 {
112 Fnt f(LOCALE_fr_FR_UTF_8, 1);
113 assert(f.thousands_sep() == ' ');
114 }
115
116#ifndef TEST_HAS_NO_WIDE_CHARACTERS
117 const wchar_t fr_sep = LocaleHelpers::mon_thousands_sep_or_default(FR_MON_THOU_SEP);
118
119 {
120 Fwf f(LOCALE_fr_FR_UTF_8, 1);
121 assert(f.thousands_sep() == fr_sep);
122 }
123 {
124 Fwt f(LOCALE_fr_FR_UTF_8, 1);
125 assert(f.thousands_sep() == fr_sep);
126 }
127#endif // TEST_HAS_NO_WIDE_CHARACTERS
128 const char sep = ' ';
129 {
130 Fnf f(LOCALE_ru_RU_UTF_8, 1);
131 assert(f.thousands_sep() == sep);
132 }
133 {
134 Fnt f(LOCALE_ru_RU_UTF_8, 1);
135 assert(f.thousands_sep() == sep);
136 }
137#ifndef TEST_HAS_NO_WIDE_CHARACTERS
138 const wchar_t wsep = LocaleHelpers::mon_thousands_sep_or_default(RU_MON_THOU_SEP);
139
140 {
141 Fwf f(LOCALE_ru_RU_UTF_8, 1);
142 assert(f.thousands_sep() == wsep);
143 }
144 {
145 Fwt f(LOCALE_ru_RU_UTF_8, 1);
146 assert(f.thousands_sep() == wsep);
147 }
148#endif // TEST_HAS_NO_WIDE_CHARACTERS
149
150 {
151 Fnf f(LOCALE_zh_CN_UTF_8, 1);
152 assert(f.thousands_sep() == ',');
153 }
154 {
155 Fnt f(LOCALE_zh_CN_UTF_8, 1);
156 assert(f.thousands_sep() == ',');
157 }
158#ifndef TEST_HAS_NO_WIDE_CHARACTERS
159 {
160 Fwf f(LOCALE_zh_CN_UTF_8, 1);
161 assert(f.thousands_sep() == L',');
162 }
163 {
164 Fwt f(LOCALE_zh_CN_UTF_8, 1);
165 assert(f.thousands_sep() == L',');
166 }
167#endif
168
169 return 0;
170}
171

source code of libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp