Text formatting rework

Rewrote main wrapping loop. Now uses iterators instead of indices and intermediate strings.
Differentiates between chars to wrap before, after or instead of.
Doesn’t preserve trailing newlines.
Wraps or more characters.
Dropped support for using tab character as an indent setting control char.
Hopefully avoids all the undefined behaviour and other bugs of the previous implementation.
This commit is contained in:
Phil Nash 2017-01-17 17:13:23 +00:00
parent 9a56609569
commit 4a04682e49
6 changed files with 325 additions and 130 deletions

View File

@ -37,19 +37,16 @@ namespace Tbc {
TextAttributes() TextAttributes()
: initialIndent( std::string::npos ), : initialIndent( std::string::npos ),
indent( 0 ), indent( 0 ),
width( consoleWidth-1 ), width( consoleWidth-1 )
tabChar( '\t' )
{} {}
TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
std::size_t initialIndent; // indent of first line, or npos std::size_t initialIndent; // indent of first line, or npos
std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
std::size_t width; // maximum width of text, including indent. Longer text will wrap std::size_t width; // maximum width of text, including indent. Longer text will wrap
char tabChar; // If this char is seen the indent is changed to current pos
}; };
class Text { class Text {
@ -57,63 +54,74 @@ namespace Tbc {
Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
: attr( _attr ) : attr( _attr )
{ {
std::string wrappableChars = " [({.,/|\\-"; const std::string wrappableBeforeChars = "[({<\t";
std::size_t indent = _attr.initialIndent != std::string::npos const std::string wrappableAfterChars = "])}>-,./|\\";
? _attr.initialIndent const std::string wrappableInsteadOfChars = " \n\r";
: _attr.indent; std::string indent = _attr.initialIndent != std::string::npos
std::string remainder = _str; ? std::string( _attr.initialIndent, ' ' )
: std::string( _attr.indent, ' ' );
typedef std::string::const_iterator iterator;
iterator it = _str.begin();
const iterator strEnd = _str.end();
while( it != strEnd ) {
while( !remainder.empty() ) {
if( lines.size() >= 1000 ) { if( lines.size() >= 1000 ) {
lines.push_back( "... message truncated due to excessive size" ); lines.push_back( "... message truncated due to excessive size" );
return; return;
} }
std::size_t tabPos = std::string::npos;
std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
std::size_t pos = remainder.find_first_of( '\n' );
if( pos <= width ) {
width = pos;
}
pos = remainder.find_last_of( _attr.tabChar, width );
if( pos != std::string::npos ) {
tabPos = pos;
if( remainder[width] == '\n' )
width--;
remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
}
if( width == remainder.size() ) {
spliceLine( indent, remainder, width ); std::string suffix;
std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
iterator itEnd = it+width;
iterator itNext = _str.end();
iterator itNewLine = std::find( it, itEnd, '\n' );
if( itNewLine != itEnd )
itEnd = itNewLine;
if( itEnd != strEnd ) {
bool foundWrapPoint = false;
for( iterator findIt = itEnd; !foundWrapPoint & findIt >= it; --findIt ) {
if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
itEnd = findIt+1;
itNext = findIt+1;
foundWrapPoint = true;
} }
else if( remainder[width] == '\n' ) { else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
spliceLine( indent, remainder, width ); itEnd = findIt;
if( width <= 1 || remainder.size() != 1 ) itNext = findIt;
remainder = remainder.substr( 1 ); foundWrapPoint = true;
indent = _attr.indent; }
else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
itNext = findIt+1;
itEnd = findIt;
foundWrapPoint = true;
}
}
if( !foundWrapPoint ) {
// No good wrap char, so we'll break mid word and add a hyphen
--itEnd;
itNext = itEnd;
suffix = "-";
} }
else { else {
pos = remainder.find_last_of( wrappableChars, width ); while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
if( pos != std::string::npos && pos > 0 ) { --itEnd;
spliceLine( indent, remainder, pos );
if( remainder[0] == ' ' )
remainder = remainder.substr( 1 );
} }
else {
spliceLine( indent, remainder, width-1 );
lines.back() += "-";
}
if( lines.size() == 1 )
indent = _attr.indent;
if( tabPos != std::string::npos )
indent += tabPos;
} }
lines.push_back( indent + std::string( it, itEnd ) + suffix );
if( indent.size() != _attr.indent )
indent = std::string( _attr.indent, ' ' );
it = itNext;
} }
} }
void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
_remainder = _remainder.substr( _pos );
}
typedef std::vector<std::string>::const_iterator const_iterator; typedef std::vector<std::string>::const_iterator const_iterator;
@ -138,6 +146,7 @@ namespace Tbc {
return _stream; return _stream;
} }
private: private:
std::string str; std::string str;
TextAttributes attr; TextAttributes attr;

