diff --git a/xo-indentlog/utest/CMakeLists.txt b/xo-indentlog/utest/CMakeLists.txt index c8ea729c..5fa2bf1b 100644 --- a/xo-indentlog/utest/CMakeLists.txt +++ b/xo-indentlog/utest/CMakeLists.txt @@ -4,7 +4,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 function.test.cpp pretty_vector.test.cpp - indentlog_utest_main.cpp log_streambuf.test.cpp toppstr.test.cpp) + indentlog_utest_main.cpp log_streambuf.test.cpp toppstr.test.cpp cond.test.cpp) xo_add_utest_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) diff --git a/xo-indentlog/utest/cond.test.cpp b/xo-indentlog/utest/cond.test.cpp new file mode 100644 index 00000000..e421c642 --- /dev/null +++ b/xo-indentlog/utest/cond.test.cpp @@ -0,0 +1,47 @@ +/* @file cond.test.cpp */ + +#include "xo/indentlog/print/cond.hpp" +#include "xo/indentlog/print/tag.hpp" +#include +#include + +using namespace xo; + +namespace ut { + TEST_CASE("cond", "[cond]") { + tag_config::tag_color = color_spec_type::none(); + + { + std::stringstream ss; + ss << cond(true, "yes", "no"); + REQUIRE(ss.str() == "yes"); + } + + { + std::stringstream ss; + ss << cond(false, "yes", "no"); + REQUIRE(ss.str() == "no"); + } + + { + std::stringstream ss; + ss << cond(true, 42, "none"); + REQUIRE(ss.str() == "42"); + } + + { + std::stringstream ss; + ss << cond(false, 42, "none"); + REQUIRE(ss.str() == "none"); + } + + { + std::stringstream ss; + int * ptr = nullptr; + ss << cond(ptr != nullptr, xtag("ptr", 123), xtag("ptr", "null")); + REQUIRE(ss.str() == " :ptr null"); + } + } +} + +/* end cond.test.cpp */