Skip to content

Commit 8f99a63

Browse files
committed
Simplify test by using std::put_money
1 parent 097480f commit 8f99a63

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

test/test_std_formatting.cpp

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ void test_by_char(const std::locale& l, const std::locale& lreal)
6666
const bool bad_parsing = [&]() {
6767
ss_ref_type ss_ref;
6868
ss_ref.imbue(lreal);
69-
ss_ref << std::showbase;
70-
std::use_facet<std::money_put<RefCharType>>(lreal).put(ss_ref, false, ss_ref, RefCharType(' '), 104334);
69+
ss_ref << std::showbase << std::put_money(104334, false);
7170
std::ios_base::iostate err = std::ios_base::iostate();
7271
typename std::money_get<RefCharType>::iter_type end;
7372
long double tmp;
@@ -80,46 +79,41 @@ void test_by_char(const std::locale& l, const std::locale& lreal)
8079
}();
8180

8281
{
83-
std::cout << "- Testing as::currency national " << std::endl;
84-
85-
ss_type ss;
86-
ss.imbue(l);
87-
88-
TEST(ss << as::currency);
89-
TEST(ss << 1043.34);
90-
if(!bad_parsing) {
91-
double v1;
92-
if TEST(ss >> v1)
93-
TEST_EQ(v1, 1043.34);
94-
}
95-
9682
ss_ref_type ss_ref;
9783
ss_ref.imbue(lreal);
9884
ss_ref << std::showbase;
99-
std::use_facet<std::money_put<RefCharType>>(lreal).put(ss_ref, false, ss_ref, RefCharType(' '), 104334);
100-
101-
TEST_EQ(to_utf8(ss.str()), to_utf8(ss_ref.str()));
102-
}
85+
{
86+
std::cout << "- Testing as::currency national " << std::endl;
87+
ss_type ss;
88+
ss.imbue(l);
10389

104-
{
105-
std::cout << "- Testing as::currency iso" << std::endl;
106-
ss_type ss;
107-
ss.imbue(l);
90+
TEST(ss << as::currency);
91+
TEST(ss << 1043.34);
92+
if(!bad_parsing) {
93+
double v1;
94+
if TEST(ss >> v1)
95+
TEST_EQ(v1, 1043.34);
96+
}
10897

109-
ss << as::currency << as::currency_iso;
110-
TEST(ss << 1043.34);
111-
if(!bad_parsing) {
112-
double v1;
113-
if TEST(ss >> v1)
114-
TEST_EQ(v1, 1043.34);
98+
empty_stream(ss_ref) << std::put_money(104334, false);
99+
TEST_EQ(to_utf8(ss.str()), to_utf8(ss_ref.str()));
115100
}
101+
{
102+
std::cout << "- Testing as::currency iso" << std::endl;
103+
ss_type ss;
104+
ss.imbue(l);
116105

117-
ss_ref_type ss_ref;
118-
ss_ref.imbue(lreal);
119-
ss_ref << std::showbase;
120-
std::use_facet<std::money_put<RefCharType>>(lreal).put(ss_ref, true, ss_ref, RefCharType(' '), 104334);
106+
ss << as::currency << as::currency_iso;
107+
TEST(ss << 1043.34);
108+
if(!bad_parsing) {
109+
double v1;
110+
if TEST(ss >> v1)
111+
TEST_EQ(v1, 1043.34);
112+
}
121113

122-
TEST_EQ(to_utf8(ss.str()), to_utf8(ss_ref.str()));
114+
empty_stream(ss_ref) << std::put_money(104334, true);
115+
TEST_EQ(to_utf8(ss.str()), to_utf8(ss_ref.str()));
116+
}
123117
}
124118

125119
{

0 commit comments

Comments
 (0)