utest: + code_location test

This commit is contained in:
Roland Conybeare 2023-09-22 14:55:38 -04:00
commit b2d939363e
5 changed files with 73 additions and 1 deletions

View file

@ -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 << "<color_spec_type :encoding " << x.encoding() << " :code " << x.code() << ">";
return os;
} /*operator<<*/
enum class coloring_control_flags : std::uint8_t {
none = 0x0,
color_on = 0x01,

View file

@ -20,6 +20,11 @@ namespace xo {
T2 x2_;
}; /*concat_impl*/
template <typename T1>
T1 concat(T1 && x1) {
return x1;
} /*concat*/
template <typename T1, typename T2>
concat_impl<T1,T2> concat(T1 && x1, T2 && x2) {
return concat_impl<T1,T2>(std::move(x1), std::move(x2));

View file

@ -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})

View file

@ -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 <vector>
#include <catch2/catch.hpp>
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<code_location_tcase> 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 */

View file

@ -21,6 +21,8 @@ namespace ut {
std::vector<filename_tcase> s_filename_tcase_v(
{
filename_tcase("foo", "foo"),
filename_tcase("/foo", "foo"),
filename_tcase("/foo/bar", "bar"),
});
TEST_CASE("filename", "[filename]") {