From cc82199a8e403f6bbde06ab452448d3e2498ff1d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 21 Sep 2023 11:20:56 -0400 Subject: [PATCH] utest: + array,vector printers --- utest/CMakeLists.txt | 2 +- utest/array.test.cpp | 40 ++++++++++++++++++++++++++++++++++ utest/vector.test.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 utest/array.test.cpp create mode 100644 utest/vector.test.cpp diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index c4ecf78e..95a6e5d3 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -1,7 +1,7 @@ # indentlog unit test set(SELF_EXECUTABLE_NAME utest.indentlog) -set(SELF_SOURCE_FILES fixed.test.cpp quoted.test.cpp indentlog_utest_main.cpp) +set(SELF_SOURCE_FILES fixed.test.cpp quoted.test.cpp vector.test.cpp array.test.cpp indentlog_utest_main.cpp) add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) xo_include_options(${SELF_EXECUTABLE_NAME}) diff --git a/utest/array.test.cpp b/utest/array.test.cpp new file mode 100644 index 00000000..4ba8b83a --- /dev/null +++ b/utest/array.test.cpp @@ -0,0 +1,40 @@ +/* @file array.test.cpp */ + +#include "indentlog/print/array.hpp" /* overload operator<< for std::array */ +#include "indentlog/print/tag.hpp" +#include +#include + +using namespace xo; + +namespace ut { + TEST_CASE("array", "[array]") { + tag_config::tag_color = color_spec_type::none(); + + { + std::array x = {}; + std::stringstream ss; + ss << x; + + REQUIRE(ss.str() == "[]"); + } + + { + std::array x = {1}; + std::stringstream ss; + ss << x; + + REQUIRE(ss.str() == "[1]"); + } + + { + std::array x = {1, 2}; + std::stringstream ss; + ss << x; + + REQUIRE(ss.str() == "[1 2]"); + } + } +} /*namespace ut*/ + +/* end array.test.cpp */ diff --git a/utest/vector.test.cpp b/utest/vector.test.cpp new file mode 100644 index 00000000..8b4f1f4c --- /dev/null +++ b/utest/vector.test.cpp @@ -0,0 +1,50 @@ +/* @file vector.test.cpp */ + +#include "indentlog/print/vector.hpp" /* overload operator<< for std::vector */ +#include "indentlog/print/tag.hpp" +#include +#include + +using namespace xo; + +namespace ut { + struct vector_tcase { + vector_tcase() = default; + vector_tcase(std::vector const & x, std::string s) + : x_{x}, s_{std::move(s)} {} + + /* vector to print */ + std::vector x_; + /* expected result */ + std::string s_; + }; /*vector_tcase*/ + + std::vector s_vector_tcase_v( + {vector_tcase({}, "[]"), + vector_tcase({1}, "[1]"), + vector_tcase({1, 2}, "[1 2]"), + vector_tcase({10, 20, 30}, "[10 20 30]"), + + }); + + TEST_CASE("vector", "[vector]") { + tag_config::tag_color = color_spec_type::none(); + + for (std::uint32_t i_tc = 0, z_tc = s_vector_tcase_v.size(); i_tc < z_tc; ++i_tc) { + vector_tcase const & tc = s_vector_tcase_v[i_tc]; + + INFO(tostr(xtag("i_tc", i_tc), xtag("x", tc.x_))); + + std::stringstream ss; + ss << tc.x_; + + INFO(xtag("ss.str", ss.str())); + + REQUIRE(ss.str() == tc.s_); + } + + REQUIRE(s_vector_tcase_v.size() > 1); + } +} /*namespace ut*/ + +/* end vector.test.cpp */