utest: + array,vector printers

This commit is contained in:
Roland Conybeare 2023-09-21 11:20:56 -04:00
commit cc82199a8e
3 changed files with 91 additions and 1 deletions

View file

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

40
utest/array.test.cpp Normal file
View file

@ -0,0 +1,40 @@
/* @file array.test.cpp */
#include "indentlog/print/array.hpp" /* overload operator<< for std::array */
#include "indentlog/print/tag.hpp"
#include <catch2/catch.hpp>
#include <sstream>
using namespace xo;
namespace ut {
TEST_CASE("array", "[array]") {
tag_config::tag_color = color_spec_type::none();
{
std::array<int, 0> x = {};
std::stringstream ss;
ss << x;
REQUIRE(ss.str() == "[]");
}
{
std::array<int, 1> x = {1};
std::stringstream ss;
ss << x;
REQUIRE(ss.str() == "[1]");
}
{
std::array<int, 2> x = {1, 2};
std::stringstream ss;
ss << x;
REQUIRE(ss.str() == "[1 2]");
}
}
} /*namespace ut*/
/* end array.test.cpp */

50
utest/vector.test.cpp Normal file
View file

@ -0,0 +1,50 @@
/* @file vector.test.cpp */
#include "indentlog/print/vector.hpp" /* overload operator<< for std::vector */
#include "indentlog/print/tag.hpp"
#include <catch2/catch.hpp>
#include <sstream>
using namespace xo;
namespace ut {
struct vector_tcase {
vector_tcase() = default;
vector_tcase(std::vector<int> const & x, std::string s)
: x_{x}, s_{std::move(s)} {}
/* vector to print */
std::vector<int> x_;
/* expected result */
std::string s_;
}; /*vector_tcase*/
std::vector<vector_tcase> 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 */