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