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
546b62e7
Commit
546b62e7
authored
Jun 10, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tests.
parent
ed191474
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
15 deletions
+38
-15
test/format-test.cc
test/format-test.cc
+0
-12
test/printf-test.cc
test/printf-test.cc
+23
-3
test/util.cc
test/util.cc
+13
-0
test/util.h
test/util.h
+2
-0
No files found.
test/format-test.cc
View file @
546b62e7
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
#include <cfloat>
#include <cfloat>
#include <climits>
#include <climits>
#include <cmath>
#include <cmath>
#include <cstdarg>
#include <cstring>
#include <cstring>
#include <fstream>
#include <fstream>
#include <iomanip>
#include <iomanip>
...
@@ -109,17 +108,6 @@ struct WriteChecker {
...
@@ -109,17 +108,6 @@ struct WriteChecker {
#define CHECK_WRITE_WCHAR(value) \
#define CHECK_WRITE_WCHAR(value) \
EXPECT_PRED_FORMAT1(WriteChecker<wchar_t>(), value)
EXPECT_PRED_FORMAT1(WriteChecker<wchar_t>(), value)
#ifdef _MSC_VER
# define vsnprintf vsprintf_s
#endif
void
SPrintf
(
char
*
buffer
,
const
char
*
format
,
...)
{
std
::
va_list
args
;
va_start
(
args
,
format
);
vsnprintf
(
buffer
,
BUFFER_SIZE
,
format
,
args
);
va_end
(
args
);
}
std
::
string
ReadFile
(
StringRef
filename
)
{
std
::
string
ReadFile
(
StringRef
filename
)
{
std
::
ifstream
out
(
filename
.
c_str
());
std
::
ifstream
out
(
filename
.
c_str
());
std
::
stringstream
content
;
std
::
stringstream
content
;
...
...
test/printf-test.cc
View file @
546b62e7
...
@@ -165,6 +165,9 @@ TEST(PrintfTest, PlusFlag) {
...
@@ -165,6 +165,9 @@ TEST(PrintfTest, PlusFlag) {
EXPECT_PRINTF
(
"-42"
,
"%+d"
,
-
42
);
EXPECT_PRINTF
(
"-42"
,
"%+d"
,
-
42
);
EXPECT_PRINTF
(
"+0042"
,
"%+05d"
,
42
);
EXPECT_PRINTF
(
"+0042"
,
"%+05d"
,
42
);
EXPECT_PRINTF
(
"+0042"
,
"%0++5d"
,
42
);
EXPECT_PRINTF
(
"+0042"
,
"%0++5d"
,
42
);
// '+' flag is ignored for non-numeric types.
EXPECT_PRINTF
(
"x"
,
"%+c"
,
'x'
);
}
}
TEST
(
PrintfTest
,
MinusFlag
)
{
TEST
(
PrintfTest
,
MinusFlag
)
{
...
@@ -177,6 +180,9 @@ TEST(PrintfTest, SpaceFlag) {
...
@@ -177,6 +180,9 @@ TEST(PrintfTest, SpaceFlag) {
EXPECT_PRINTF
(
"-42"
,
"% d"
,
-
42
);
EXPECT_PRINTF
(
"-42"
,
"% d"
,
-
42
);
EXPECT_PRINTF
(
" 0042"
,
"% 05d"
,
42
);
EXPECT_PRINTF
(
" 0042"
,
"% 05d"
,
42
);
EXPECT_PRINTF
(
" 0042"
,
"%0 5d"
,
42
);
EXPECT_PRINTF
(
" 0042"
,
"%0 5d"
,
42
);
// ' ' flag is ignored for non-numeric types.
EXPECT_PRINTF
(
"x"
,
"% c"
,
'x'
);
}
}
TEST
(
PrintfTest
,
HashFlag
)
{
TEST
(
PrintfTest
,
HashFlag
)
{
...
@@ -189,15 +195,29 @@ TEST(PrintfTest, HashFlag) {
...
@@ -189,15 +195,29 @@ TEST(PrintfTest, HashFlag) {
EXPECT_PRINTF
(
"-0x42"
,
"%#x"
,
-
0x42
);
EXPECT_PRINTF
(
"-0x42"
,
"%#x"
,
-
0x42
);
EXPECT_PRINTF
(
"0"
,
"%#x"
,
0
);
EXPECT_PRINTF
(
"0"
,
"%#x"
,
0
);
EXPECT_PRINTF
(
"0x0042"
,
"%#06x"
,
0x42
);
EXPECT_PRINTF
(
"0x0042"
,
"%0##6x"
,
0x42
);
EXPECT_PRINTF
(
"0x0042"
,
"%0##6x"
,
0x42
);
EXPECT_PRINTF
(
"-42.000000"
,
"%#f"
,
-
42.0
);
EXPECT_PRINTF
(
"-42.000000"
,
"%#F"
,
-
42.0
);
char
buffer
[
BUFFER_SIZE
];
SPrintf
(
buffer
,
"%#e"
,
-
42.0
);
EXPECT_PRINTF
(
buffer
,
"%#e"
,
-
42.0
);
SPrintf
(
buffer
,
"%#E"
,
-
42.0
);
EXPECT_PRINTF
(
buffer
,
"%#E"
,
-
42.0
);
EXPECT_PRINTF
(
"-42.0000"
,
"%#g"
,
-
42.0
);
EXPECT_PRINTF
(
"-42.0000"
,
"%#g"
,
-
42.0
);
//EXPECT_PRINTF("-4.200000e+01", "%#e", -42.0);
EXPECT_PRINTF
(
"-42.0000"
,
"%#G"
,
-
42.0
);
// TODO
//EXPECT_PRINTF("-0x1.5p+5", "%#a", -42.0);
//EXPECT_PRINTF("-0x1.5A+5", "%#A", -42.0);
// TODO: more tests
// '#' flag is ignored for non-numeric types.
EXPECT_PRINTF
(
"x"
,
"%#c"
,
'x'
);
}
}
// TODO: test '*' width, precision, length and type specifier
// TODO: test '*' width, precision, length and type specifier
#endif
#endif
test/util.cc
View file @
546b62e7
...
@@ -26,8 +26,21 @@
...
@@ -26,8 +26,21 @@
*/
*/
#include "util.h"
#include "util.h"
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <cstring>
#ifdef _MSC_VER
# define vsnprintf vsprintf_s
#endif
void
SPrintf
(
char
*
buffer
,
const
char
*
format
,
...)
{
std
::
va_list
args
;
va_start
(
args
,
format
);
vsnprintf
(
buffer
,
BUFFER_SIZE
,
format
,
args
);
va_end
(
args
);
}
void
Increment
(
char
*
s
)
{
void
Increment
(
char
*
s
)
{
for
(
int
i
=
static_cast
<
int
>
(
std
::
strlen
(
s
))
-
1
;
i
>=
0
;
--
i
)
{
for
(
int
i
=
static_cast
<
int
>
(
std
::
strlen
(
s
))
-
1
;
i
>=
0
;
--
i
)
{
if
(
s
[
i
]
!=
'9'
)
{
if
(
s
[
i
]
!=
'9'
)
{
...
...
test/util.h
View file @
546b62e7
...
@@ -27,5 +27,7 @@
...
@@ -27,5 +27,7 @@
enum
{
BUFFER_SIZE
=
256
};
enum
{
BUFFER_SIZE
=
256
};
void
SPrintf
(
char
*
buffer
,
const
char
*
format
,
...);
// Increment a number in a string.
// Increment a number in a string.
void
Increment
(
char
*
s
);
void
Increment
(
char
*
s
);
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