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
1b3ac760
Commit
1b3ac760
authored
Jan 21, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check that hex and oct don't conflict with IO manipulators.
parent
c7354b67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
format_test.cc
format_test.cc
+11
-2
No files found.
format_test.cc
View file @
1b3ac760
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include <cfloat>
#include <cfloat>
#include <climits>
#include <climits>
#include <cstring>
#include <cstring>
#include <iomanip>
#include <memory>
#include <memory>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "format.h"
#include "format.h"
...
@@ -50,9 +51,7 @@ using fmt::Formatter;
...
@@ -50,9 +51,7 @@ using fmt::Formatter;
using
fmt
::
Format
;
using
fmt
::
Format
;
using
fmt
::
FormatError
;
using
fmt
::
FormatError
;
using
fmt
::
StringRef
;
using
fmt
::
StringRef
;
using
fmt
::
hex
;
using
fmt
::
hexu
;
using
fmt
::
hexu
;
using
fmt
::
oct
;
using
fmt
::
pad
;
using
fmt
::
pad
;
#define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \
#define FORMAT_TEST_THROW_(statement, expected_exception, message, fail) \
...
@@ -1065,6 +1064,7 @@ TEST(TempFormatterTest, Examples) {
...
@@ -1065,6 +1064,7 @@ TEST(TempFormatterTest, Examples) {
}
}
TEST
(
StrTest
,
oct
)
{
TEST
(
StrTest
,
oct
)
{
using
fmt
::
oct
;
EXPECT_EQ
(
"12"
,
(
BasicFormatter
()
<<
oct
(
static_cast
<
short
>
(
012
))).
str
());
EXPECT_EQ
(
"12"
,
(
BasicFormatter
()
<<
oct
(
static_cast
<
short
>
(
012
))).
str
());
EXPECT_EQ
(
"12"
,
(
BasicFormatter
()
<<
oct
(
012
)).
str
());
EXPECT_EQ
(
"12"
,
(
BasicFormatter
()
<<
oct
(
012
)).
str
());
EXPECT_EQ
(
"34"
,
(
BasicFormatter
()
<<
oct
(
034u
)).
str
());
EXPECT_EQ
(
"34"
,
(
BasicFormatter
()
<<
oct
(
034u
)).
str
());
...
@@ -1073,6 +1073,7 @@ TEST(StrTest, oct) {
...
@@ -1073,6 +1073,7 @@ TEST(StrTest, oct) {
}
}
TEST
(
StrTest
,
hex
)
{
TEST
(
StrTest
,
hex
)
{
using
fmt
::
hex
;
fmt
::
IntFormatter
<
int
,
fmt
::
TypeSpec
<
'x'
>
>
(
*
phex
)(
int
value
)
=
hex
;
fmt
::
IntFormatter
<
int
,
fmt
::
TypeSpec
<
'x'
>
>
(
*
phex
)(
int
value
)
=
hex
;
phex
(
42
);
phex
(
42
);
// This shouldn't compile:
// This shouldn't compile:
...
@@ -1107,6 +1108,7 @@ public:
...
@@ -1107,6 +1108,7 @@ public:
ISO8601DateFormatter
iso8601
(
const
Date
&
d
)
{
return
ISO8601DateFormatter
(
d
);
}
ISO8601DateFormatter
iso8601
(
const
Date
&
d
)
{
return
ISO8601DateFormatter
(
d
);
}
TEST
(
StrTest
,
pad
)
{
TEST
(
StrTest
,
pad
)
{
using
fmt
::
hex
;
EXPECT_EQ
(
" cafe"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xcafe
),
8
)).
str
());
EXPECT_EQ
(
" cafe"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xcafe
),
8
)).
str
());
EXPECT_EQ
(
" babe"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xbabeu
),
8
)).
str
());
EXPECT_EQ
(
" babe"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xbabeu
),
8
)).
str
());
EXPECT_EQ
(
" dead"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xdeadl
),
8
)).
str
());
EXPECT_EQ
(
" dead"
,
(
BasicFormatter
()
<<
pad
(
hex
(
0xdeadl
),
8
)).
str
());
...
@@ -1129,6 +1131,13 @@ TEST(StrTest, pad) {
...
@@ -1129,6 +1131,13 @@ TEST(StrTest, pad) {
EXPECT_EQ
(
"2012-01-09"
,
f
.
str
());
EXPECT_EQ
(
"2012-01-09"
,
f
.
str
());
}
}
TEST
(
StrTest
,
NoConflictWithIOManip
)
{
using
namespace
std
;
using
namespace
fmt
;
EXPECT_EQ
(
"cafe"
,
(
BasicFormatter
()
<<
hex
(
0xcafe
)).
str
());
EXPECT_EQ
(
"12"
,
(
BasicFormatter
()
<<
oct
(
012
)).
str
());
}
template
<
typename
T
>
template
<
typename
T
>
std
::
string
str
(
const
T
&
value
)
{
std
::
string
str
(
const
T
&
value
)
{
return
fmt
::
str
(
fmt
::
Format
(
"{0}"
)
<<
value
);
return
fmt
::
str
(
fmt
::
Format
(
"{0}"
)
<<
value
);
...
...
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