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

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