From ca64cdd91194bf95dbf4240529818f922f9755e2 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 22 Sep 2023 12:16:41 -0400 Subject: [PATCH] utest: + tag/xtag + basename tests --- utest/CMakeLists.txt | 5 ++- utest/filename.test.cpp | 41 +++++++++++++++++++++++++ utest/tag.test.cpp | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 utest/filename.test.cpp create mode 100644 utest/tag.test.cpp diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 6c4c07a0..6e6352b5 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -1,7 +1,10 @@ # indentlog unit test 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 indentlog_utest_main.cpp) +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 + indentlog_utest_main.cpp) add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) xo_include_options(${SELF_EXECUTABLE_NAME}) diff --git a/utest/filename.test.cpp b/utest/filename.test.cpp new file mode 100644 index 00000000..ee5fdfaf --- /dev/null +++ b/utest/filename.test.cpp @@ -0,0 +1,41 @@ +/* @file filename.test.cpp */ + +#include "indentlog/print/filename.hpp" +#include "indentlog/print/tag.hpp" +#include +#include + +using namespace xo; + +namespace ut { + struct filename_tcase { + filename_tcase() = default; + filename_tcase(std::string_view path, std::string_view basename) + : path_{path}, basename_{basename} {} + + /* target time value to test */ + std::string_view path_; + std::string_view basename_; + }; /*filename_tcase*/ + + std::vector s_filename_tcase_v( + { + filename_tcase("foo", "foo"), + }); + + TEST_CASE("filename", "[filename]") { + for (std::uint32_t i_tc = 0, z_tc = s_filename_tcase_v.size(); i_tc < z_tc; ++i_tc) { + filename_tcase const & tc = s_filename_tcase_v[i_tc]; + + INFO(tostr(xtag("i_tc", i_tc), xtag("path", tc.path_))); + INFO(xtag("tc.basename", tc.basename_)); + + std::stringstream ss; + ss << basename(tc.path_); + + REQUIRE(ss.str() == tc.basename_); + } + } /*TEST_CASE(filename)*/ +} /*namespace ut*/ + +/* end filename.test.cpp */ diff --git a/utest/tag.test.cpp b/utest/tag.test.cpp new file mode 100644 index 00000000..8ecabb8d --- /dev/null +++ b/utest/tag.test.cpp @@ -0,0 +1,67 @@ +/* @file tag.test.cpp */ + +#include "indentlog/print/tag.hpp" +#include "indentlog/print/vector.hpp" +#include "indentlog/print/concat.hpp" +#include +#include + +using namespace xo; + +namespace ut { + TEST_CASE("tag", "[tag]") { + tag_config::tag_color = color_spec_type::none(); + + { + std::stringstream ss; + ss << tag("foo", "hello,world!"); + + REQUIRE(ss.str() == ":foo hello,world!"); + } + + { + std::stringstream ss; + ss << tag("foo", "hello, world!"); + + REQUIRE(ss.str() == ":foo \"hello, world!\""); + } + + { + std::stringstream ss; + std::vector v = {1, 2, 3}; + ss << tag("foo", v); + + REQUIRE(ss.str() == ":foo \"[1 2 3]\""); + } + + { + std::stringstream ss; + ss << tag("foo", concat("farenheit", 451)); + + REQUIRE(ss.str() == ":foo farenheit451"); + } + + { + std::stringstream ss; + ss << tag("foo", "hello") << xtag("bar", "there"); + + REQUIRE(ss.str() == ":foo hello :bar there"); + } + + tag_config::tag_color = color_spec_type::blue(); + + { + std::stringstream ss; + ss << tag("foo", "hello,world!"); + + /* color on color off + * <---------> <-----> + * + * see [indentlog/print/color.hpp] for escape sequences + */ + REQUIRE(ss.str() == "\033[31;34m:foo\033[0m hello,world!"); + } + } /*TEST_CASE(tag)*/ +} /*namespace ut*/ + +/* end tag.test.cpp */