View File

@ -584,7 +584,7 @@ MiscTests.cpp:<line number>: FAILED:
CHECK( s1 == s2 ) CHECK( s1 == s2 )
with expansion: with expansion:
"if ($b == 10) { "if ($b == 10) {
$a= 20; $a = 20;
}" }"
== ==
"if ($b == 10) { "if ($b == 10) {
@ -831,5 +831,5 @@ with expansion:
=============================================================================== ===============================================================================
test cases: 159 | 115 passed | 42 failed | 2 failed as expected test cases: 159 | 115 passed | 42 failed | 2 failed as expected
assertions: 909 | 813 passed | 78 failed | 18 failed as expected assertions: 915 | 819 passed | 78 failed | 18 failed as expected

View File

@ -2932,13 +2932,9 @@ TestMain.cpp:<line number>
TestMain.cpp:<line number>: TestMain.cpp:<line number>:
PASSED: PASSED:
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" ) CHECK( Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef" )
with expansion: with expansion:
"abcdef "abcdef" == "abcdef"
"
==
"abcdef
"
TestMain.cpp:<line number>: TestMain.cpp:<line number>:
PASSED: PASSED:
@ -2948,13 +2944,19 @@ with expansion:
TestMain.cpp:<line number>: TestMain.cpp:<line number>:
PASSED: PASSED:
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" ) CHECK( Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" )
with expansion: with expansion:
"abcdef "abcdef" == "abcdef"
"
TestMain.cpp:<line number>:
PASSED:
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 5 ) ).toString() == "abcd-\nef" )
with expansion:
"abcd-
ef"
== ==
"abcdef "abcd-
" ef"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Long strings can be wrapped Long strings can be wrapped
@ -3024,24 +3026,107 @@ with expansion:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Long strings can be wrapped Long strings can be wrapped
With tabs With wrap-before/ after characters
No wrapping
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
TestMain.cpp:<line number> TestMain.cpp:<line number>
............................................................................... ...............................................................................
TestMain.cpp:<line number>: TestMain.cpp:<line number>:
PASSED: PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 15 ) ).toString() == "one two three\n four\n five\n six" ) CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString )
with expansion: with expansion:
"one two three "one,two(three) <here>"
four
five
six"
== ==
"one two three "one,two(three) <here>"
four
five TestMain.cpp:<line number>:
six" PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 24 ) ).toString() == testString )
with expansion:
"one,two(three) <here>"
==
"one,two(three) <here>"
-------------------------------------------------------------------------------
Long strings can be wrapped
With wrap-before/ after characters
Wrap before
-------------------------------------------------------------------------------
TestMain.cpp:<line number>
...............................................................................
TestMain.cpp:<line number>:
PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 11 ) ).toString() == "one,two\n(three)\n<here>" )
with expansion:
"one,two
(three)
<here>"
==
"one,two
(three)
<here>"
-------------------------------------------------------------------------------
Long strings can be wrapped
With wrap-before/ after characters
Wrap after
-------------------------------------------------------------------------------
TestMain.cpp:<line number>
...............................................................................
TestMain.cpp:<line number>:
PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one,\ntwo\n(thre-\ne)\n<here>" )
with expansion:
"one,
two
(thre-
e)
<here>"
==
"one,
two
(thre-
e)
<here>"
TestMain.cpp:<line number>:
PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one,\ntwo\n(thr-\nee)\n<her-\ne>" )
with expansion:
"one,
two
(thr-
ee)
<her-
e>"
==
"one,
two
(thr-
ee)
<her-
e>"
TestMain.cpp:<line number>:
PASSED:
CHECK( Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one,\ntwo\n(th-\nree)\n<he-\nre>" )
with expansion:
"one,
two
(th-
ree)
<he-
re>"
==
"one,
two
(th-
ree)
<he-
re>"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Long text is truncted Long text is truncted
@ -6458,7 +6543,7 @@ MiscTests.cpp:<line number>: FAILED:
CHECK( s1 == s2 ) CHECK( s1 == s2 )
with expansion: with expansion:
"if ($b == 10) { "if ($b == 10) {
$a= 20; $a = 20;
}" }"
== ==
"if ($b == 10) { "if ($b == 10) {
@ -6479,8 +6564,7 @@ PASSED:
with expansion: with expansion:
"error: tag alias, "[@zzz]" already registered. "error: tag alias, "[@zzz]" already registered.
First seen at file:2 First seen at file:2
Redefined at file:10" contains: " Redefined at file:10" contains: "[@zzz]"
[@zzz]"
TagAliasTests.cpp:<line number>: TagAliasTests.cpp:<line number>:
PASSED: PASSED:
@ -6488,8 +6572,7 @@ PASSED:
with expansion: with expansion:
"error: tag alias, "[@zzz]" already registered. "error: tag alias, "[@zzz]" already registered.
First seen at file:2 First seen at file:2
Redefined at file:10" contains: Redefined at file:10" contains: "file"
"file"
TagAliasTests.cpp:<line number>: TagAliasTests.cpp:<line number>:
PASSED: PASSED:
@ -6497,8 +6580,7 @@ PASSED:
with expansion: with expansion:
"error: tag alias, "[@zzz]" already registered. "error: tag alias, "[@zzz]" already registered.
First seen at file:2 First seen at file:2
Redefined at file:10" contains: Redefined at file:10" contains: "2"
"2"
TagAliasTests.cpp:<line number>: TagAliasTests.cpp:<line number>:
PASSED: PASSED:
@ -6506,8 +6588,7 @@ PASSED:
with expansion: with expansion:
"error: tag alias, "[@zzz]" already registered. "error: tag alias, "[@zzz]" already registered.
First seen at file:2 First seen at file:2
Redefined at file:10" contains: Redefined at file:10" contains: "10"
"10"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Tag alias can be registered against tag patterns Tag alias can be registered against tag patterns
@ -8972,5 +9053,5 @@ PASSED:
=============================================================================== ===============================================================================
test cases: 159 | 114 passed | 43 failed | 2 failed as expected test cases: 159 | 114 passed | 43 failed | 2 failed as expected
assertions: 911 | 813 passed | 80 failed | 18 failed as expected assertions: 917 | 819 passed | 80 failed | 18 failed as expected

View File

@ -1,6 +1,6 @@
<?xml version="1.1" encoding="UTF-8"?> <?xml version="1.1" encoding="UTF-8"?>
<testsuites> <testsuites>
<testsuite name="<exe-name>" errors="13" failures="68" tests="912" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="13" failures="68" tests="918" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="global" name="'Not' checks that should fail" time="{duration}"> <testcase classname="global" name="'Not' checks that should fail" time="{duration}">
<failure message="false != false" type="CHECK"> <failure message="false != false" type="CHECK">
@ -242,7 +242,9 @@ ConditionTests.cpp:<line number>
<testcase classname="Long strings can be wrapped" name="With newlines/Trailing newline" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With newlines/Trailing newline" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With newlines/Wrapped once" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With newlines/Wrapped once" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With newlines/Wrapped twice" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With newlines/Wrapped twice" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With tabs" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/No wrapping" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap before" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap after" time="{duration}"/>
<testcase classname="global" name="Long text is truncted" time="{duration}"/> <testcase classname="global" name="Long text is truncted" time="{duration}"/>
<testcase classname="global" name="ManuallyRegistered" time="{duration}"/> <testcase classname="global" name="ManuallyRegistered" time="{duration}"/>
<testcase classname="global" name="Matchers can be (AllOf) composed with the &amp;&amp; operator" time="{duration}"/> <testcase classname="global" name="Matchers can be (AllOf) composed with the &amp;&amp; operator" time="{duration}"/>

View File

@ -2987,14 +2987,10 @@ three four"
<Section name="Trailing newline"> <Section name="Trailing newline">
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original> <Original>
Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef"
</Original> </Original>
<Expanded> <Expanded>
"abcdef "abcdef" == "abcdef"
"
==
"abcdef
"
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
@ -3007,19 +3003,27 @@ three four"
</Expression> </Expression>
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original> <Original>
Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef"
</Original> </Original>
<Expanded> <Expanded>
"abcdef "abcdef" == "abcdef"
"
==
"abcdef
"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/> <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( "abcdef\n", TextAttributes().setWidth( 5 ) ).toString() == "abcd-\nef"
</Original>
<Expanded>
"abcd-
ef"
==
"abcd-
ef"
</Expanded>
</Expression>
<OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="3" failures="0" expectedFailures="0"/> <OverallResults successes="4" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="With newlines"> <Section name="With newlines">
<Section name="Wrapped once"> <Section name="Wrapped once">
@ -3091,25 +3095,116 @@ four"
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="With tabs"> <Section name="With wrap-before/ after characters">
<Section name="No wrapping">
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original> <Original>
Text( testString, TextAttributes().setWidth( 15 ) ).toString() == "one two three\n four\n five\n six" Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString
</Original> </Original>
<Expanded> <Expanded>
"one two three "one,two(three) &lt;here>"
four
five
six"
== ==
"one two three "one,two(three) &lt;here>"
four </Expanded>
five </Expression>
six" <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( testString, TextAttributes().setWidth( 24 ) ).toString() == testString
</Original>
<Expanded>
"one,two(three) &lt;here>"
==
"one,two(three) &lt;here>"
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="With wrap-before/ after characters">
<Section name="Wrap before">
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( testString, TextAttributes().setWidth( 11 ) ).toString() == "one,two\n(three)\n&lt;here>"
</Original>
<Expanded>
"one,two
(three)
&lt;here>"
==
"one,two
(three)
&lt;here>"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="With wrap-before/ after characters">
<Section name="Wrap after">
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one,\ntwo\n(thre-\ne)\n&lt;here>"
</Original>
<Expanded>
"one,
two
(thre-
e)
&lt;here>"
==
"one,
two
(thre-
e)
&lt;here>"
</Expanded>
</Expression>
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one,\ntwo\n(thr-\nee)\n&lt;her-\ne>"
</Original>
<Expanded>
"one,
two
(thr-
ee)
&lt;her-
e>"
==
"one,
two
(thr-
ee)
&lt;her-
e>"
</Expanded>
</Expression>
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
<Original>
Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one,\ntwo\n(th-\nree)\n&lt;he-\nre>"
</Original>
<Expanded>
"one,
two
(th-
ree)
&lt;he-
re>"
==
"one,
two
(th-
ree)
&lt;he-
re>"
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="Long text is truncted"> <TestCase name="Long text is truncted">
@ -9432,7 +9527,7 @@ there"
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="813" failures="81" expectedFailures="18"/> <OverallResults successes="819" failures="81" expectedFailures="18"/>
</Group> </Group>
<OverallResults successes="813" failures="80" expectedFailures="18"/> <OverallResults successes="819" failures="80" expectedFailures="18"/>
</Catch> </Catch>

View File

@ -299,9 +299,10 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
CHECK( Text( testString, TextAttributes().setWidth( 10 ) ).toString() == testString ); CHECK( Text( testString, TextAttributes().setWidth( 10 ) ).toString() == testString );
} }
SECTION( "Trailing newline" , "" ) { SECTION( "Trailing newline" , "" ) {
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" ); CHECK( Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef" );
CHECK( Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" ); CHECK( Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" );
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" ); CHECK( Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" );
CHECK( Text( "abcdef\n", TextAttributes().setWidth( 5 ) ).toString() == "abcd-\nef" );
} }
SECTION( "Wrapped once", "" ) { SECTION( "Wrapped once", "" ) {
CHECK( Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" ); CHECK( Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" );
@ -313,15 +314,22 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
} }
} }
SECTION( "With tabs", "" ) { SECTION( "With wrap-before/ after characters", "" ) {
std::string testString = "one,two(three) <here>";
// guide: 1234567890123456789 SECTION( "No wrapping", "" ) {
std::string testString = "one two \tthree four five six"; CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
CHECK( Text( testString, TextAttributes().setWidth( 24 ) ).toString() == testString );
CHECK( Text( testString, TextAttributes().setWidth( 15 ) ).toString() }
== "one two three\n four\n five\n six" ); SECTION( "Wrap before", "" ) {
CHECK( Text( testString, TextAttributes().setWidth( 11 ) ).toString() == "one,two\n(three)\n<here>" );
}
SECTION( "Wrap after", "" ) {
CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one,\ntwo\n(thre-\ne)\n<here>" );
CHECK( Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one,\ntwo\n(thr-\nee)\n<her-\ne>" );
CHECK( Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one,\ntwo\n(th-\nree)\n<he-\nre>" );
}
} }
} }