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
2dc108b3
Commit
2dc108b3
authored
Jul 01, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated code
🎆
🎆
🎆
parent
ccf1dbb1
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
388 deletions
+14
-388
format.cc
format.cc
+8
-9
format.h
format.h
+4
-280
test/format-test.cc
test/format-test.cc
+2
-99
No files found.
format.cc
View file @
2dc108b3
...
...
@@ -1104,15 +1104,6 @@ void fmt::ReportWinError(
}
#endif
void
fmt
::
ANSITerminalSink
::
operator
()(
const
fmt
::
BasicWriter
<
char
>
&
w
)
const
{
char
escape
[]
=
"
\x1b
[30m"
;
escape
[
3
]
=
'0'
+
static_cast
<
char
>
(
color_
);
std
::
fputs
(
escape
,
file_
);
std
::
fwrite
(
w
.
data
(),
1
,
w
.
size
(),
file_
);
std
::
fputs
(
RESET_COLOR
,
file_
);
}
void
fmt
::
print
(
StringRef
format
,
const
ArgList
&
args
)
{
Writer
w
;
w
.
write
(
format
,
args
);
...
...
@@ -1125,6 +1116,14 @@ void fmt::print(std::FILE *f, StringRef format, const ArgList &args) {
std
::
fwrite
(
w
.
data
(),
1
,
w
.
size
(),
f
);
}
void
fmt
::
print_colored
(
Color
c
,
StringRef
format
,
const
ArgList
&
args
)
{
char
escape
[]
=
"
\x1b
[30m"
;
escape
[
3
]
=
'0'
+
static_cast
<
char
>
(
c
);
std
::
fputs
(
escape
,
stdout
);
print
(
format
,
args
);
std
::
fputs
(
RESET_COLOR
,
stdout
);
}
void
fmt
::
printf
(
StringRef
format
,
const
ArgList
&
args
)
{
Writer
w
;
printf
(
w
,
format
,
args
);
...
...
format.h
View file @
2dc108b3
This diff is collapsed.
Click to expand it.
test/format-test.cc
View file @
2dc108b3
...
...
@@ -1232,7 +1232,7 @@ TEST(FormatterTest, FormatNaN) {
if
(
fmt
::
internal
::
SignBitNoInline
(
-
nan
))
EXPECT_EQ
(
"-nan"
,
format
(
"{}"
,
-
nan
));
else
fmt
::
P
rint
(
"Warning: compiler doesn't handle negative NaN correctly"
);
fmt
::
p
rint
(
"Warning: compiler doesn't handle negative NaN correctly"
);
EXPECT_EQ
(
" nan"
,
format
(
"{: }"
,
nan
));
EXPECT_EQ
(
"NAN"
,
format
(
"{:F}"
,
nan
));
EXPECT_EQ
(
"nan "
,
format
(
"{:<7}"
,
nan
));
...
...
@@ -1386,100 +1386,6 @@ TEST(StringRefTest, ConvertToString) {
EXPECT_EQ
(
"abc"
,
s
);
}
TEST
(
FormatterTest
,
Ctor
)
{
fmt
::
Formatter
<>
f1
(
"test"
);
fmt
::
Formatter
<>
f1copy
(
f1
);
fmt
::
Formatter
<>
f2
(
"test"
,
fmt
::
NullSink
());
fmt
::
Formatter
<
fmt
::
NullSink
>
f3
(
"test"
);
fmt
::
Formatter
<
fmt
::
NullSink
,
wchar_t
>
f4
(
L"test"
);
fmt
::
Formatter
<
fmt
::
NullSink
,
wchar_t
>
f4copy
(
f4
);
fmt
::
Formatter
<
fmt
::
NullSink
,
wchar_t
>
f5
(
L"test"
,
fmt
::
NullSink
());
}
// A sink that counts the number of times the output is written to it.
struct
CountingSink
{
int
&
num_writes
;
explicit
CountingSink
(
int
&
num_writes
)
:
num_writes
(
num_writes
)
{}
void
operator
()(
const
Writer
&
)
const
{
++
num_writes
;
}
};
TEST
(
FormatterTest
,
Sink
)
{
int
num_writes
=
0
;
{
fmt
::
Formatter
<
CountingSink
>
f
(
"test"
,
CountingSink
(
num_writes
));
EXPECT_EQ
(
0
,
num_writes
);
}
EXPECT_EQ
(
1
,
num_writes
);
}
TEST
(
FormatterTest
,
Move
)
{
// Test if formatting is performed once if we "move" a formatter.
int
num_writes
=
0
;
{
typedef
fmt
::
Formatter
<
CountingSink
>
TestFormatter
;
TestFormatter
*
f
=
new
TestFormatter
(
"test"
,
CountingSink
(
num_writes
));
TestFormatter
f2
(
*
f
);
delete
f
;
EXPECT_EQ
(
0
,
num_writes
);
}
EXPECT_EQ
(
1
,
num_writes
);
}
TEST
(
FormatterTest
,
OutputNotWrittenOnError
)
{
int
num_writes
=
0
;
{
typedef
fmt
::
Formatter
<
CountingSink
>
TestFormatter
;
EXPECT_THROW
(
TestFormatter
f
(
"{0"
,
CountingSink
(
num_writes
)),
FormatError
);
}
EXPECT_EQ
(
0
,
num_writes
);
}
#if FMT_USE_FILE_DESCRIPTORS
using
fmt
::
BufferedFile
;
using
fmt
::
File
;
TEST
(
FormatterTest
,
FileSink
)
{
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
BufferedFile
f
=
write_end
.
fdopen
(
"w"
);
EXPECT_WRITE
(
f
.
get
(),
{
fmt
::
FileSink
fs
(
f
.
get
());
fs
(
Writer
()
<<
"test"
);
},
"test"
);
}
TEST
(
FormatterTest
,
FileSinkWriteError
)
{
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
BufferedFile
f
=
read_end
.
fdopen
(
"r"
);
fmt
::
FileSink
fs
(
f
.
get
());
std
::
size_t
result
=
std
::
fwrite
(
" "
,
1
,
1
,
f
.
get
());
int
error_code
=
errno
;
EXPECT_EQ
(
0u
,
result
);
EXPECT_SYSTEM_ERROR
(
fs
(
Writer
()
<<
"test"
),
error_code
,
"cannot write to file"
);
}
#else
# pragma message "warning: some tests are disabled"
#endif
struct
PrintError
{
void
operator
()(
const
fmt
::
Writer
&
w
)
const
{
std
::
cerr
<<
"Error: "
<<
w
.
str
()
<<
std
::
endl
;
}
};
fmt
::
Formatter
<
PrintError
>
ReportError
(
const
char
*
format
)
{
fmt
::
Formatter
<
PrintError
>
f
(
format
);
return
f
;
}
TEST
(
FormatterTest
,
Examples
)
{
EXPECT_EQ
(
"First, thou shalt count to three"
,
format
(
"First, thou shalt count to {0}"
,
"three"
));
...
...
@@ -1517,9 +1423,6 @@ TEST(FormatterTest, Examples) {
EXPECT_EQ
(
"int: 42; hex: 0x2a; oct: 052"
,
format
(
"int: {0:d}; hex: {0:#x}; oct: {0:#o}"
,
42
));
std
::
string
path
=
"somefile"
;
ReportError
(
"File not found: {0}"
)
<<
path
;
EXPECT_EQ
(
"The answer is 42"
,
format
(
"The answer is {}"
,
42
));
EXPECT_THROW_MSG
(
format
(
"The answer is {:d}"
,
"forty-two"
),
FormatError
,
...
...
@@ -1584,7 +1487,7 @@ TEST(FormatTest, Print) {
}
TEST
(
FormatTest
,
PrintColored
)
{
EXPECT_WRITE
(
stdout
,
fmt
::
PrintColored
(
fmt
::
RED
,
"Hello, {}!
\n
"
)
<<
"world"
,
EXPECT_WRITE
(
stdout
,
fmt
::
print_colored
(
fmt
::
RED
,
"Hello, {}!
\n
"
,
"world"
)
,
"
\x1b
[31mHello, world!
\n\x1b
[0m"
);
}
...
...
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