print: utest for print::quoted, print::unq
This commit is contained in:
parent
d656a3970d
commit
bc4474c72f
2 changed files with 77 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# indentlog unit test
|
||||
|
||||
set(SELF_EXECUTABLE_NAME utest.indentlog)
|
||||
set(SELF_SOURCE_FILES fixed.test.cpp indentlog_utest_main.cpp)
|
||||
set(SELF_SOURCE_FILES fixed.test.cpp quoted.test.cpp indentlog_utest_main.cpp)
|
||||
|
||||
add_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES})
|
||||
xo_include_options(${SELF_EXECUTABLE_NAME})
|
||||
|
|
|
|||
76
utest/quoted.test.cpp
Normal file
76
utest/quoted.test.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* @file fixed.test.cpp */
|
||||
|
||||
#include "indentlog/print/quoted.hpp"
|
||||
#include "indentlog/print/tag.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace xo;
|
||||
using namespace xo::print;
|
||||
|
||||
namespace ut {
|
||||
struct quoted_tcase {
|
||||
quoted_tcase() = default;
|
||||
quoted_tcase(std::string x, bool unq_flag, std::string s)
|
||||
: x_{x}, unq_flag_{unq_flag}, s_{std::move(s)} {}
|
||||
|
||||
/* string to be printed-in-machine-readable-form */
|
||||
std::string x_;
|
||||
/* if true: omit surrounding " chars when unambiguous
|
||||
* (printed string does not contain spaces or escaped chars)
|
||||
* if false: always require surrounding " chars
|
||||
*/
|
||||
bool unq_flag_ = true;
|
||||
/* expected result */
|
||||
std::string s_;
|
||||
}; /*quoted_tcase*/
|
||||
|
||||
std::vector<quoted_tcase> s_quoted_tcase_v(
|
||||
{
|
||||
quoted_tcase("", true, "\"\""),
|
||||
quoted_tcase("", false, "\"\""),
|
||||
|
||||
quoted_tcase("foo", true, "foo"),
|
||||
quoted_tcase("foo", false, "\"foo\""),
|
||||
|
||||
quoted_tcase("foo\n", true, "\"foo\\\n\""),
|
||||
quoted_tcase("foo\n", false, "\"foo\\\n\""),
|
||||
|
||||
quoted_tcase("two words", true, "\"two words\""),
|
||||
quoted_tcase("two words", false, "\"two words\""),
|
||||
|
||||
quoted_tcase("1st\n2nd", true, "\"1st\\\n2nd\""),
|
||||
quoted_tcase("1st\n2nd", true, "\"1st\\\n2nd\""),
|
||||
|
||||
quoted_tcase("misakte\rfix", true, "\"misakte\\\rfix\""),
|
||||
quoted_tcase("misakte\rfix", true, "\"misakte\\\rfix\""),
|
||||
|
||||
quoted_tcase("\"oh!\", she said", true, "\"\\\"oh!\\\", she said\""),
|
||||
quoted_tcase("\"oh!\", she said", false, "\"\\\"oh!\\\", she said\""),
|
||||
|
||||
quoted_tcase("<object printer output>", true, "<object printer output>"),
|
||||
quoted_tcase("<object printer output>", false, "<object printer output>"),
|
||||
});
|
||||
|
||||
TEST_CASE("quoted", "[quoted]") {
|
||||
for (std::uint32_t i_tc = 0, z_tc = s_quoted_tcase_v.size(); i_tc < z_tc; ++i_tc) {
|
||||
quoted_tcase const & tc = s_quoted_tcase_v[i_tc];
|
||||
|
||||
INFO(tostr(xtag("i_tc", i_tc), xtag("x", tc.x_), xtag("unq_flag", tc.unq_flag_)));
|
||||
|
||||
std::stringstream ss;
|
||||
if (tc.unq_flag_)
|
||||
ss << unq(tc.x_);
|
||||
else
|
||||
ss << quoted(tc.x_);
|
||||
|
||||
INFO(xtag("ss.str", ss.str()));
|
||||
|
||||
REQUIRE(ss.str() == tc.s_);
|
||||
}
|
||||
|
||||
REQUIRE(s_quoted_tcase_v.size() > 1);
|
||||
}
|
||||
} /*namespace ut*/
|
||||
|
||||
/* end quoted.test.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue