Skip to content

Commit

Permalink
[libcxx] [test] Fix en_US money locale formatting tests on Windows
Browse files Browse the repository at this point in the history
In the en_US locale on Windows, negative currency amounts is formatted
as "($0.01)" instead of "-$0.01".

Adjust the test references accordingly, making these tests pass.

Differential Revision: https://reviews.llvm.org/D120798
  • Loading branch information
mstorsjo committed Mar 2, 2022
1 parent 3ba6643 commit 1425011
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 7 deletions.
Expand Up @@ -12,8 +12,6 @@

// REQUIRES: locale.en_US.UTF-8

// XFAIL: LIBCXX-WINDOWS-FIXME

#include <iomanip>
#include <istream>
#include <cassert>
Expand Down Expand Up @@ -44,15 +42,23 @@ struct testbuf
int main(int, char**)
{
{
#if defined(_WIN32)
testbuf<char> sb(" ($1,234,567.89)");
#else
testbuf<char> sb(" -$1,234,567.89");
#endif
std::istream is(&sb);
is.imbue(std::locale(LOCALE_en_US_UTF_8));
long double x = 0;
is >> std::get_money(x, false);
assert(x == -123456789);
}
{
#if defined(_WIN32)
testbuf<char> sb(" (USD 1,234,567.89)");
#else
testbuf<char> sb(" -USD 1,234,567.89");
#endif
std::istream is(&sb);
is.imbue(std::locale(LOCALE_en_US_UTF_8));
long double x = 0;
Expand All @@ -61,15 +67,23 @@ int main(int, char**)
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
#if defined(_WIN32)
testbuf<wchar_t> sb(L" ($1,234,567.89)");
#else
testbuf<wchar_t> sb(L" -$1,234,567.89");
#endif
std::wistream is(&sb);
is.imbue(std::locale(LOCALE_en_US_UTF_8));
long double x = 0;
is >> std::get_money(x, false);
assert(x == -123456789);
}
{
#if defined(_WIN32)
testbuf<wchar_t> sb(L" (USD 1,234,567.89)");
#else
testbuf<wchar_t> sb(L" -USD 1,234,567.89");
#endif
std::wistream is(&sb);
is.imbue(std::locale(LOCALE_en_US_UTF_8));
long double x = 0;
Expand Down
Expand Up @@ -12,8 +12,6 @@

// REQUIRES: locale.en_US.UTF-8

// XFAIL: LIBCXX-WINDOWS-FIXME

#include <iomanip>
#include <ostream>
#include <cassert>
Expand Down Expand Up @@ -62,7 +60,11 @@ int main(int, char**)
std::showbase(os);
long double x = -123456789;
os << std::put_money(x, false);
#if defined(_WIN32)
assert(sb.str() == "($1,234,567.89)");
#else
assert(sb.str() == "-$1,234,567.89");
#endif
}
{
testbuf<char> sb;
Expand All @@ -71,7 +73,11 @@ int main(int, char**)
std::showbase(os);
long double x = -123456789;
os << std::put_money(x, true);
#if defined(_WIN32)
assert(sb.str() == "(USD1,234,567.89)");
#else
assert(sb.str() == "-USD 1,234,567.89");
#endif
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
Expand All @@ -81,7 +87,11 @@ int main(int, char**)
std::showbase(os);
long double x = -123456789;
os << std::put_money(x, false);
#if defined(_WIN32)
assert(sb.str() == L"($1,234,567.89)");
#else
assert(sb.str() == L"-$1,234,567.89");
#endif
}
{
testbuf<wchar_t> sb;
Expand All @@ -90,7 +100,11 @@ int main(int, char**)
std::showbase(os);
long double x = -123456789;
os << std::put_money(x, true);
#if defined(_WIN32)
assert(sb.str() == L"(USD1,234,567.89)");
#else
assert(sb.str() == L"-USD 1,234,567.89");
#endif
}
#endif

Expand Down

0 comments on commit 1425011

Please sign in to comment.