mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Fixed line wrap bug
Added line wrap tests and modified wrap algo to wrap within words using a -
This commit is contained in:
parent
29426b6359
commit
2927c240a1
@ -25,8 +25,14 @@ namespace Catch {
|
||||
for( std::size_t pos = 0; pos < paragraph.size(); ++pos ) {
|
||||
if( pos == width ) {
|
||||
addIndent( os, indent );
|
||||
os << paragraph.substr( 0, wrapPoint ) << "\n";
|
||||
return recursivelyWrapLine( os, paragraph.substr( wrapPoint+1 ), columns, indent+tab );
|
||||
if( paragraph[wrapPoint] == ' ' ) {
|
||||
os << paragraph.substr( 0, wrapPoint ) << "\n";
|
||||
while( paragraph[++wrapPoint] == ' ' );
|
||||
}
|
||||
else {
|
||||
os << paragraph.substr( 0, --wrapPoint ) << "-\n";
|
||||
}
|
||||
return recursivelyWrapLine( os, paragraph.substr( wrapPoint ), columns, indent+tab );
|
||||
}
|
||||
if( paragraph[pos] == '\t' ) {
|
||||
tab = pos;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include "catch_self_test.hpp"
|
||||
#include "catch_line_wrap.h"
|
||||
|
||||
TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" ) {
|
||||
using namespace Catch;
|
||||
@ -422,5 +423,37 @@ TEST_CASE( "selftest/tags", "" ) {
|
||||
CHECK( oneTag.matchesTags( "~[hide]" ) == false );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
|
||||
// guide: 123456789012345678
|
||||
std::string testString = "one two three four";
|
||||
|
||||
SECTION( "No wrapping", "" ) {
|
||||
CHECK( Catch::wrapLongStrings( testString, 80, 0 ) == testString );
|
||||
CHECK( Catch::wrapLongStrings( testString, 18, 0 ) == testString );
|
||||
}
|
||||
SECTION( "Wrapped once", "" ) {
|
||||
CHECK( Catch::wrapLongStrings( testString, 17, 0 ) == "one two three\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 16, 0 ) == "one two three\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 15, 0 ) == "one two three\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 14, 0 ) == "one two three\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 13, 0 ) == "one two\nthree four" );
|
||||
}
|
||||
SECTION( "Wrapped twice", "" ) {
|
||||
CHECK( Catch::wrapLongStrings( testString, 9, 0 ) == "one two\nthree\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 8, 0 ) == "one two\nthree\nfour" );
|
||||
}
|
||||
SECTION( "Wrapped three times", "" ) {
|
||||
CHECK( Catch::wrapLongStrings( testString, 7, 0 ) == "one\ntwo\nthree\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 5, 0 ) == "one\ntwo\nthree\nfour" );
|
||||
}
|
||||
SECTION( "Short wrap", "" ) {
|
||||
CHECK( Catch::wrapLongStrings( "abcdef", 4, 0 ) == "abc-\ndef" );
|
||||
CHECK( Catch::wrapLongStrings( "abcdefg", 4, 0 ) == "abc-\ndefg" );
|
||||
CHECK( Catch::wrapLongStrings( "abcdefgh", 4, 0 ) == "abc-\ndef-\ngh" );
|
||||
|
||||
CHECK( Catch::wrapLongStrings( testString, 4, 0 ) == "one\ntwo\nthr-\nee\nfour" );
|
||||
CHECK( Catch::wrapLongStrings( testString, 3, 0 ) == "one\ntwo\nth-\nree\nfo-\nur" );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user