Skip to content

Commit

Permalink
[libcxx] [test] Fix get_string_en_US, get_long_double_en_US for 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".

Differential Revision: https://reviews.llvm.org/D120799
  • Loading branch information
mstorsjo committed Mar 4, 2022
1 parent d32f46b commit b2d9340
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 66 deletions.
Expand Up @@ -14,7 +14,6 @@
// ios_base::iostate& err, long double& v) const;

// REQUIRES: locale.en_US.UTF-8
// XFAIL: LIBCXX-WINDOWS-FIXME

#include <locale>
#include <ios>
Expand All @@ -23,6 +22,7 @@
#include "test_macros.h"
#include "test_iterators.h"

#include "locale_helpers.h"
#include "platform_support.h" // locale name macros

typedef std::money_get<char, cpp17_input_iterator<const char*> > Fn;
Expand Down Expand Up @@ -76,7 +76,7 @@ int main(int, char**)
assert(ex == 0);
}
{ // negative one
std::string v = "-0.01";
std::string v = LocaleHelpers::negate_en_US("0.01");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -98,7 +98,7 @@ int main(int, char**)
assert(ex == 123456789);
}
{ // negative
std::string v = "-1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("1,234,567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -109,7 +109,7 @@ int main(int, char**)
assert(ex == -123456789);
}
{ // negative
std::string v = "-1234567.89";
std::string v = LocaleHelpers::negate_en_US("1234567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand Down Expand Up @@ -144,7 +144,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative one, showbase
std::string v = "-$0.01";
std::string v = LocaleHelpers::negate_en_US("$0.01");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -155,7 +155,7 @@ int main(int, char**)
assert(ex == -1);
}
{ // negative one, showbase
std::string v = "-$0.01";
std::string v = LocaleHelpers::negate_en_US("$0.01");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand Down Expand Up @@ -192,7 +192,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-$1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("$1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand All @@ -205,7 +205,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-USD 1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("USD 1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand All @@ -217,7 +217,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-USD 1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("USD 1,234,567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -242,7 +242,7 @@ int main(int, char**)
assert(ex == 0);
}
{ // negative one
std::string v = "-0.01";
std::string v = LocaleHelpers::negate_en_US("0.01");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -264,7 +264,7 @@ int main(int, char**)
assert(ex == 123456789);
}
{ // negative
std::string v = "-1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("1,234,567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -275,7 +275,7 @@ int main(int, char**)
assert(ex == -123456789);
}
{ // negative
std::string v = "-1234567.89";
std::string v = LocaleHelpers::negate_en_US("1234567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand Down Expand Up @@ -310,7 +310,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative one, showbase
std::string v = "-USD 0.01";
std::string v = LocaleHelpers::negate_en_US("USD 0.01");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -321,7 +321,7 @@ int main(int, char**)
assert(ex == -1);
}
{ // negative one, showbase
std::string v = "-USD 0.01";
std::string v = LocaleHelpers::negate_en_US("USD 0.01");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand Down Expand Up @@ -358,7 +358,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-USD 1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("USD 1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand All @@ -371,7 +371,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-$1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("$1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const char*> I;
long double ex;
Expand All @@ -383,7 +383,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::string v = "-$1,234,567.89";
std::string v = LocaleHelpers::negate_en_US("$1,234,567.89");
typedef cpp17_input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -409,7 +409,7 @@ int main(int, char**)
assert(ex == 0);
}
{ // negative one
std::wstring v = L"-0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"0.01");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -431,7 +431,7 @@ int main(int, char**)
assert(ex == 123456789);
}
{ // negative
std::wstring v = L"-1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"1,234,567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -442,7 +442,7 @@ int main(int, char**)
assert(ex == -123456789);
}
{ // negative
std::wstring v = L"-1234567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"1234567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand Down Expand Up @@ -477,7 +477,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative one, showbase
std::wstring v = L"-$0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"$0.01");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -488,7 +488,7 @@ int main(int, char**)
assert(ex == -1);
}
{ // negative one, showbase
std::wstring v = L"-$0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"$0.01");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand Down Expand Up @@ -525,7 +525,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-$1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"$1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand All @@ -538,7 +538,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-USD 1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"USD 1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand All @@ -550,7 +550,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-USD 1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"USD 1,234,567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -575,7 +575,7 @@ int main(int, char**)
assert(ex == 0);
}
{ // negative one
std::wstring v = L"-0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"0.01");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -597,7 +597,7 @@ int main(int, char**)
assert(ex == 123456789);
}
{ // negative
std::wstring v = L"-1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"1,234,567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -608,7 +608,7 @@ int main(int, char**)
assert(ex == -123456789);
}
{ // negative
std::wstring v = L"-1234567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"1234567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand Down Expand Up @@ -643,7 +643,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative one, showbase
std::wstring v = L"-USD 0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"USD 0.01");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand All @@ -654,7 +654,7 @@ int main(int, char**)
assert(ex == -1);
}
{ // negative one, showbase
std::wstring v = L"-USD 0.01";
std::wstring v = LocaleHelpers::negate_en_US(L"USD 0.01");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand Down Expand Up @@ -691,7 +691,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-USD 1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"USD 1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand All @@ -704,7 +704,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-$1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"$1,234,567.89");
std::showbase(ios);
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
Expand All @@ -716,7 +716,7 @@ int main(int, char**)
std::noshowbase(ios);
}
{ // negative, showbase
std::wstring v = L"-$1,234,567.89";
std::wstring v = LocaleHelpers::negate_en_US(L"$1,234,567.89");
typedef cpp17_input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
Expand Down

0 comments on commit b2d9340

Please sign in to comment.