xo-umbrella2/xo-indentlog2/utest/span_pp.test.cpp
Roland Conybeare a095a49bb0
All checks were successful
cmake-docker / cmake-build (clang, clang++) (push) Successful in 23m28s
cmake-docker / cmake-build (gcc, g++) (push) Successful in 24m51s
CI / smoke-test (push) Successful in 44m4s
refactoring _ostream.hpp _pp.hpp vs ODR [REFACTOR]
2026-08-17 00:38:44 -04:00

58 lines
1.8 KiB
C++

/** @file span_pp.test.cpp
*
* exercise xo::pp::Prettifier<xo::mm::span<CharT>> (from xo/arena/span_pp.hpp)
* -- the ppsink-native structured printing for an arena span.
**/
#include <xo/arena/span.hpp>
#include <xo/ppsink/FlatSink.hpp>
#include <catch2/catch.hpp>
#include <sstream>
#include <string>
namespace ut {
using xo::pp::FlatSink;
using std::stringstream;
static std::string pretty_of(const xo::mm::span<const char> & sp) {
stringstream ss;
FlatSink sink(ss.rdbuf());
sink.pp(sp);
return ss.str();
}
TEST_CASE("span_pp-basic", "[span_pp]") {
const char * text = "hello";
xo::mm::span<const char> sp(text, text + 5);
std::string out = pretty_of(sp);
REQUIRE(out.substr(0, 5) == "<span");
REQUIRE(out.back() == '>');
REQUIRE(out.find(":size 5") != std::string::npos);
REQUIRE(out.find(":text hello") != std::string::npos); /* unambiguous => bare (unq) */
REQUIRE(out.find(":addr ") != std::string::npos);
}
TEST_CASE("span_pp-empty", "[span_pp]") {
/* a null span: size 0, empty text */
xo::mm::span<const char> sp = xo::mm::span<const char>::make_null();
std::string out = pretty_of(sp);
REQUIRE(out.find(":size 0") != std::string::npos);
REQUIRE(out.find(":text \"\">") != std::string::npos); /* empty => ambiguous bare => quoted "" (unq) */
}
TEST_CASE("span_pp-quoted-text", "[span_pp]") {
/* text containing a space is ambiguous bare, so unq quotes it */
const char * text = "a b";
xo::mm::span<const char> sp(text, text + 3);
std::string out = pretty_of(sp);
REQUIRE(out.find(":text \"a b\"") != std::string::npos);
}
} /*namespace ut*/
/* end span_pp.test.cpp */