From b052bd729af9f46b378c7e9ffc3f74f81b5cbb93 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 27 Mar 2013 19:08:16 +0000 Subject: [PATCH] Refactored string wrapper - to be much more flexible (writes to vector) - fixed a couple of bugs --- include/catch_runner.hpp | 2 +- include/internal/catch_line_wrap.h | 32 +- include/internal/catch_line_wrap.hpp | 121 ++- include/reporters/catch_reporter_console.hpp | 11 +- .../SelfTest/Baselines/approvedResults.txt | 871 +++++++++++++----- projects/SelfTest/TestMain.cpp | 85 +- 6 files changed, 806 insertions(+), 316 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index edceeccb..6d63b878 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -161,7 +161,7 @@ namespace Catch { displayedSpecificOption = true; std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n" << opt.optionSummary() << "\n\n" - << wrapLongStrings( opt.optionDescription(), 80, 2 ) << "\n" << std::endl; + << LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ).toString() << "\n" << std::endl; } } diff --git a/include/internal/catch_line_wrap.h b/include/internal/catch_line_wrap.h index 1197fb0b..e08dada1 100644 --- a/include/internal/catch_line_wrap.h +++ b/include/internal/catch_line_wrap.h @@ -9,11 +9,39 @@ #define TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED #include +#include namespace Catch { - void wrapLongStrings( std::ostream& stream, const std::string& str, std::size_t columns, std::size_t indent = 0 ); - std::string wrapLongStrings( const std::string& str, std::size_t columns, std::size_t indent = 0 ); + class LineWrapper { + public: + LineWrapper( std::size_t _indent, std::size_t _right ); + LineWrapper( std::size_t _right ); + LineWrapper(); + + LineWrapper& setIndent( std::size_t _indent ); + LineWrapper& setRight( std::size_t _right ); + + LineWrapper& wrap( std::string const& _str ); + + std::ostream& intoStream( std::ostream& stream ) const; + std::string toString() const; + + typedef std::vector::const_iterator const_iterator; + + const_iterator begin() const { return lines.begin(); } + const_iterator end() const { return lines.end(); } + + private: + void wrapInternal( std::string const& _str ); + void addLine( const std::string& _line ); + + std::string indent; + std::size_t right; + std::size_t nextTab; + std::size_t tab; + std::vector lines; + }; } // end namespace Catch diff --git a/include/internal/catch_line_wrap.hpp b/include/internal/catch_line_wrap.hpp index 8a734fd8..bb8247d9 100644 --- a/include/internal/catch_line_wrap.hpp +++ b/include/internal/catch_line_wrap.hpp @@ -12,60 +12,91 @@ namespace Catch { - namespace { - inline void addIndent( std::ostream& os, std::size_t indent ) { - while( indent-- > 0 ) - os << ' '; - } - - inline void recursivelyWrapLine( std::ostream& os, std::string paragraph, std::size_t columns, std::size_t indent ) { - std::size_t width = columns-indent; - std::size_t tab = 0; - std::size_t wrapPoint = width; - for( std::size_t pos = 0; pos < paragraph.size(); ++pos ) { - if( pos == width ) { - addIndent( os, indent ); - 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 ); + + LineWrapper::LineWrapper( std::size_t _indent, std::size_t _right ) + : indent( _indent, ' ' ), + right( _right ), + nextTab( 0 ), + tab( 0 ) + {} + LineWrapper::LineWrapper( std::size_t _right ) + : right( _right ), + nextTab( 0 ), + tab( 0 ) + {} + LineWrapper::LineWrapper() + : right( CATCH_CONFIG_CONSOLE_WIDTH-1 ), + nextTab( 0 ), + tab( 0 ) + {} + + LineWrapper& LineWrapper::setIndent( std::size_t _indent ) { + indent = std::string( _indent, ' ' ); + return *this; + } + LineWrapper& LineWrapper::setRight( std::size_t _right ) { + right = _right; + return *this; + } + LineWrapper& LineWrapper::wrap( std::string const& _str ) { + nextTab = tab = 0; + wrapInternal( _str ); + return *this; + } + void LineWrapper::wrapInternal( std::string const& _str ) { + std::size_t width = right - indent.size(); + std::size_t wrapPoint = width-tab; + for( std::size_t pos = 0; pos < _str.size(); ++pos ) { + if( _str[pos] == '\n' ) + { + addLine( _str.substr( 0, pos ) ); + nextTab = tab = 0; + return wrapInternal( _str.substr( pos+1 ) ); + } + if( pos == width-tab ) { + if( _str[wrapPoint] == ' ' ) { + addLine( _str.substr( 0, wrapPoint ) ); + while( _str[++wrapPoint] == ' ' ); } - if( paragraph[pos] == '\t' ) { - tab = pos; - paragraph = paragraph.substr( 0, tab ) + paragraph.substr( tab+1 ); - pos--; - } - else if( paragraph[pos] == ' ' ) { - wrapPoint = pos; + else { + addLine( _str.substr( 0, --wrapPoint ) + '-' ); } + return wrapInternal( _str.substr( wrapPoint ) ); + } + if( _str[pos] == '\t' ) { + nextTab = pos; + std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 ); + return wrapInternal( withoutTab ); + } + else if( _str[pos] == ' ' ) { + wrapPoint = pos; } - addIndent( os, indent ); - os << paragraph; } + addLine( _str ); } - void wrapLongStrings( std::ostream& stream, const std::string& str, std::size_t columns, std::size_t indent ) { - std::string::size_type pos = 0; - std::string::size_type newline = str.find_first_of( '\n' ); - while( newline != std::string::npos ) { - std::string paragraph = str.substr( pos, newline-pos ); - recursivelyWrapLine( stream, paragraph, columns, indent ); - stream << "\n"; - pos = newline+1; - newline = str.find_first_of( '\n', pos ); + std::ostream& LineWrapper::intoStream( std::ostream& stream ) const { + for( const_iterator it = begin(), itEnd = end(); + it != itEnd; ++it ) { + if( it != begin() ) + stream << "\n"; + stream << *it; } - if( pos != str.size() ) - recursivelyWrapLine( stream, str.substr( pos, str.size()-pos ), columns, indent ); + return stream; } - - std::string wrapLongStrings( const std::string& str, std::size_t columns, std::size_t indent ) { + std::string LineWrapper::toString() const { std::ostringstream oss; - wrapLongStrings( oss, str, columns, indent ); - return oss.str(); + intoStream( oss ); + return oss.str(); + } + + void LineWrapper::addLine( const std::string& _line ) { + if( tab > 0 ) + lines.push_back( indent + std::string( tab, ' ' ) + _line ); + else + lines.push_back( indent + _line ); + if( nextTab > 0 ) + tab = nextTab; } } // end namespace Catch diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp index 042dbacc..b621aa6e 100644 --- a/include/reporters/catch_reporter_console.hpp +++ b/include/reporters/catch_reporter_console.hpp @@ -211,7 +211,7 @@ namespace Catch { if( result.hasExpandedExpression() ) { stream << "with expansion:\n"; TextColour colourGuard( TextColour::ReconstructedExpression ); - stream << wrapLongStrings( result.getExpandedExpression() ) << "\n"; + stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ).toString() << "\n"; } } void printMessage() const { @@ -219,8 +219,9 @@ namespace Catch { stream << messageLabel << ":" << "\n"; for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); it != itEnd; - ++it ) { - stream << wrapLongStrings( it->message ) << "\n"; + ++it ) { + LineWrapper().setIndent(2).wrap( it->message ).intoStream( stream ); + stream << "\n"; } } void printSourceInfo() const { @@ -228,10 +229,6 @@ namespace Catch { stream << result.getSourceInfo() << ": "; } - static std::string wrapLongStrings( std::string const& _string ){ - return Catch::wrapLongStrings( _string, CATCH_CONFIG_CONSOLE_WIDTH-1, 2 ); - } - std::ostream& stream; AssertionStats const& stats; AssertionResult const& result; diff --git a/projects/SelfTest/Baselines/approvedResults.txt b/projects/SelfTest/Baselines/approvedResults.txt index 65371a79..43fd126a 100644 --- a/projects/SelfTest/Baselines/approvedResults.txt +++ b/projects/SelfTest/Baselines/approvedResults.txt @@ -1,6 +1,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -CatchSelfTest is a CATCH v0.9 b27 (integration) host application. +CatchSelfTest is a CATCH v0.9 b28 (integration) host application. Run with -? for options ------------------------------------------------------------------------------- @@ -4167,20 +4167,21 @@ with expansion: ------------------------------------------------------------------------------- Long strings can be wrapped + plain string No wrapping ............................................................................... -TestMain.cpp:433: +TestMain.cpp:435: PASSED: - CHECK( Catch::wrapLongStrings( testString, 80, 0 ) == testString ) + CHECK( Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString ) with expansion: "one two three four" == "one two three four" -TestMain.cpp:434: +TestMain.cpp:436: PASSED: - CHECK( Catch::wrapLongStrings( testString, 18, 0 ) == testString ) + CHECK( Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString ) with expansion: "one two three four" == @@ -4188,32 +4189,13 @@ with expansion: ------------------------------------------------------------------------------- Long strings can be wrapped + plain string Wrapped once ............................................................................... -TestMain.cpp:437: -PASSED: - CHECK( Catch::wrapLongStrings( testString, 17, 0 ) == "one two three\nfour" ) -with expansion: - "one two three - four" - == - "one two three - four" - -TestMain.cpp:438: -PASSED: - CHECK( Catch::wrapLongStrings( testString, 16, 0 ) == "one two three\nfour" ) -with expansion: - "one two three - four" - == - "one two three - four" - TestMain.cpp:439: PASSED: - CHECK( Catch::wrapLongStrings( testString, 15, 0 ) == "one two three\nfour" ) + CHECK( Catch::LineWrapper( 17 ).wrap( testString ).toString() == "one two three\nfour" ) with expansion: "one two three four" @@ -4223,7 +4205,7 @@ with expansion: TestMain.cpp:440: PASSED: - CHECK( Catch::wrapLongStrings( testString, 14, 0 ) == "one two three\nfour" ) + CHECK( Catch::LineWrapper( 16 ).wrap( testString ).toString() == "one two three\nfour" ) with expansion: "one two three four" @@ -4233,7 +4215,27 @@ with expansion: TestMain.cpp:441: PASSED: - CHECK( Catch::wrapLongStrings( testString, 13, 0 ) == "one two\nthree four" ) + CHECK( Catch::LineWrapper( 15 ).wrap( testString ).toString() == "one two three\nfour" ) +with expansion: + "one two three + four" + == + "one two three + four" + +TestMain.cpp:442: +PASSED: + CHECK( Catch::LineWrapper( 14 ).wrap( testString ).toString() == "one two three\nfour" ) +with expansion: + "one two three + four" + == + "one two three + four" + +TestMain.cpp:443: +PASSED: + CHECK( Catch::LineWrapper( 13 ).wrap( testString ).toString() == "one two\nthree four" ) with expansion: "one two three four" @@ -4243,12 +4245,13 @@ with expansion: ------------------------------------------------------------------------------- Long strings can be wrapped + plain string Wrapped twice ............................................................................... -TestMain.cpp:444: +TestMain.cpp:446: PASSED: - CHECK( Catch::wrapLongStrings( testString, 9, 0 ) == "one two\nthree\nfour" ) + CHECK( Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" ) with expansion: "one two three @@ -4258,9 +4261,9 @@ with expansion: three four" -TestMain.cpp:445: +TestMain.cpp:447: PASSED: - CHECK( Catch::wrapLongStrings( testString, 8, 0 ) == "one two\nthree\nfour" ) + CHECK( Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" ) with expansion: "one two three @@ -4272,12 +4275,13 @@ with expansion: ------------------------------------------------------------------------------- Long strings can be wrapped + plain string Wrapped three times ............................................................................... -TestMain.cpp:448: +TestMain.cpp:450: PASSED: - CHECK( Catch::wrapLongStrings( testString, 7, 0 ) == "one\ntwo\nthree\nfour" ) + CHECK( Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ) with expansion: "one two @@ -4289,9 +4293,9 @@ with expansion: three four" -TestMain.cpp:449: +TestMain.cpp:451: PASSED: - CHECK( Catch::wrapLongStrings( testString, 5, 0 ) == "one\ntwo\nthree\nfour" ) + CHECK( Catch::LineWrapper( 5 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ) with expansion: "one two @@ -4305,44 +4309,45 @@ with expansion: ------------------------------------------------------------------------------- Long strings can be wrapped + plain string Short wrap ............................................................................... -TestMain.cpp:452: -PASSED: - CHECK( Catch::wrapLongStrings( "abcdef", 4, 0 ) == "abc-\ndef" ) -with expansion: - "abc- - def" - == - "abc- - def" - -TestMain.cpp:453: -PASSED: - CHECK( Catch::wrapLongStrings( "abcdefg", 4, 0 ) == "abc-\ndefg" ) -with expansion: - "abc- - defg" - == - "abc- - defg" - TestMain.cpp:454: PASSED: - CHECK( Catch::wrapLongStrings( "abcdefgh", 4, 0 ) == "abc-\ndef-\ngh" ) + CHECK( Catch::LineWrapper( 4 ).wrap( "abcdef" ).toString() == "abc-\ndef" ) with expansion: "abc- - def- - gh" + def" == "abc- - def- - gh" + def" + +TestMain.cpp:455: +PASSED: + CHECK( Catch::LineWrapper( 4 ).wrap( "abcdefg" ).toString() == "abc-\ndefg" ) +with expansion: + "abc- + defg" + == + "abc- + defg" TestMain.cpp:456: PASSED: - CHECK( Catch::wrapLongStrings( testString, 4, 0 ) == "one\ntwo\nthr-\nee\nfour" ) + CHECK( Catch::LineWrapper( 4 ).wrap("abcdefgh" ).toString() == "abc-\ndef-\ngh" ) +with expansion: + "abc- + def- + gh" + == + "abc- + def- + gh" + +TestMain.cpp:458: +PASSED: + CHECK( Catch::LineWrapper( 4 ).wrap( testString ).toString() == "one\ntwo\nthr-\nee\nfour" ) with expansion: "one two @@ -4356,9 +4361,9 @@ with expansion: ee four" -TestMain.cpp:457: +TestMain.cpp:459: PASSED: - CHECK( Catch::wrapLongStrings( testString, 3, 0 ) == "one\ntwo\nth-\nree\nfo-\nur" ) + CHECK( Catch::LineWrapper( 3 ).wrap( testString ).toString() == "one\ntwo\nth-\nree\nfo-\nur" ) with expansion: "one two @@ -4374,6 +4379,136 @@ with expansion: fo- ur" +------------------------------------------------------------------------------- +Long strings can be wrapped + With newlines + No wrapping +............................................................................... + +TestMain.cpp:469: +PASSED: + CHECK( Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString ) +with expansion: + "one two + three four" + == + "one two + three four" + +TestMain.cpp:470: +PASSED: + CHECK( Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString ) +with expansion: + "one two + three four" + == + "one two + three four" + +TestMain.cpp:471: +PASSED: + CHECK( Catch::LineWrapper( 10 ).wrap( testString ).toString() == testString ) +with expansion: + "one two + three four" + == + "one two + three four" + +------------------------------------------------------------------------------- +Long strings can be wrapped + With newlines + Trailing newline +............................................................................... + +TestMain.cpp:474: +PASSED: + CHECK( Catch::LineWrapper( 10 ).wrap( "abcdef\n" ).toString() == "abcdef\n" ) +with expansion: + "abcdef + " + == + "abcdef + " + +TestMain.cpp:475: +PASSED: + CHECK( Catch::LineWrapper( 6 ).wrap( "abcdef" ).toString() == "abcdef" ) +with expansion: + "abcdef" == "abcdef" + +TestMain.cpp:476: +PASSED: + CHECK( Catch::LineWrapper( 6 ).wrap( "abcdef\n" ).toString() == "abcdef\n" ) +with expansion: + "abcdef + " + == + "abcdef + " + +------------------------------------------------------------------------------- +Long strings can be wrapped + With newlines + Wrapped once +............................................................................... + +TestMain.cpp:479: +PASSED: + CHECK( Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" ) +with expansion: + "one two + three + four" + == + "one two + three + four" + +TestMain.cpp:480: +PASSED: + CHECK( Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" ) +with expansion: + "one two + three + four" + == + "one two + three + four" + +TestMain.cpp:481: +PASSED: + CHECK( Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one two\nthree\nfour" ) +with expansion: + "one two + three + four" + == + "one two + three + four" + +------------------------------------------------------------------------------- +Long strings can be wrapped + With newlines + Wrapped twice +............................................................................... + +TestMain.cpp:484: +PASSED: + CHECK( Catch::LineWrapper( 6 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ) +with expansion: + "one + two + three + four" + == + "one + two + three + four" + ------------------------------------------------------------------------------- ./succeeding/Tricky/std::pair ............................................................................... @@ -4704,11 +4839,11 @@ with message: no assertions =============================================================================== -106 test cases - 47 failed (666 assertions - 104 failed) +106 test cases - 47 failed (676 assertions - 104 failed) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -CatchSelfTest is a CATCH v0.9 b27 (integration) host application. +CatchSelfTest is a CATCH v0.9 b28 (integration) host application. Run with -? for options ------------------------------------------------------------------------------- @@ -4999,7 +5134,7 @@ with expansion: 13 test cases - 3 failed (40 assertions - 4 failed) - + @@ -10238,130 +10373,140 @@ TestMain.cpp" line="423"> -
-TestMain.cpp" line="433"> - - Catch::wrapLongStrings( testString, 80, 0 ) == testString - - - "one two three four" +
+
+TestMain.cpp" line="435"> + + Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString + + + "one two three four" == "one two three four" - - -TestMain.cpp" line="434"> - - Catch::wrapLongStrings( testString, 18, 0 ) == testString - - - "one two three four" + + +TestMain.cpp" line="436"> + + Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString + + + "one two three four" == "one two three four" - - + + + +
-
-TestMain.cpp" line="437"> - - Catch::wrapLongStrings( testString, 17, 0 ) == "one two three\nfour" - - - "one two three -four" -== -"one two three -four" - - -TestMain.cpp" line="438"> - - Catch::wrapLongStrings( testString, 16, 0 ) == "one two three\nfour" - - - "one two three -four" -== -"one two three -four" - - +
+
TestMain.cpp" line="439"> - - Catch::wrapLongStrings( testString, 15, 0 ) == "one two three\nfour" - - - "one two three + + Catch::LineWrapper( 17 ).wrap( testString ).toString() == "one two three\nfour" + + + "one two three four" == "one two three four" - - + + TestMain.cpp" line="440"> - - Catch::wrapLongStrings( testString, 14, 0 ) == "one two three\nfour" - - - "one two three + + Catch::LineWrapper( 16 ).wrap( testString ).toString() == "one two three\nfour" + + + "one two three four" == "one two three four" - - + + TestMain.cpp" line="441"> - - Catch::wrapLongStrings( testString, 13, 0 ) == "one two\nthree four" - - - "one two + + Catch::LineWrapper( 15 ).wrap( testString ).toString() == "one two three\nfour" + + + "one two three +four" +== +"one two three +four" + + +TestMain.cpp" line="442"> + + Catch::LineWrapper( 14 ).wrap( testString ).toString() == "one two three\nfour" + + + "one two three +four" +== +"one two three +four" + + +TestMain.cpp" line="443"> + + Catch::LineWrapper( 13 ).wrap( testString ).toString() == "one two\nthree four" + + + "one two three four" == "one two three four" - - + + + +
-
-TestMain.cpp" line="444"> - - Catch::wrapLongStrings( testString, 9, 0 ) == "one two\nthree\nfour" - - - "one two +
+
+TestMain.cpp" line="446"> + + Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" + + + "one two three four" == "one two three four" - - -TestMain.cpp" line="445"> - - Catch::wrapLongStrings( testString, 8, 0 ) == "one two\nthree\nfour" - - - "one two + + +TestMain.cpp" line="447"> + + Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" + + + "one two three four" == "one two three four" - - + + + +
-
-TestMain.cpp" line="448"> - - Catch::wrapLongStrings( testString, 7, 0 ) == "one\ntwo\nthree\nfour" - - - "one +
+
+TestMain.cpp" line="450"> + + Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" + + + "one two three four" @@ -10370,14 +10515,14 @@ four" two three four" - - -TestMain.cpp" line="449"> - - Catch::wrapLongStrings( testString, 5, 0 ) == "one\ntwo\nthree\nfour" - - - "one + + +TestMain.cpp" line="451"> + + Catch::LineWrapper( 5 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" + + + "one two three four" @@ -10386,55 +10531,58 @@ four" two three four" - - + + + +
-
-TestMain.cpp" line="452"> - - Catch::wrapLongStrings( "abcdef", 4, 0 ) == "abc-\ndef" - - - "abc- -def" -== -"abc- -def" - - -TestMain.cpp" line="453"> - - Catch::wrapLongStrings( "abcdefg", 4, 0 ) == "abc-\ndefg" - - - "abc- -defg" -== -"abc- -defg" - - +
+
TestMain.cpp" line="454"> - - Catch::wrapLongStrings( "abcdefgh", 4, 0 ) == "abc-\ndef-\ngh" - - - "abc- + + Catch::LineWrapper( 4 ).wrap( "abcdef" ).toString() == "abc-\ndef" + + + "abc- +def" +== +"abc- +def" + + +TestMain.cpp" line="455"> + + Catch::LineWrapper( 4 ).wrap( "abcdefg" ).toString() == "abc-\ndefg" + + + "abc- +defg" +== +"abc- +defg" + + +TestMain.cpp" line="456"> + + Catch::LineWrapper( 4 ).wrap("abcdefgh" ).toString() == "abc-\ndef-\ngh" + + + "abc- def- gh" == "abc- def- gh" - - -TestMain.cpp" line="456"> - - Catch::wrapLongStrings( testString, 4, 0 ) == "one\ntwo\nthr-\nee\nfour" - - - "one + + +TestMain.cpp" line="458"> + + Catch::LineWrapper( 4 ).wrap( testString ).toString() == "one\ntwo\nthr-\nee\nfour" + + + "one two thr- ee @@ -10445,14 +10593,14 @@ two thr- ee four" - - -TestMain.cpp" line="457"> - - Catch::wrapLongStrings( testString, 3, 0 ) == "one\ntwo\nth-\nree\nfo-\nur" - - - "one + + +TestMain.cpp" line="459"> + + Catch::LineWrapper( 3 ).wrap( testString ).toString() == "one\ntwo\nth-\nree\nfo-\nur" + + + "one two th- ree @@ -10465,10 +10613,165 @@ th- ree fo- ur" - - + + + +
+
+ +
+
+
+TestMain.cpp" line="469"> + + Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString + + + "one two +three four" +== +"one two +three four" + + +TestMain.cpp" line="470"> + + Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString + + + "one two +three four" +== +"one two +three four" + + +TestMain.cpp" line="471"> + + Catch::LineWrapper( 10 ).wrap( testString ).toString() == testString + + + "one two +three four" +== +"one two +three four" + + + +
+ +
+
+
+TestMain.cpp" line="474"> + + Catch::LineWrapper( 10 ).wrap( "abcdef\n" ).toString() == "abcdef\n" + + + "abcdef +" +== +"abcdef +" + + +TestMain.cpp" line="475"> + + Catch::LineWrapper( 6 ).wrap( "abcdef" ).toString() == "abcdef" + + + "abcdef" == "abcdef" + + +TestMain.cpp" line="476"> + + Catch::LineWrapper( 6 ).wrap( "abcdef\n" ).toString() == "abcdef\n" + + + "abcdef +" +== +"abcdef +" + + + +
+ +
+
+
+TestMain.cpp" line="479"> + + Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" + + + "one two +three +four" +== +"one two +three +four" + + +TestMain.cpp" line="480"> + + Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" + + + "one two +three +four" +== +"one two +three +four" + + +TestMain.cpp" line="481"> + + Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one two\nthree\nfour" + + + "one two +three +four" +== +"one two +three +four" + + + +
+ +
+
+
+TestMain.cpp" line="484"> + + Catch::LineWrapper( 6 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" + + + "one +two +three +four" +== +"one +two +three +four" + + + +
+ +
@@ -10802,9 +11105,9 @@ BDDTests.cpp" line="23">
- + - + [Started testing: CatchSelfTest] [Started group: '~dummy'] @@ -12108,43 +12411,47 @@ TestMain.cpp:423: oneTag.matchesTags( "~[hide]" ) == false succeeded for: false [Finished: 'selftest/tags' All tests passed (30 assertions in 1 test case)] [Running: Long strings can be wrapped] +[Started section: 'plain string'] [Started section: 'No wrapping'] -TestMain.cpp:433: Catch::wrapLongStrings( testString, 80, 0 ) == testString succeeded for: +TestMain.cpp:435: Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString succeeded for: "one two three four" == "one two three four" -TestMain.cpp:434: Catch::wrapLongStrings( testString, 18, 0 ) == testString succeeded for: +TestMain.cpp:436: Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString succeeded for: "one two three four" == "one two three four" [End of section: 'No wrapping' All 2 assertions passed] +[End of section: 'plain string' All 2 assertions passed] + +[Started section: 'plain string'] [Started section: 'Wrapped once'] -TestMain.cpp:437: Catch::wrapLongStrings( testString, 17, 0 ) == "one two three\nfour" succeeded for: +TestMain.cpp:439: Catch::LineWrapper( 17 ).wrap( testString ).toString() == "one two three\nfour" succeeded for: "one two three four" == "one two three four" -TestMain.cpp:438: Catch::wrapLongStrings( testString, 16, 0 ) == "one two three\nfour" succeeded for: +TestMain.cpp:440: Catch::LineWrapper( 16 ).wrap( testString ).toString() == "one two three\nfour" succeeded for: "one two three four" == "one two three four" -TestMain.cpp:439: Catch::wrapLongStrings( testString, 15, 0 ) == "one two three\nfour" succeeded for: +TestMain.cpp:441: Catch::LineWrapper( 15 ).wrap( testString ).toString() == "one two three\nfour" succeeded for: "one two three four" == "one two three four" -TestMain.cpp:440: Catch::wrapLongStrings( testString, 14, 0 ) == "one two three\nfour" succeeded for: +TestMain.cpp:442: Catch::LineWrapper( 14 ).wrap( testString ).toString() == "one two three\nfour" succeeded for: "one two three four" == "one two three four" -TestMain.cpp:441: Catch::wrapLongStrings( testString, 13, 0 ) == "one two\nthree four" succeeded for: +TestMain.cpp:443: Catch::LineWrapper( 13 ).wrap( testString ).toString() == "one two\nthree four" succeeded for: "one two three four" == @@ -12152,8 +12459,11 @@ three four" three four" [End of section: 'Wrapped once' All 5 assertions passed] +[End of section: 'plain string' All 5 assertions passed] + +[Started section: 'plain string'] [Started section: 'Wrapped twice'] -TestMain.cpp:444: Catch::wrapLongStrings( testString, 9, 0 ) == "one two\nthree\nfour" succeeded for: +TestMain.cpp:446: Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" succeeded for: "one two three four" @@ -12161,7 +12471,7 @@ four" "one two three four" -TestMain.cpp:445: Catch::wrapLongStrings( testString, 8, 0 ) == "one two\nthree\nfour" succeeded for: +TestMain.cpp:447: Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" succeeded for: "one two three four" @@ -12171,8 +12481,11 @@ three four" [End of section: 'Wrapped twice' All 2 assertions passed] +[End of section: 'plain string' All 2 assertions passed] + +[Started section: 'plain string'] [Started section: 'Wrapped three times'] -TestMain.cpp:448: Catch::wrapLongStrings( testString, 7, 0 ) == "one\ntwo\nthree\nfour" succeeded for: +TestMain.cpp:450: Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" succeeded for: "one two three @@ -12182,7 +12495,7 @@ four" two three four" -TestMain.cpp:449: Catch::wrapLongStrings( testString, 5, 0 ) == "one\ntwo\nthree\nfour" succeeded for: +TestMain.cpp:451: Catch::LineWrapper( 5 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" succeeded for: "one two three @@ -12194,25 +12507,28 @@ three four" [End of section: 'Wrapped three times' All 2 assertions passed] +[End of section: 'plain string' All 2 assertions passed] + +[Started section: 'plain string'] [Started section: 'Short wrap'] -TestMain.cpp:452: Catch::wrapLongStrings( "abcdef", 4, 0 ) == "abc-\ndef" succeeded for: "abc- +TestMain.cpp:454: Catch::LineWrapper( 4 ).wrap( "abcdef" ).toString() == "abc-\ndef" succeeded for: "abc- def" == "abc- def" -TestMain.cpp:453: Catch::wrapLongStrings( "abcdefg", 4, 0 ) == "abc-\ndefg" succeeded for: "abc- +TestMain.cpp:455: Catch::LineWrapper( 4 ).wrap( "abcdefg" ).toString() == "abc-\ndefg" succeeded for: "abc- defg" == "abc- defg" -TestMain.cpp:454: Catch::wrapLongStrings( "abcdefgh", 4, 0 ) == "abc-\ndef-\ngh" succeeded for: "abc- +TestMain.cpp:456: Catch::LineWrapper( 4 ).wrap("abcdefgh" ).toString() == "abc-\ndef-\ngh" succeeded for: "abc- def- gh" == "abc- def- gh" -TestMain.cpp:456: Catch::wrapLongStrings( testString, 4, 0 ) == "one\ntwo\nthr-\nee\nfour" succeeded for: +TestMain.cpp:458: Catch::LineWrapper( 4 ).wrap( testString ).toString() == "one\ntwo\nthr-\nee\nfour" succeeded for: "one two thr- @@ -12224,7 +12540,7 @@ two thr- ee four" -TestMain.cpp:457: Catch::wrapLongStrings( testString, 3, 0 ) == "one\ntwo\nth-\nree\nfo-\nur" succeeded for: +TestMain.cpp:459: Catch::LineWrapper( 3 ).wrap( testString ).toString() == "one\ntwo\nth-\nree\nfo-\nur" succeeded for: "one two th- @@ -12240,7 +12556,96 @@ fo- ur" [End of section: 'Short wrap' All 5 assertions passed] -[Finished: 'Long strings can be wrapped' All tests passed (16 assertions in 1 test case)] +[End of section: 'plain string' All 5 assertions passed] + +[Started section: 'With newlines'] +[Started section: 'No wrapping'] +TestMain.cpp:469: Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString succeeded for: + "one two +three four" +== +"one two +three four" +TestMain.cpp:470: Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString succeeded for: + "one two +three four" +== +"one two +three four" +TestMain.cpp:471: Catch::LineWrapper( 10 ).wrap( testString ).toString() == testString succeeded for: + "one two +three four" +== +"one two +three four" +[End of section: 'No wrapping' All 3 assertions passed] + +[End of section: 'With newlines' All 3 assertions passed] + +[Started section: 'With newlines'] +[Started section: 'Trailing newline'] +TestMain.cpp:474: Catch::LineWrapper( 10 ).wrap( "abcdef\n" ).toString() == "abcdef\n" succeeded for: "abcdef +" +== +"abcdef +" +TestMain.cpp:475: Catch::LineWrapper( 6 ).wrap( "abcdef" ).toString() == "abcdef" succeeded for: "abcdef" == "abcdef" +TestMain.cpp:476: Catch::LineWrapper( 6 ).wrap( "abcdef\n" ).toString() == "abcdef\n" succeeded for: "abcdef +" +== +"abcdef +" +[End of section: 'Trailing newline' All 3 assertions passed] + +[End of section: 'With newlines' All 3 assertions passed] + +[Started section: 'With newlines'] +[Started section: 'Wrapped once'] +TestMain.cpp:479: Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" succeeded for: + "one two +three +four" +== +"one two +three +four" +TestMain.cpp:480: Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" succeeded for: + "one two +three +four" +== +"one two +three +four" +TestMain.cpp:481: Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one two\nthree\nfour" succeeded for: + "one two +three +four" +== +"one two +three +four" +[End of section: 'Wrapped once' All 3 assertions passed] + +[End of section: 'With newlines' All 3 assertions passed] + +[Started section: 'With newlines'] +[Started section: 'Wrapped twice'] +TestMain.cpp:484: Catch::LineWrapper( 6 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" succeeded for: + "one +two +three +four" +== +"one +two +three +four" +[End of section: 'Wrapped twice' 1 assertion passed] + +[End of section: 'With newlines' 1 assertion passed] + +[Finished: 'Long strings can be wrapped' All tests passed (26 assertions in 1 test case)] [Running: ./succeeding/Tricky/std::pair] TrickyTests.cpp:37: (std::pair( 1, 2 )) == aNicePair succeeded for: std::pair( 1, 2 ) == std::pair( 1, 2 ) @@ -12377,10 +12782,10 @@ VariadicMacrosTests.cpp:26: succeeded [End of section: 'Section with one argument' 1 assertion passed] [Finished: 'Variadic macros' All tests passed (1 assertion in 1 test case)] -[End of group: '~dummy'. 47 of 106 test cases failed (104 of 666 assertions failed)] +[End of group: '~dummy'. 47 of 106 test cases failed (104 of 676 assertions failed)] -[Testing completed. 47 of 106 test cases failed (104 of 666 assertions failed)] +[Testing completed. 47 of 106 test cases failed (104 of 676 assertions failed)] [Started testing: CatchSelfTest] [Started group: '~dummy'] diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp index 45e002a8..9f1e3d4d 100644 --- a/projects/SelfTest/TestMain.cpp +++ b/projects/SelfTest/TestMain.cpp @@ -426,34 +426,63 @@ TEST_CASE( "selftest/tags", "" ) { } 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" ); + SECTION( "plain string", "" ) { + // guide: 123456789012345678 + std::string testString = "one two three four"; + + SECTION( "No wrapping", "" ) { + CHECK( Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString ); + CHECK( Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString ); + } + SECTION( "Wrapped once", "" ) { + CHECK( Catch::LineWrapper( 17 ).wrap( testString ).toString() == "one two three\nfour" ); + CHECK( Catch::LineWrapper( 16 ).wrap( testString ).toString() == "one two three\nfour" ); + CHECK( Catch::LineWrapper( 15 ).wrap( testString ).toString() == "one two three\nfour" ); + CHECK( Catch::LineWrapper( 14 ).wrap( testString ).toString() == "one two three\nfour" ); + CHECK( Catch::LineWrapper( 13 ).wrap( testString ).toString() == "one two\nthree four" ); + } + SECTION( "Wrapped twice", "" ) { + CHECK( Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" ); + CHECK( Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" ); + } + SECTION( "Wrapped three times", "" ) { + CHECK( Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ); + CHECK( Catch::LineWrapper( 5 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ); + } + SECTION( "Short wrap", "" ) { + CHECK( Catch::LineWrapper( 4 ).wrap( "abcdef" ).toString() == "abc-\ndef" ); + CHECK( Catch::LineWrapper( 4 ).wrap( "abcdefg" ).toString() == "abc-\ndefg" ); + CHECK( Catch::LineWrapper( 4 ).wrap("abcdefgh" ).toString() == "abc-\ndef-\ngh" ); + + CHECK( Catch::LineWrapper( 4 ).wrap( testString ).toString() == "one\ntwo\nthr-\nee\nfour" ); + CHECK( Catch::LineWrapper( 3 ).wrap( testString ).toString() == "one\ntwo\nth-\nree\nfo-\nur" ); + } } + + SECTION( "With newlines", "" ) { + + // guide: 1234567890123456789 + std::string testString = "one two\nthree four"; + + SECTION( "No wrapping" , "" ) { + CHECK( Catch::LineWrapper( 80 ).wrap( testString ).toString() == testString ); + CHECK( Catch::LineWrapper( 18 ).wrap( testString ).toString() == testString ); + CHECK( Catch::LineWrapper( 10 ).wrap( testString ).toString() == testString ); + } + SECTION( "Trailing newline" , "" ) { + CHECK( Catch::LineWrapper( 10 ).wrap( "abcdef\n" ).toString() == "abcdef\n" ); + CHECK( Catch::LineWrapper( 6 ).wrap( "abcdef" ).toString() == "abcdef" ); + CHECK( Catch::LineWrapper( 6 ).wrap( "abcdef\n" ).toString() == "abcdef\n" ); + } + SECTION( "Wrapped once", "" ) { + CHECK( Catch::LineWrapper( 9 ).wrap( testString ).toString() == "one two\nthree\nfour" ); + CHECK( Catch::LineWrapper( 8 ).wrap( testString ).toString() == "one two\nthree\nfour" ); + CHECK( Catch::LineWrapper( 7 ).wrap( testString ).toString() == "one two\nthree\nfour" ); + } + SECTION( "Wrapped twice", "" ) { + CHECK( Catch::LineWrapper( 6 ).wrap( testString ).toString() == "one\ntwo\nthree\nfour" ); + } + } + }