utest: + array,vector printers
This commit is contained in:
parent
bc4474c72f
commit
cc82199a8e
3 changed files with 91 additions and 1 deletions
50
utest/vector.test.cpp
Normal file
50
utest/vector.test.cpp
Normal 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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue