Skip to content

Commit 119ed43

Browse files
Address @mordante's review comments on the test
1 parent 2849685 commit 119ed43

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_overlong.pass.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,31 @@
1313
// iter_type get(iter_type b, iter_type e, bool intl, ios_base& iob,
1414
// ios_base::iostate& err, long double& v) const;
1515

16+
// Ensure that money_get::do_get correct works when the input doesn't fit into the stack buffer
17+
// (100 characters currently).
18+
1619
#include <cassert>
1720
#include <cstddef>
1821
#include <ios>
1922
#include <locale>
2023
#include <streambuf>
2124
#include <string>
2225

26+
#include "make_string.h"
2327
#include "test_macros.h"
2428
#include "test_iterators.h"
2529

26-
typedef std::money_get<char, cpp17_input_iterator<const char*> > Fn;
27-
28-
class my_facet : public Fn {
29-
public:
30-
explicit my_facet(std::size_t refs = 0) : Fn(refs) {}
31-
};
32-
33-
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
34-
typedef std::money_get<wchar_t, cpp17_input_iterator<const wchar_t*> > Fw;
30+
template <class CharT>
31+
class my_basic_facet : public std::money_get<CharT, cpp17_input_iterator<const CharT*> > {
32+
private:
33+
typedef std::money_get<CharT, cpp17_input_iterator<const CharT*> > Base;
3534

36-
class my_facetw : public Fw {
3735
public:
38-
explicit my_facetw(std::size_t refs = 0) : Fw(refs) {}
36+
explicit my_basic_facet(std::size_t refs = 0) : Base(refs) {}
3937
};
40-
#endif
4138

42-
int main(int, char**) {
39+
template <class CharT>
40+
void test() {
4341
struct digit_result_case {
4442
std::size_t digit;
4543
long double result;
@@ -49,13 +47,13 @@ int main(int, char**) {
4947

5048
std::ios ios(0);
5149
{
52-
const my_facet f(1);
50+
const my_basic_facet<CharT> f(1);
5351
for (std::size_t i = 0; i != sizeof(digit_result_cases) / sizeof(digit_result_cases[0]); ++i) {
5452
{
55-
std::string v = "2";
56-
v.append(digit_result_cases[i].digit, '0');
53+
std::basic_string<CharT> v = MAKE_STRING(CharT, "2");
54+
v.append(digit_result_cases[i].digit, static_cast<CharT>('0'));
5755

58-
typedef cpp17_input_iterator<const char*> I;
56+
typedef cpp17_input_iterator<const CharT*> I;
5957
long double ex;
6058
std::ios_base::iostate err = std::ios_base::goodbit;
6159
I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex);
@@ -64,49 +62,51 @@ int main(int, char**) {
6462
assert(ex == digit_result_cases[i].result);
6563
}
6664
{
67-
std::string v = "-2";
68-
v.append(digit_result_cases[i].digit, '0');
65+
std::basic_string<CharT> v = MAKE_STRING(CharT, "-2");
66+
v.append(digit_result_cases[i].digit, static_cast<CharT>('0'));
6967

70-
typedef cpp17_input_iterator<const char*> I;
68+
typedef cpp17_input_iterator<const CharT*> I;
7169
long double ex;
7270
std::ios_base::iostate err = std::ios_base::goodbit;
7371
I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex);
7472
assert(base(iter) == v.data() + v.size());
7573
assert(err == std::ios_base::eofbit);
7674
assert(ex == -digit_result_cases[i].result);
7775
}
78-
}
79-
}
80-
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
81-
{
82-
const my_facetw f(1);
83-
for (std::size_t i = 0; i != sizeof(digit_result_cases) / sizeof(digit_result_cases[0]); ++i) {
8476
{
85-
std::wstring v = L"2";
86-
v.append(digit_result_cases[i].digit, L'0');
77+
std::basic_string<CharT> v = MAKE_STRING(CharT, "0.");
78+
v.append(digit_result_cases[i].digit, static_cast<CharT>('0'));
79+
v += MAKE_CSTRING(CharT, "2");
8780

88-
typedef cpp17_input_iterator<const wchar_t*> I;
81+
typedef cpp17_input_iterator<const CharT*> I;
8982
long double ex;
9083
std::ios_base::iostate err = std::ios_base::goodbit;
9184
I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex);
92-
assert(base(iter) == v.data() + v.size());
93-
assert(err == std::ios_base::eofbit);
94-
assert(ex == digit_result_cases[i].result);
85+
assert(base(iter) == v.data() + 1);
86+
assert(err == std::ios_base::goodbit);
87+
assert(ex == 0.0L);
9588
}
9689
{
97-
std::wstring v = L"-2";
98-
v.append(digit_result_cases[i].digit, L'0');
90+
std::basic_string<CharT> v = MAKE_STRING(CharT, "-0.");
91+
v.append(digit_result_cases[i].digit, static_cast<CharT>('0'));
92+
v += MAKE_CSTRING(CharT, "2");
9993

100-
typedef cpp17_input_iterator<const wchar_t*> I;
94+
typedef cpp17_input_iterator<const CharT*> I;
10195
long double ex;
10296
std::ios_base::iostate err = std::ios_base::goodbit;
10397
I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex);
104-
assert(base(iter) == v.data() + v.size());
105-
assert(err == std::ios_base::eofbit);
106-
assert(ex == -digit_result_cases[i].result);
98+
assert(base(iter) == v.data() + 2);
99+
assert(err == std::ios_base::goodbit);
100+
assert(ex == 0.0L);
107101
}
108102
}
109103
}
104+
}
105+
106+
int main(int, char**) {
107+
test<char>();
108+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
109+
test<wchar_t>();
110110
#endif
111111

112112
return 0;

0 commit comments

Comments
 (0)