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 decimal_point() 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
28class Fnf
29    : public std::moneypunct_byname<char, false>
30{
31public:
32    explicit Fnf(const std::string& nm, std::size_t refs = 0)
33        : std::moneypunct_byname<char, false>(nm, refs) {}
34};
35
36class Fnt
37    : public std::moneypunct_byname<char, true>
38{
39public:
40    explicit Fnt(const std::string& nm, std::size_t refs = 0)
41        : std::moneypunct_byname<char, true>(nm, refs) {}
42};
43
44class Fwf
45    : public std::moneypunct_byname<wchar_t, false>
46{
47public:
48    explicit Fwf(const std::string& nm, std::size_t refs = 0)
49        : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
50};
51
52class Fwt
53    : public std::moneypunct_byname<wchar_t, true>
54{
55public:
56    explicit Fwt(const std::string& nm, std::size_t refs = 0)
57        : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
58};
59
60int main()
61{
62    {
63        Fnf f("C", 1);
64        assert(f.decimal_point() == std::numeric_limits<char>::max());
65    }
66    {
67        Fnt f("C", 1);
68        assert(f.decimal_point() == std::numeric_limits<char>::max());
69    }
70    {
71        Fwf f("C", 1);
72        assert(f.decimal_point() == std::numeric_limits<wchar_t>::max());
73    }
74    {
75        Fwt f("C", 1);
76        assert(f.decimal_point() == std::numeric_limits<wchar_t>::max());
77    }
78
79    {
80        Fnf f(LOCALE_en_US_UTF_8, 1);
81        assert(f.decimal_point() == '.');
82    }
83    {
84        Fnt f(LOCALE_en_US_UTF_8, 1);
85        assert(f.decimal_point() == '.');
86    }
87    {
88        Fwf f(LOCALE_en_US_UTF_8, 1);
89        assert(f.decimal_point() == L'.');
90    }
91    {
92        Fwt f(LOCALE_en_US_UTF_8, 1);
93        assert(f.decimal_point() == L'.');
94    }
95
96    {
97        Fnf f(LOCALE_fr_FR_UTF_8, 1);
98        assert(f.decimal_point() == ',');
99    }
100    {
101        Fnt f(LOCALE_fr_FR_UTF_8, 1);
102        assert(f.decimal_point() == ',');
103    }
104    {
105        Fwf f(LOCALE_fr_FR_UTF_8, 1);
106        assert(f.decimal_point() == L',');
107    }
108    {
109        Fwt f(LOCALE_fr_FR_UTF_8, 1);
110        assert(f.decimal_point() == L',');
111    }
112// GLIBC 2.23 uses '.' as the decimal point while other C libraries use ','
113#ifndef TEST_HAS_GLIBC
114    const char sep = ',';
115    const wchar_t wsep = L',';
116#else
117    const char sep = '.';
118    const wchar_t wsep = L'.';
119#endif
120    {
121        Fnf f(LOCALE_ru_RU_UTF_8, 1);
122        assert(f.decimal_point() == sep);
123    }
124    {
125        Fnt f(LOCALE_ru_RU_UTF_8, 1);
126        assert(f.decimal_point() == sep);
127    }
128    {
129        Fwf f(LOCALE_ru_RU_UTF_8, 1);
130        assert(f.decimal_point() == wsep);
131    }
132    {
133        Fwt f(LOCALE_ru_RU_UTF_8, 1);
134        assert(f.decimal_point() == wsep);
135    }
136
137    {
138        Fnf f(LOCALE_zh_CN_UTF_8, 1);
139        assert(f.decimal_point() == '.');
140    }
141    {
142        Fnt f(LOCALE_zh_CN_UTF_8, 1);
143        assert(f.decimal_point() == '.');
144    }
145    {
146        Fwf f(LOCALE_zh_CN_UTF_8, 1);
147        assert(f.decimal_point() == L'.');
148    }
149    {
150        Fwt f(LOCALE_zh_CN_UTF_8, 1);
151        assert(f.decimal_point() == L'.');
152    }
153}
154