utest: + function_name test
This commit is contained in:
parent
3983361e78
commit
7aa534567f
3 changed files with 72 additions and 1 deletions
|
|
@ -24,6 +24,18 @@ namespace xo {
|
|||
simple
|
||||
};
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, function_style x) {
|
||||
switch(x) {
|
||||
case function_style::literal: os << "literal"; break;
|
||||
case function_style::pretty: os << "pretty"; break;
|
||||
case function_style::streamlined: os << "streamlined"; break;
|
||||
case function_style::simple: os << "simple"; break;
|
||||
default: os << "???"; break;
|
||||
}
|
||||
return os;
|
||||
} /*operator<<*/
|
||||
|
||||
/* Tag to drive header-only expression */
|
||||
template <typename Tag>
|
||||
class function_name_impl {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
set(SELF_EXECUTABLE_NAME utest.indentlog)
|
||||
set(SELF_SOURCE_FILES
|
||||
fixed.test.cpp quoted.test.cpp vector.test.cpp array.test.cpp timeutil.test.cpp tag.test.cpp
|
||||
filename.test.cpp code_location.test.cpp
|
||||
filename.test.cpp code_location.test.cpp function.test.cpp
|
||||
indentlog_utest_main.cpp)
|
||||
|
||||
add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES})
|
||||
|
|
|
|||
59
utest/function.test.cpp
Normal file
59
utest/function.test.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* @file function.test.cpp */
|
||||
|
||||
#include "indentlog/print/function.hpp"
|
||||
#include "indentlog/print/tag.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace xo;
|
||||
|
||||
namespace ut {
|
||||
struct function_tcase {
|
||||
function_tcase() = default;
|
||||
function_tcase(function_style style, color_spec_type spec, std::string_view pretty, std::string_view output)
|
||||
: style_{style}, spec_{spec}, pretty_{pretty}, output_{output} {}
|
||||
|
||||
/* function style: literal|pretty|streamlined|simple*/
|
||||
function_style style_;
|
||||
/* color spec for output */
|
||||
color_spec_type spec_;
|
||||
/* function signature (as per __PRETTY_FUNCTION__) */
|
||||
std::string_view pretty_;
|
||||
/* output text */
|
||||
std::string_view output_;
|
||||
}; /*function_tcase*/
|
||||
|
||||
std::vector<function_tcase> s_function_tcase_v(
|
||||
{
|
||||
function_tcase(function_style::pretty, color_spec_type::none(), "void foo() const", "[void foo() const]"),
|
||||
function_tcase(function_style::streamlined, color_spec_type::none(), "void foo() const", "foo"),
|
||||
function_tcase(function_style::simple, color_spec_type::none(), "void foo() const", "foo"),
|
||||
|
||||
function_tcase(function_style::pretty, color_spec_type::none(), "void xo::class::foo() const", "[void xo::class::foo() const]"),
|
||||
function_tcase(function_style::streamlined, color_spec_type::none(), "void xo::class::foo() const", "class::foo"),
|
||||
function_tcase(function_style::simple, color_spec_type::none(), "void xo::class::foo() const", "foo"),
|
||||
|
||||
function_tcase(function_style::pretty, color_spec_type::blue(), "void xo::class::foo() const", "[\033[31;34mvoid xo::class::foo() const\033[0m]"),
|
||||
});
|
||||
|
||||
TEST_CASE("function", "[function]") {
|
||||
tag_config::tag_color = color_spec_type::none();
|
||||
|
||||
for (std::uint32_t i_tc = 0, z_tc = s_function_tcase_v.size(); i_tc < z_tc; ++i_tc) {
|
||||
function_tcase const & tc = s_function_tcase_v[i_tc];
|
||||
|
||||
INFO(tostr(xtag("i_tc", i_tc), xtag("style", tc.style_), xtag("spec", tc.spec_), xtag("pretty", tc.pretty_)));
|
||||
|
||||
std::stringstream ss;
|
||||
ss << function_name(tc.style_, tc.spec_, tc.pretty_);
|
||||
|
||||
INFO(xtag("ss.str", ss.str()));
|
||||
|
||||
REQUIRE(ss.str() == tc.output_);
|
||||
}
|
||||
|
||||
REQUIRE(s_function_tcase_v.size() > 1);
|
||||
}
|
||||
} /*namespace ut*/
|
||||
|
||||
/* end function.test.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue