[libcxx] [test] Fix the monetary locale curr_symbol test on Windows, Apple and FreeBSD

International currency symbols (like USD, EUR) are returned with a
trailing space, like "USD ", on previously supported Unix platforms.
On Windows, the locales return them without a trailing space.

Also adjust the test for expecting a different unicode sequence for
the national currency symbol for ru_RU.UTF-8 and zh_CN.UTF-8.

Differential Revision: https://reviews.llvm.org/D120547
This commit is contained in:
Martin Storsjö 2022-01-18 09:48:27 +00:00
parent 092f15ac40
commit 1521162d78
1 changed files with 41 additions and 15 deletions

View File

@ -6,13 +6,9 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// XFAIL: darwin
//
// NetBSD does not support LC_MONETARY at the moment // NetBSD does not support LC_MONETARY at the moment
// XFAIL: netbsd // XFAIL: netbsd
// XFAIL: LIBCXX-WINDOWS-FIXME
// REQUIRES: locale.en_US.UTF-8 // REQUIRES: locale.en_US.UTF-8
// REQUIRES: locale.fr_FR.UTF-8 // REQUIRES: locale.fr_FR.UTF-8
// REQUIRES: locale.ru_RU.UTF-8 // REQUIRES: locale.ru_RU.UTF-8
@ -86,28 +82,42 @@ int main(int, char**)
} }
#endif #endif
#ifdef _WIN32
std::string curr_space = "";
#else
std::string curr_space = " ";
#endif
{ {
Fnf f(LOCALE_en_US_UTF_8, 1); Fnf f(LOCALE_en_US_UTF_8, 1);
assert(f.curr_symbol() == "$"); assert(f.curr_symbol() == "$");
} }
{ {
Fnt f(LOCALE_en_US_UTF_8, 1); Fnt f(LOCALE_en_US_UTF_8, 1);
assert(f.curr_symbol() == "USD "); assert(f.curr_symbol() == "USD" + curr_space);
} }
#ifndef TEST_HAS_NO_WIDE_CHARACTERS #ifndef TEST_HAS_NO_WIDE_CHARACTERS
#ifdef _WIN32
std::wstring w_curr_space = L"";
#else
std::wstring w_curr_space = L" ";
#endif
{ {
Fwf f(LOCALE_en_US_UTF_8, 1); Fwf f(LOCALE_en_US_UTF_8, 1);
assert(f.curr_symbol() == L"$"); assert(f.curr_symbol() == L"$");
} }
{ {
Fwt f(LOCALE_en_US_UTF_8, 1); Fwt f(LOCALE_en_US_UTF_8, 1);
assert(f.curr_symbol() == L"USD "); assert(f.curr_symbol() == L"USD" + w_curr_space);
} }
#endif #endif
{ {
Fnf f(LOCALE_fr_FR_UTF_8, 1); Fnf f(LOCALE_fr_FR_UTF_8, 1);
#ifdef __APPLE__
assert(f.curr_symbol() == " Eu");
#else
assert(f.curr_symbol() == " \u20ac"); assert(f.curr_symbol() == " \u20ac");
#endif
} }
{ {
Fnt f(LOCALE_fr_FR_UTF_8, 1); Fnt f(LOCALE_fr_FR_UTF_8, 1);
@ -116,7 +126,11 @@ int main(int, char**)
#ifndef TEST_HAS_NO_WIDE_CHARACTERS #ifndef TEST_HAS_NO_WIDE_CHARACTERS
{ {
Fwf f(LOCALE_fr_FR_UTF_8, 1); Fwf f(LOCALE_fr_FR_UTF_8, 1);
#ifdef __APPLE__
assert(f.curr_symbol() == L" Eu");
#else
assert(f.curr_symbol() == L" \u20ac"); assert(f.curr_symbol() == L" \u20ac");
#endif
} }
{ {
Fwt f(LOCALE_fr_FR_UTF_8, 1); Fwt f(LOCALE_fr_FR_UTF_8, 1);
@ -131,11 +145,13 @@ int main(int, char**)
// GLIBC >= 2.24 uses currency_symbol="<U20BD>" // GLIBC >= 2.24 uses currency_symbol="<U20BD>"
// See also: http://www.fileformat.info/info/unicode/char/20bd/index.htm // See also: http://www.fileformat.info/info/unicode/char/20bd/index.htm
if (!glibc_version_less_than("2.24")) if (!glibc_version_less_than("2.24"))
assert(f.curr_symbol() == " \u20BD"); assert(f.curr_symbol() == " \xE2\x82\xBD"); // \u20BD
else else
assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1"); assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1"); // \u0440\u0443\u0431
#elif defined(_WIN32) || defined(__FreeBSD__)
assert(f.curr_symbol() == " \xE2\x82\xBD"); // \u20BD
#else #else
assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1"); assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1."); // \u0440\u0443\u0431.
#endif #endif
} }
{ {
@ -149,9 +165,11 @@ int main(int, char**)
if (!glibc_version_less_than("2.24")) if (!glibc_version_less_than("2.24"))
assert(f.curr_symbol() == L" \u20BD"); assert(f.curr_symbol() == L" \u20BD");
else else
assert(f.curr_symbol() == L" \x440\x443\x431"); assert(f.curr_symbol() == L" \u0440\u0443\u0431");
#elif defined(_WIN32) || defined(__FreeBSD__)
assert(f.curr_symbol() == L" \u20BD");
#else #else
assert(f.curr_symbol() == L" \x440\x443\x431"); assert(f.curr_symbol() == L" \u0440\u0443\u0431.");
#endif #endif
} }
@ -163,20 +181,28 @@ int main(int, char**)
{ {
Fnf f(LOCALE_zh_CN_UTF_8, 1); Fnf f(LOCALE_zh_CN_UTF_8, 1);
assert(f.curr_symbol() == "\xEF\xBF\xA5"); #ifdef _WIN32
assert(f.curr_symbol() == "\xC2\xA5"); // \u00A5
#else
assert(f.curr_symbol() == "\xEF\xBF\xA5"); // \uFFE5
#endif
} }
{ {
Fnt f(LOCALE_zh_CN_UTF_8, 1); Fnt f(LOCALE_zh_CN_UTF_8, 1);
assert(f.curr_symbol() == "CNY "); assert(f.curr_symbol() == "CNY" + curr_space);
} }
#ifndef TEST_HAS_NO_WIDE_CHARACTERS #ifndef TEST_HAS_NO_WIDE_CHARACTERS
{ {
Fwf f(LOCALE_zh_CN_UTF_8, 1); Fwf f(LOCALE_zh_CN_UTF_8, 1);
assert(f.curr_symbol() == L"\xFFE5"); #ifdef _WIN32
assert(f.curr_symbol() == L"\u00A5");
#else
assert(f.curr_symbol() == L"\uFFE5");
#endif
} }
{ {
Fwt f(LOCALE_zh_CN_UTF_8, 1); Fwt f(LOCALE_zh_CN_UTF_8, 1);
assert(f.curr_symbol() == L"CNY "); assert(f.curr_symbol() == L"CNY" + w_curr_space);
} }
#endif // TEST_HAS_NO_WIDE_CHARACTERS #endif // TEST_HAS_NO_WIDE_CHARACTERS