mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
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:
parent
9a56609569
commit
4a04682e49
105
include/external/tbc_text_format.h
vendored
105
include/external/tbc_text_format.h
vendored
@ -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() ) );
|
||||||
else if( remainder[width] == '\n' ) {
|
iterator itEnd = it+width;
|
||||||
spliceLine( indent, remainder, width );
|
iterator itNext = _str.end();
|
||||||
if( width <= 1 || remainder.size() != 1 )
|
|
||||||
remainder = remainder.substr( 1 );
|
iterator itNewLine = std::find( it, itEnd, '\n' );
|
||||||
indent = _attr.indent;
|
if( itNewLine != itEnd )
|
||||||
}
|
itEnd = itNewLine;
|
||||||
else {
|
|
||||||
pos = remainder.find_last_of( wrappableChars, width );
|
if( itEnd != strEnd ) {
|
||||||
if( pos != std::string::npos && pos > 0 ) {
|
bool foundWrapPoint = false;
|
||||||
spliceLine( indent, remainder, pos );
|
for( iterator findIt = itEnd; !foundWrapPoint & findIt >= it; --findIt ) {
|
||||||
if( remainder[0] == ' ' )
|
|
||||||
remainder = remainder.substr( 1 );
|
if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
|
||||||
|
itEnd = findIt+1;
|
||||||
|
itNext = findIt+1;
|
||||||
|
foundWrapPoint = true;
|
||||||
|
}
|
||||||
|
else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
|
||||||
|
itEnd = findIt;
|
||||||
|
itNext = findIt;
|
||||||
|
foundWrapPoint = true;
|
||||||
|
}
|
||||||
|
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 {
|
||||||
spliceLine( indent, remainder, width-1 );
|
while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
|
||||||
lines.back() += "-";
|
--itEnd;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
@ -584,11 +584,11 @@ 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) {
|
||||||
$a = 20;
|
$a = 20;
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
|
||||||
@ -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
|
||||||
|
|
||||||
|
@ -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,11 +6543,11 @@ 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) {
|
||||||
$a = 20;
|
$a = 20;
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
|
||||||
@ -6478,36 +6563,32 @@ PASSED:
|
|||||||
CHECK_THAT( what, Contains( "[@zzz]" ) )
|
CHECK_THAT( what, Contains( "[@zzz]" ) )
|
||||||
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:
|
||||||
CHECK_THAT( what, Contains( "file" ) )
|
CHECK_THAT( what, Contains( "file" ) )
|
||||||
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:
|
||||||
CHECK_THAT( what, Contains( "2" ) )
|
CHECK_THAT( what, Contains( "2" ) )
|
||||||
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:
|
||||||
CHECK_THAT( what, Contains( "10" ) )
|
CHECK_THAT( what, Contains( "10" ) )
|
||||||
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
|
||||||
|
|
||||||
|
@ -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 && operator" time="{duration}"/>
|
<testcase classname="global" name="Matchers can be (AllOf) composed with the && operator" time="{duration}"/>
|
||||||
|
@ -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">
|
||||||
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
|
<Section name="No wrapping">
|
||||||
<Original>
|
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
|
||||||
Text( testString, TextAttributes().setWidth( 15 ) ).toString() == "one two three\n four\n five\n six"
|
<Original>
|
||||||
</Original>
|
Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString
|
||||||
<Expanded>
|
</Original>
|
||||||
"one two three
|
<Expanded>
|
||||||
four
|
"one,two(three) <here>"
|
||||||
five
|
|
||||||
six"
|
|
||||||
==
|
==
|
||||||
"one two three
|
"one,two(three) <here>"
|
||||||
four
|
</Expanded>
|
||||||
five
|
</Expression>
|
||||||
six"
|
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
|
||||||
</Expanded>
|
<Original>
|
||||||
</Expression>
|
Text( testString, TextAttributes().setWidth( 24 ) ).toString() == testString
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
"one,two(three) <here>"
|
||||||
|
==
|
||||||
|
"one,two(three) <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<here>"
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
"one,two
|
||||||
|
(three)
|
||||||
|
<here>"
|
||||||
|
==
|
||||||
|
"one,two
|
||||||
|
(three)
|
||||||
|
<here>"
|
||||||
|
</Expanded>
|
||||||
|
</Expression>
|
||||||
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
|
</Section>
|
||||||
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
</Section>
|
</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<here>"
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(thre-
|
||||||
|
e)
|
||||||
|
<here>"
|
||||||
|
==
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(thre-
|
||||||
|
e)
|
||||||
|
<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<her-\ne>"
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(thr-
|
||||||
|
ee)
|
||||||
|
<her-
|
||||||
|
e>"
|
||||||
|
==
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(thr-
|
||||||
|
ee)
|
||||||
|
<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<he-\nre>"
|
||||||
|
</Original>
|
||||||
|
<Expanded>
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(th-
|
||||||
|
ree)
|
||||||
|
<he-
|
||||||
|
re>"
|
||||||
|
==
|
||||||
|
"one,
|
||||||
|
two
|
||||||
|
(th-
|
||||||
|
ree)
|
||||||
|
<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>
|
||||||
|
@ -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,16 +314,23 @@ 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>" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Catch;
|
using namespace Catch;
|
||||||
|
Loading…
Reference in New Issue
Block a user