#include <vector>
#include <string>
+#include <type_traits>
+
namespace pp
{
public:
void append(const std::string &line);
+
+ template <typename Derived>
+ typename std::enable_if<std::is_base_of<MultiLineText, Derived>::value>::type
+ append(const Derived &txt)
+ {
+ for (uint32_t n = 0; n < txt.lines(); ++n)
+ {
+ append(txt.line(n));
+ }
+ }
+
template <typename... Args> void append(const Args &... args) { append(fmt(args...)); }
public:
ASSERT_EQ(doc.line(2), "A");
}
+struct TwoLineDocument final : public pp::MultiLineText
+{
+ uint32_t lines(void) const override { return 2; }
+
+ const std::string &line(uint32_t n) const override { return _lines[n]; }
+
+ std::string _lines[2];
+};
+
+TEST(LINEAR_DOCUMENT, append_multi_line_text)
+{
+ pp::LinearDocument doc;
+ TwoLineDocument sub;
+
+ sub._lines[0] = "B";
+ sub._lines[1] = " C";
+
+ doc.append("A");
+ doc.indent();
+
+ doc.append(sub);
+ doc.unindent();
+ doc.append("D");
+
+ ASSERT_EQ(doc.lines(), 4);
+
+ ASSERT_EQ(doc.line(0), "A");
+ ASSERT_EQ(doc.line(1), " B");
+ ASSERT_EQ(doc.line(2), " C");
+ ASSERT_EQ(doc.line(3), "D");
+}
+
TEST(LINEAR_DOCUMENT, document_append)
{
pp::LinearDocument doc{pp::LinearDocument::Direction::Forward};