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_NUMERIC at the moment |
10 | // XFAIL: netbsd |
11 | |
12 | // XFAIL: LIBCXX-AIX-FIXME |
13 | // XFAIL: LIBCXX-FREEBSD-FIXME |
14 | |
15 | // REQUIRES: locale.en_US.UTF-8 |
16 | // REQUIRES: locale.fr_FR.UTF-8 |
17 | |
18 | // <locale> |
19 | |
20 | // template <class charT> class numpunct_byname; |
21 | |
22 | // char_type thousands_sep() const; |
23 | |
24 | |
25 | #include <locale> |
26 | #include <cassert> |
27 | |
28 | #include "test_macros.h" |
29 | #include "platform_support.h" // locale name macros |
30 | |
31 | int main(int, char**) |
32 | { |
33 | { |
34 | std::locale l("C" ); |
35 | { |
36 | typedef char C; |
37 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(loc: l); |
38 | assert(np.thousands_sep() == ','); |
39 | } |
40 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
41 | { |
42 | typedef wchar_t C; |
43 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(loc: l); |
44 | assert(np.thousands_sep() == L','); |
45 | } |
46 | #endif |
47 | } |
48 | { |
49 | std::locale l(LOCALE_en_US_UTF_8); |
50 | { |
51 | typedef char C; |
52 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l); |
53 | assert(np.thousands_sep() == ','); |
54 | } |
55 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
56 | { |
57 | typedef wchar_t C; |
58 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l); |
59 | assert(np.thousands_sep() == L','); |
60 | } |
61 | #endif |
62 | } |
63 | { |
64 | // The below tests work around GLIBC's use of U202F as LC_NUMERIC thousands_sep. |
65 | std::locale l(LOCALE_fr_FR_UTF_8); |
66 | { |
67 | #if defined(_CS_GNU_LIBC_VERSION) || defined(_WIN32) |
68 | const char sep = ' '; |
69 | #else |
70 | const char sep = ','; |
71 | #endif |
72 | typedef char C; |
73 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l); |
74 | assert(np.thousands_sep() == sep); |
75 | } |
76 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
77 | { |
78 | #if defined(_CS_GNU_LIBC_VERSION) |
79 | const wchar_t wsep = glibc_version_less_than("2.27" ) ? L' ' : L'\u202f'; |
80 | #elif defined(_WIN32) |
81 | const wchar_t wsep = L'\u00A0'; |
82 | #else |
83 | const wchar_t wsep = L','; |
84 | #endif |
85 | typedef wchar_t C; |
86 | const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l); |
87 | assert(np.thousands_sep() == wsep); |
88 | } |
89 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
90 | } |
91 | |
92 | return 0; |
93 | } |
94 | |