"Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. "
"During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet. \n"
"Pursued by the Empire’s sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy..."
).width(40);
SECTION( "no indent" ) {
auto lines = toVector(col);
REQUIRE(lines[0] == "It is a period of civil war. Rebel");
REQUIRE(lines[1] == "spaceships, striking from a hidden base,");
REQUIRE(lines[2] == "have won their first victory against the");
REQUIRE(lines[3] == "evil Galactic Empire. During the battle,");
}
SECTION( "indent only" ) {
col.indent( 4 );
auto lines = toVector(col);
// 0123456789012345678901234567890123456789
REQUIRE(lines[0] == " It is a period of civil war. Rebel");
REQUIRE(lines[1] == " spaceships, striking from a hidden");
REQUIRE(lines[2] == " base, have won their first victory");
REQUIRE(lines[3] == " against the evil Galactic Empire." );
}
SECTION( "initial indent only" ) {
col.initialIndent( 8 );
auto lines = toVector(col);
// 0123456789012345678901234567890123456789
REQUIRE(lines[0] == " It is a period of civil war.");
REQUIRE(lines[1] == "Rebel spaceships, striking from a hidden");
REQUIRE(lines[2] == "base, have won their first victory");
REQUIRE(lines[3] == "against the evil Galactic Empire. During" );
}
SECTION( "initial indent > indent" ) {
col.initialIndent( 8 ).indent( 4 );
auto lines = toVector(col);
// 0123456789012345678901234567890123456789
REQUIRE(lines[0] == " It is a period of civil war.");
REQUIRE(lines[1] == " Rebel spaceships, striking from a");
REQUIRE(lines[2] == " hidden base, have won their first");
REQUIRE(lines[3] == " victory against the evil Galactic" );
}
SECTION( "initial indent < indent" ) {
col.initialIndent( 4 ).indent( 8 );
auto lines = toVector(col);
// 0123456789012345678901234567890123456789
REQUIRE(lines[0] == " It is a period of civil war. Rebel");
REQUIRE(lines[1] == " spaceships, striking from a");
REQUIRE(lines[2] == " hidden base, have won their");
REQUIRE(lines[3] == " first victory against the evil" );
}
}
TEST_CASE( "combined columns" ) {
auto a = Column( "This is a load of text that should go on the left" ).width(10);
auto b = Column( "Here's some more strings that should be formatted to the right. "
"It's longer so there should be blanks on the left" ).width(12);
auto layout = a + Spacer(4) + b;
auto lines = toVector( layout );
CHECK( lines[0] == "This is a Here's some" );
CHECK( lines[1] == "load of more strings" );
CHECK( lines[2] == "text that that should" );
CHECK( lines[6] == " longer so" );
CHECK( layout.toString() ==
"This is a Here's some\n"
"load of more strings\n"
"text that that should\n"
"should go be formatted\n"
"on the to the\n"
"left right. It's\n"
" longer so\n"
" there should\n"
" be blanks on\n"
" the left" );
}
TEST_CASE( "indent at existing newlines" ) {
auto col = Column( "This text has\n newlines\nembedded in it - but also some long text that should be wrapped" )
.width(20)
.indent(2);
REQUIRE( col.toString() ==
" This text has\n"
" newlines\n"
" embedded in it -\n"
" but also some long\n"
" text that should\n"
" be wrapped" );
}
TEST_CASE( "another long string" ) {
// This test is taken from @JoeyGrajciar's PR against the Clara repo:
// https://github.com/catchorg/Clara/pull/74
constauto long_string = std::string(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nisl \n"
"massa, luctus ut ligula vitae, suscipit tempus velit. Vivamus sodales, quam in \n"
"convallis posuere, libero nisi ultricies orci, nec lobortis.\n");
auto col = Column( long_string )
.width(79)
.indent(2);
REQUIRE( col.toString() ==
" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nisl \n"
" massa, luctus ut ligula vitae, suscipit tempus velit. Vivamus sodales, quam\n"
" in \n"
" convallis posuere, libero nisi ultricies orci, nec lobortis." );