]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / localization / locale.categories / category.monetary / locale.moneypunct.byname / thousands_sep.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // REQUIRES: locale.en_US.UTF-8
11 // REQUIRES: locale.fr_FR.UTF-8
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14
15 // <locale>
16
17 // class moneypunct_byname<charT, International>
18
19 // charT thousands_sep() const;
20
21 #include <locale>
22 #include <limits>
23 #include <cassert>
24
25 #include "test_macros.h"
26 #include "platform_support.h" // locale name macros
27
28 class Fnf
29     : public std::moneypunct_byname<char, false>
30 {
31 public:
32     explicit Fnf(const std::string& nm, std::size_t refs = 0)
33         : std::moneypunct_byname<char, false>(nm, refs) {}
34 };
35
36 class Fnt
37     : public std::moneypunct_byname<char, true>
38 {
39 public:
40     explicit Fnt(const std::string& nm, std::size_t refs = 0)
41         : std::moneypunct_byname<char, true>(nm, refs) {}
42 };
43
44 class Fwf
45     : public std::moneypunct_byname<wchar_t, false>
46 {
47 public:
48     explicit Fwf(const std::string& nm, std::size_t refs = 0)
49         : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
50 };
51
52 class Fwt
53     : public std::moneypunct_byname<wchar_t, true>
54 {
55 public:
56     explicit Fwt(const std::string& nm, std::size_t refs = 0)
57         : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
58 };
59
60 int main()
61 {
62     {
63         Fnf f("C", 1);
64         assert(f.thousands_sep() == std::numeric_limits<char>::max());
65     }
66     {
67         Fnt f("C", 1);
68         assert(f.thousands_sep() == std::numeric_limits<char>::max());
69     }
70     {
71         Fwf f("C", 1);
72         assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
73     }
74     {
75         Fwt f("C", 1);
76         assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
77     }
78
79     {
80         Fnf f(LOCALE_en_US_UTF_8, 1);
81         assert(f.thousands_sep() == ',');
82     }
83     {
84         Fnt f(LOCALE_en_US_UTF_8, 1);
85         assert(f.thousands_sep() == ',');
86     }
87     {
88         Fwf f(LOCALE_en_US_UTF_8, 1);
89         assert(f.thousands_sep() == L',');
90     }
91     {
92         Fwt f(LOCALE_en_US_UTF_8, 1);
93         assert(f.thousands_sep() == L',');
94     }
95
96     {
97         Fnf f(LOCALE_fr_FR_UTF_8, 1);
98         assert(f.thousands_sep() == ' ');
99     }
100     {
101         Fnt f(LOCALE_fr_FR_UTF_8, 1);
102         assert(f.thousands_sep() == ' ');
103     }
104     {
105         Fwf f(LOCALE_fr_FR_UTF_8, 1);
106         assert(f.thousands_sep() == L' ');
107     }
108     {
109         Fwt f(LOCALE_fr_FR_UTF_8, 1);
110         assert(f.thousands_sep() == L' ');
111     }
112 // The below tests work around GLIBC's use of U00A0 as mon_thousands_sep
113 // and U002E as mon_decimal_point.
114 // TODO: Fix thousands_sep for 'char'.
115 // related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16006
116 #ifndef TEST_HAS_GLIBC
117     const char sep = ' ';
118     const wchar_t wsep = L' ';
119 #else
120     // FIXME libc++ specifically works around \u00A0 by translating it into
121     // a regular space.
122     const char sep = ' ';
123     const wchar_t wsep = L'\u00A0';
124 #endif
125     {
126         Fnf f(LOCALE_ru_RU_UTF_8, 1);
127         assert(f.thousands_sep() == sep);
128     }
129     {
130         Fnt f(LOCALE_ru_RU_UTF_8, 1);
131         assert(f.thousands_sep() == sep);
132     }
133     {
134         Fwf f(LOCALE_ru_RU_UTF_8, 1);
135         assert(f.thousands_sep() == wsep);
136     }
137     {
138         Fwt f(LOCALE_ru_RU_UTF_8, 1);
139         assert(f.thousands_sep() == wsep);
140     }
141
142     {
143         Fnf f(LOCALE_zh_CN_UTF_8, 1);
144         assert(f.thousands_sep() == ',');
145     }
146     {
147         Fnt f(LOCALE_zh_CN_UTF_8, 1);
148         assert(f.thousands_sep() == ',');
149     }
150     {
151         Fwf f(LOCALE_zh_CN_UTF_8, 1);
152         assert(f.thousands_sep() == L',');
153     }
154     {
155         Fwt f(LOCALE_zh_CN_UTF_8, 1);
156         assert(f.thousands_sep() == L',');
157     }
158 }