diff --git a/include/indentlog/print/color.hpp b/include/indentlog/print/color.hpp index 47167b66..f8b64985 100644 --- a/include/indentlog/print/color.hpp +++ b/include/indentlog/print/color.hpp @@ -14,6 +14,18 @@ namespace xo { rgb }; + inline std::ostream & + operator<< (std::ostream & os, color_encoding x) { + switch(x) { + case color_encoding::none: os << "none"; break; + case color_encoding::ansi: os << "ansi"; break; + case color_encoding::xterm: os << "xterm"; break; + case color_encoding::rgb: os << "rgb"; break; + default: os << "???"; break; + } + return os; + } /*operator<<*/ + /* specify a color (consistent with ANSI escape sequences - the Select Graphics Rendition subset * see [[https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences]] * @@ -106,6 +118,12 @@ namespace xo { std::uint32_t code_ = 0; }; /*color_spec_type*/ + inline std::ostream & + operator<< (std::ostream & os, color_spec_type const & x) { + os << ""; + return os; + } /*operator<<*/ + enum class coloring_control_flags : std::uint8_t { none = 0x0, color_on = 0x01, diff --git a/include/indentlog/print/concat.hpp b/include/indentlog/print/concat.hpp index 31bd6b43..223900ec 100644 --- a/include/indentlog/print/concat.hpp +++ b/include/indentlog/print/concat.hpp @@ -20,6 +20,11 @@ namespace xo { T2 x2_; }; /*concat_impl*/ + template + T1 concat(T1 && x1) { + return x1; + } /*concat*/ + template concat_impl concat(T1 && x1, T2 && x2) { return concat_impl(std::move(x1), std::move(x2)); diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 6e6352b5..1513f8bc 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -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 + filename.test.cpp code_location.test.cpp indentlog_utest_main.cpp) add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) diff --git a/utest/code_location.test.cpp b/utest/code_location.test.cpp new file mode 100644 index 00000000..64f1a0c4 --- /dev/null +++ b/utest/code_location.test.cpp @@ -0,0 +1,47 @@ +/* @file code_location.test.cpp */ + +#include "indentlog/print/code_location.hpp" +#include "indentlog/print/color.hpp" +#include "indentlog/print/tag.hpp" +#include +#include + +using namespace xo; + +namespace ut { + struct code_location_tcase { + code_location_tcase() = default; + code_location_tcase(std::string_view file, std::uint32_t line, color_spec_type color, std::string_view output) + : file_{file}, line_{line}, color_{color}, output_{output} {} + + /* target time value to test */ + std::string_view file_; + std::uint32_t line_; + color_spec_type color_; + std::string_view output_; + }; /*code_location_tcase*/ + + std::vector s_code_location_tcase_v( + { + code_location_tcase("/foo/bar", 123, color_spec_type::none(), "[bar:123]"), + code_location_tcase("/foo/bar", 123, color_spec_type::blue(), "[\033[31;34mbar\033[0m:123]"), + code_location_tcase("/foo/bar", 123, color_spec_type::xterm(196), "[\033[38;5;196mbar\033[0m:123]"), + code_location_tcase("/foo/bar", 123, color_spec_type::rgb(255, 127, 63), "[\033[38;2;255;127;63mbar\033[0m:123]"), + }); + + TEST_CASE("code_location", "[code_location]") { + for (std::uint32_t i_tc = 0, z_tc = s_code_location_tcase_v.size(); i_tc < z_tc; ++i_tc) { + code_location_tcase const & tc = s_code_location_tcase_v[i_tc]; + + INFO(tostr(xtag("i_tc", i_tc), xtag("file", tc.file_), xtag("line", tc.line_), xtag("color", tc.color_))); + INFO(xtag("tc.output", tc.output_)); + + std::stringstream ss; + ss << code_location(tc.file_, tc.line_, tc.color_); + + REQUIRE(ss.str() == tc.output_); + } + } /*TEST_CASE(code_location)*/ +} /*namespace ut*/ + +/* end code_location.test.cpp */ diff --git a/utest/filename.test.cpp b/utest/filename.test.cpp index ee5fdfaf..ebff42b4 100644 --- a/utest/filename.test.cpp +++ b/utest/filename.test.cpp @@ -21,6 +21,8 @@ namespace ut { std::vector s_filename_tcase_v( { filename_tcase("foo", "foo"), + filename_tcase("/foo", "foo"), + filename_tcase("/foo/bar", "bar"), }); TEST_CASE("filename", "[filename]") {