Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
5dff01d3
Commit
5dff01d3
authored
Aug 22, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add complex tests
parent
d16d585e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
test/locale-test.cc
test/locale-test.cc
+9
-1
No files found.
test/locale-test.cc
View file @
5dff01d3
...
@@ -121,7 +121,7 @@ template <class charT> struct formatter<std::complex<double>, charT> {
...
@@ -121,7 +121,7 @@ template <class charT> struct formatter<std::complex<double>, charT> {
detail
::
specs_checker
<
handler_type
>
handler
(
handler_type
(
specs_
,
ctx
),
detail
::
specs_checker
<
handler_type
>
handler
(
handler_type
(
specs_
,
ctx
),
detail
::
type
::
string_type
);
detail
::
type
::
string_type
);
auto
it
=
parse_format_specs
(
ctx
.
begin
(),
ctx
.
end
(),
handler
);
auto
it
=
parse_format_specs
(
ctx
.
begin
(),
ctx
.
end
(),
handler
);
detail
::
check_string_type_spec
(
specs_
.
type
,
ctx
.
error_handler
());
detail
::
parse_float_type_spec
(
specs_
,
ctx
.
error_handler
());
return
it
;
return
it
;
}
}
...
@@ -131,11 +131,17 @@ template <class charT> struct formatter<std::complex<double>, charT> {
...
@@ -131,11 +131,17 @@ template <class charT> struct formatter<std::complex<double>, charT> {
detail
::
handle_dynamic_spec
<
detail
::
precision_checker
>
(
detail
::
handle_dynamic_spec
<
detail
::
precision_checker
>
(
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
auto
format_specs
=
std
::
string
();
auto
format_specs
=
std
::
string
();
if
(
specs_
.
precision
>
0
)
format_specs
=
fmt
::
format
(
".{}"
,
specs_
.
precision
);
if
(
specs_
.
type
)
format_specs
+=
specs_
.
type
;
auto
real
=
fmt
::
format
(
ctx
.
locale
().
template
get
<
std
::
locale
>(),
auto
real
=
fmt
::
format
(
ctx
.
locale
().
template
get
<
std
::
locale
>(),
"{:"
+
format_specs
+
"}"
,
c
.
real
());
"{:"
+
format_specs
+
"}"
,
c
.
real
());
auto
imag
=
fmt
::
format
(
ctx
.
locale
().
template
get
<
std
::
locale
>(),
auto
imag
=
fmt
::
format
(
ctx
.
locale
().
template
get
<
std
::
locale
>(),
"{:"
+
format_specs
+
"}"
,
c
.
imag
());
"{:"
+
format_specs
+
"}"
,
c
.
imag
());
auto
fill_align_width
=
std
::
string
();
auto
fill_align_width
=
std
::
string
();
if
(
specs_
.
width
>
0
)
fill_align_width
=
fmt
::
format
(
">{}"
,
specs_
.
width
);
return
format_to
(
return
format_to
(
ctx
.
out
(),
"{:"
+
fill_align_width
+
"}"
,
ctx
.
out
(),
"{:"
+
fill_align_width
+
"}"
,
fmt
::
format
(
c
.
real
()
!=
0
?
"({0}+{1}i)"
:
"{1}i"
,
real
,
imag
));
fmt
::
format
(
c
.
real
()
!=
0
?
"({0}+{1}i)"
:
"{1}i"
,
real
,
imag
));
...
@@ -147,6 +153,8 @@ TEST(FormatTest, Complex) {
...
@@ -147,6 +153,8 @@ TEST(FormatTest, Complex) {
std
::
string
s
=
fmt
::
format
(
"{}"
,
std
::
complex
<
double
>
(
1
,
2
));
std
::
string
s
=
fmt
::
format
(
"{}"
,
std
::
complex
<
double
>
(
1
,
2
));
// We might want to drop trailing zeros for consistency with to_chars.
// We might want to drop trailing zeros for consistency with to_chars.
EXPECT_EQ
(
s
,
"(1.0+2.0i)"
);
EXPECT_EQ
(
s
,
"(1.0+2.0i)"
);
EXPECT_EQ
(
fmt
::
format
(
"{:.2f}"
,
std
::
complex
<
double
>
(
1
,
2
)),
"(1.00+2.00i)"
);
EXPECT_EQ
(
fmt
::
format
(
"{:12}"
,
std
::
complex
<
double
>
(
1
,
2
)),
" (1.0+2.0i)"
);
}
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment