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
8641461c
Commit
8641461c
authored
Apr 27, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tests.
parent
0b307248
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
3 deletions
+56
-3
CMakeLists.txt
CMakeLists.txt
+10
-0
format-test.cc
format-test.cc
+43
-3
test/CMakeLists.txt
test/CMakeLists.txt
+3
-0
No files found.
CMakeLists.txt
View file @
8641461c
...
@@ -63,6 +63,16 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
...
@@ -63,6 +63,16 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_definitions
(
-DGTEST_USE_OWN_TR1_TUPLE=1
)
add_definitions
(
-DGTEST_USE_OWN_TR1_TUPLE=1
)
endif
()
endif
()
include
(
CheckSymbolExists
)
if
(
WIN32
)
check_symbol_exists
(
dup io.h HAVE_DUP
)
else
()
check_symbol_exists
(
dup unistd.h HAVE_DUP
)
endif
()
if
(
HAVE_DUP
)
add_definitions
(
-DFMT_USE_DUP=1
)
endif
()
add_library
(
gtest gtest/gtest-all.cc
)
add_library
(
gtest gtest/gtest-all.cc
)
find_package
(
Threads
)
find_package
(
Threads
)
...
...
format-test.cc
View file @
8641461c
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <climits>
#include <climits>
#include <cstdarg>
#include <cstdarg>
#include <cstring>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iomanip>
#include <memory>
#include <memory>
#include <sstream>
#include <sstream>
...
@@ -41,6 +42,17 @@
...
@@ -41,6 +42,17 @@
# include <crtdbg.h>
# include <crtdbg.h>
#endif
#endif
#if FMT_USE_DUP
# ifdef _WIN32
# include <io.h>
# else
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
# endif
#endif
#include "format.h"
#include "format.h"
#include <stdint.h>
#include <stdint.h>
...
@@ -1341,7 +1353,7 @@ TEST(FormatterTest, FormatChar) {
...
@@ -1341,7 +1353,7 @@ TEST(FormatterTest, FormatChar) {
TEST
(
FormatterTest
,
FormatWChar
)
{
TEST
(
FormatterTest
,
FormatWChar
)
{
EXPECT_EQ
(
L"a"
,
str
(
Format
(
L"{0}"
)
<<
L'a'
));
EXPECT_EQ
(
L"a"
,
str
(
Format
(
L"{0}"
)
<<
L'a'
));
// This shouldn't compile:
// This shouldn't compile:
//Format("{
0
}") << L'a';
//Format("{}") << L'a';
}
}
TEST
(
FormatterTest
,
FormatCString
)
{
TEST
(
FormatterTest
,
FormatCString
)
{
...
@@ -1490,7 +1502,7 @@ TEST(FormatterTest, ActionNotCalledOnError) {
...
@@ -1490,7 +1502,7 @@ TEST(FormatterTest, ActionNotCalledOnError) {
// The test doesn't compile on older compilers which follow C++03 and
// The test doesn't compile on older compilers which follow C++03 and
// require an accessible copy constructor when binding a temporary to
// require an accessible copy constructor when binding a temporary to
// a const reference.
// a const reference.
#if
__GNUC__ >= 4 && __GNUC_MINOR__ >=
7
#if
FMT_GCC_VERSION >= 40
7
TEST
(
FormatterTest
,
ArgLifetime
)
{
TEST
(
FormatterTest
,
ArgLifetime
)
{
// The following code is for testing purposes only. It is a definite abuse
// The following code is for testing purposes only. It is a definite abuse
// of the API and shouldn't be used in real applications.
// of the API and shouldn't be used in real applications.
...
@@ -1609,11 +1621,39 @@ TEST(FormatIntTest, FormatDec) {
...
@@ -1609,11 +1621,39 @@ TEST(FormatIntTest, FormatDec) {
EXPECT_EQ
(
"42"
,
FormatDec
(
42ull
));
EXPECT_EQ
(
"42"
,
FormatDec
(
42ull
));
}
}
#ifdef FMT_USE_DUP
class
File
{
private:
int
fd_
;
File
(
const
File
&
);
void
operator
=
(
const
File
&
);
public:
File
(
int
fd
)
:
fd_
(
fd
)
{}
~
File
()
{
close
(
fd_
);
}
int
fd
()
const
{
return
fd_
;
}
};
TEST
(
ColorTest
,
PrintColored
)
{
TEST
(
ColorTest
,
PrintColored
)
{
std
::
fflush
(
stdout
);
File
saved_stdio
(
dup
(
1
));
EXPECT_NE
(
-
1
,
saved_stdio
.
fd
());
{
File
out
(
open
(
"out"
,
O_WRONLY
|
O_CREAT
,
S_IRUSR
|
S_IWUSR
));
EXPECT_NE
(
-
1
,
out
.
fd
());
EXPECT_NE
(
-
1
,
dup2
(
out
.
fd
(),
1
));
}
fmt
::
PrintColored
(
fmt
::
RED
,
"Hello, {}!
\n
"
)
<<
"world"
;
fmt
::
PrintColored
(
fmt
::
RED
,
"Hello, {}!
\n
"
)
<<
"world"
;
// TODO
std
::
fflush
(
stdout
);
EXPECT_NE
(
-
1
,
dup2
(
saved_stdio
.
fd
(),
1
));
std
::
ifstream
out
(
"out"
);
std
::
stringstream
content
;
content
<<
out
.
rdbuf
();
EXPECT_EQ
(
"
\x1b
[31mHello, world!
\n\x1b
[0m"
,
content
.
str
());
}
}
#endif
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
);
...
...
test/CMakeLists.txt
View file @
8641461c
...
@@ -33,3 +33,6 @@ expect_compile_error("fmt::Writer a, b; b = a;")
...
@@ -33,3 +33,6 @@ expect_compile_error("fmt::Writer a, b; b = a;")
expect_compile_error
(
"fmt::Writer() << L'a';"
)
expect_compile_error
(
"fmt::Writer() << L'a';"
)
expect_compile_error
(
"fmt::Writer() << fmt::pad(
\"
abc
\"
, 5, L' ');"
)
expect_compile_error
(
"fmt::Writer() << fmt::pad(
\"
abc
\"
, 5, L' ');"
)
expect_compile_error
(
"fmt::Writer() << fmt::pad(42, 5, L' ');"
)
expect_compile_error
(
"fmt::Writer() << fmt::pad(42, 5, L' ');"
)
# Formatting a wide character with a narrow format string is forbidden.
expect_compile_error
(
"Format(
\"
{}
\"
) << L'a';"
)
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