Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
644c81b9
Commit
644c81b9
authored
Apr 06, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added color ranges to formatter tests
parent
3452892f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
2 deletions
+63
-2
test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+63
-2
No files found.
tests/test_pattern_formatter.cpp
View file @
644c81b9
...
...
@@ -7,8 +7,10 @@ static std::string log_to_str(const std::string &msg, const std::shared_ptr<spdl
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"pattern_tester"
,
oss_sink
);
oss_logger
.
set_level
(
spdlog
::
level
::
info
);
if
(
formatter
)
oss_logger
.
set_formatter
(
formatter
);
if
(
formatter
)
{
oss_logger
.
set_formatter
(
formatter
);
}
oss_logger
.
info
(
msg
);
return
oss
.
str
();
}
...
...
@@ -61,3 +63,62 @@ TEST_CASE("date MM/DD/YY ", "[pattern_formatter]")
<<
(
now_tm
.
tm_year
+
1900
)
%
1000
<<
" Some message
\n
"
;
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
oss
.
str
());
}
TEST_CASE
(
"color range test1"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^%v%$"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
spdlog
::
details
::
log_msg
msg
;
msg
.
raw
<<
"Hello"
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
5
);
REQUIRE
(
log_to_str
(
"hello"
,
formatter
)
==
"hello
\n
"
);
}
TEST_CASE
(
"color range test2"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^%$"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
spdlog
::
details
::
log_msg
msg
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
0
);
REQUIRE
(
log_to_str
(
""
,
formatter
)
==
"
\n
"
);
}
TEST_CASE
(
"color range test3"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^***%$"
);
spdlog
::
details
::
log_msg
msg
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
3
);
}
TEST_CASE
(
"color range test4"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"XX%^YYY%$"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
spdlog
::
details
::
log_msg
msg
;
msg
.
raw
<<
"ignored"
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
2
);
REQUIRE
(
msg
.
color_range_end
==
5
);
REQUIRE
(
log_to_str
(
"ignored"
,
formatter
)
==
"XXYYY
\n
"
);
}
TEST_CASE
(
"color range test5"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"**%^"
);
spdlog
::
details
::
log_msg
msg
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
2
);
REQUIRE
(
msg
.
color_range_end
==
0
);
}
TEST_CASE
(
"color range test6"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"**%$"
);
spdlog
::
details
::
log_msg
msg
;
formatter
->
format
(
msg
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
2
);
}
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