xo-umbrella2/xo-ppsink/utest/FlatSink.test.cpp

31 lines
842 B
C++

/* @file FlatSink.test.cpp */
#include <xo/ppsink/FlatSink.hpp>
#include <xo/ppsink/pretty_ostream.hpp>
#include <catch2/catch.hpp>
#include <sstream>
using xo::pp::FlatSink;
using xo::pp::PpSink;
TEST_CASE("flatsink-put-and-noop-structure", "[flatsink]") {
/* FlatSink writes put() text straight through; begin/split/end are no-ops */
std::stringstream ss;
FlatSink sink(ss.rdbuf());
sink.put("hello").begin().put("a").split().put("b").end().put("!");
REQUIRE(ss.str() == "helloab!");
}
TEST_CASE("flatsink-stream-open", "[flatsink]") {
/* stream_open returns an inserter that writes straight to the ostream */
std::stringstream ss;
FlatSink sink(ss.rdbuf());
{
auto ins = sink.stream_open(64);
ins << 42 << ' ' << "x";
ins.finish();
}
REQUIRE(ss.str() == "42 x");
}