diff options
| author | Phil Nash | 2013-04-20 19:36:40 +0100 |
|---|---|---|
| committer | Phil Nash | 2013-04-20 19:36:40 +0100 |
| commit | b3acf45d7052efc97409db4ba2f930833cd15596 (patch) | |
| tree | 3c5a0489b4b2e7cd6bbad68ec19d3d20d41a0553 /include/internal | |
| parent | 97d99852a85f37dbc19fac9e6979c63bf5db0bc2 (diff) | |
| download | catch3-b3acf45d7052efc97409db4ba2f930833cd15596.tar.gz | |
Fully committed to new Text class.
- moved impl into .hpp
- replaced last few uses of LineWrapper with Text
- removed LineWrapper
Diffstat (limited to 'include/internal')
| -rw-r--r-- | include/internal/catch_impl.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.h | 58 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.hpp | 117 | ||||
| -rw-r--r-- | include/internal/catch_list.hpp | 16 | ||||
| -rw-r--r-- | include/internal/catch_test_case_info.h | 1 | ||||
| -rw-r--r-- | include/internal/catch_text.h | 76 | ||||
| -rw-r--r-- | include/internal/catch_text.hpp | 92 |
7 files changed, 108 insertions, 254 deletions
diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp index f3f214b2..ff95675b 100644 --- a/include/internal/catch_impl.hpp +++ b/include/internal/catch_impl.hpp @@ -27,7 +27,7 @@ #include "catch_test_case_info.hpp" #include "catch_tags.hpp" #include "catch_version.hpp" -#include "catch_line_wrap.hpp" +#include "catch_text.hpp" #include "catch_message.hpp" #include "catch_legacy_reporter_adapter.hpp" diff --git a/include/internal/catch_line_wrap.h b/include/internal/catch_line_wrap.h deleted file mode 100644 index cfd31df8..00000000 --- a/include/internal/catch_line_wrap.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Created by Phil on 11/1/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED -#define TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED - -#include <string> -#include <vector> - -namespace Catch { - - class LineWrapper { - public: - LineWrapper(); - - LineWrapper& setIndent( std::size_t _indent ); - LineWrapper& setInitialIndent( std::size_t _initalIndent ); - LineWrapper& setRight( std::size_t _right ); - LineWrapper& setTabChar( char _tabChar ); - - LineWrapper& wrap( std::string const& _str ); - - std::string toString() const; - - typedef std::vector<std::string>::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - - friend std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper ); - - private: - void wrapInternal( std::string const& _str ); - void addLine( const std::string& _line ); - bool isWrapPoint( char c ); - std::size_t getCurrentIndent() const; - - std::size_t right; - std::size_t nextTab; - std::size_t tab; - std::size_t indent; - std::size_t initialIndent; - std::string wrappableChars; - char tabChar; - int recursionCount; - std::vector<std::string> lines; - }; - -} // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED diff --git a/include/internal/catch_line_wrap.hpp b/include/internal/catch_line_wrap.hpp deleted file mode 100644 index aa278f5d..00000000 --- a/include/internal/catch_line_wrap.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Created by Phil on 11/1/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED - -#include "catch_line_wrap.h" - -namespace Catch { - - LineWrapper::LineWrapper() - : right( CATCH_CONFIG_CONSOLE_WIDTH-1 ), - nextTab( 0 ), - tab( 0 ), - indent( 0 ), - initialIndent( (std::size_t)-1 ), // use indent by default - wrappableChars( " [({.,/|\\" ), - tabChar( '\t' ), - recursionCount( 0 ) - {} - - LineWrapper& LineWrapper::setIndent( std::size_t _indent ) { - indent = _indent; - return *this; - } - LineWrapper& LineWrapper::setInitialIndent( std::size_t _initialIndent ) { - initialIndent = _initialIndent; - 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; - } - LineWrapper& LineWrapper::setTabChar( char _tabChar ) { - tabChar = _tabChar; - return *this; - } - bool LineWrapper::isWrapPoint( char c ) { - return wrappableChars.find( c ) != std::string::npos; - } - void LineWrapper::wrapInternal( std::string const& _str ) { - assert( ++recursionCount < 1000 ); - - std::size_t width = right - getCurrentIndent(); - 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] == ' ' ); - } - else if( isWrapPoint( _str[wrapPoint] ) ) { - addLine( _str.substr( 0, wrapPoint ) ); - } - else { - addLine( _str.substr( 0, --wrapPoint ) + '-' ); - } - return wrapInternal( _str.substr( wrapPoint ) ); - } - if( _str[pos] == tabChar ) { - nextTab = pos; - std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 ); - return wrapInternal( withoutTab ); - } - else if( pos > 0 && isWrapPoint( _str[pos] ) ) { - wrapPoint = pos; - } - } - addLine( _str ); - } - - std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper ) { - for( LineWrapper::const_iterator it = _lineWrapper.begin(), itEnd = _lineWrapper.end(); - it != itEnd; ++it ) { - if( it != _lineWrapper.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - std::string LineWrapper::toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - void LineWrapper::addLine( const std::string& _line ) { - lines.push_back( std::string( tab + getCurrentIndent(), ' ' ) + _line ); - if( nextTab > 0 ) - tab = nextTab; - } - - std::size_t LineWrapper::getCurrentIndent() const - { - return (initialIndent != (std::size_t)-1 && lines.empty() ) - ? initialIndent - : indent; - } - -} // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp index c0a44081..b1504f4d 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -9,7 +9,7 @@ #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED #include "catch_commandline.hpp" -#include "catch_line_wrap.h" +#include "catch_text.h" #include "catch_console_colour.hpp" #include <limits> @@ -57,11 +57,11 @@ namespace Catch { if( matchesFilters( config.filters, *it ) ) { matchedTests++; // !TBD: consider listAs() - LineWrapper nameWrapper; - nameWrapper.setRight( maxNameLen ).setIndent( 2 ).wrap( it->getTestCaseInfo().name ); + Text nameWrapper( it->getTestCaseInfo().name, + TextAttributes().setWidth( maxNameLen ).setIndent(2) ); - LineWrapper tagsWrapper; - tagsWrapper.setRight( maxTagLen ).wrap( it->getTestCaseInfo().tagsAsString ); + Text tagsWrapper( it->getTestCaseInfo().tagsAsString, + TextAttributes().setWidth( maxTagLen ) ); for( std::size_t i = 0; i < std::max( nameWrapper.size(), tagsWrapper.size() ); ++i ) { Colour::Code colour = Colour::None; @@ -135,9 +135,9 @@ namespace Catch { for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), countItEnd = tagCounts.end(); countIt != countItEnd; ++countIt ) { - LineWrapper wrapper; - wrapper.setIndent(2).setRight( maxTagLen ).wrap( "[" + countIt->first + "]" ); - + Text wrapper( "[" + countIt->first + "]", TextAttributes() + .setIndent(2) + .setWidth( maxTagLen ) ); std::cout << wrapper; std::size_t dots = 2; if( maxTagLen > wrapper.last().size() ) diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h index fde9748a..ba804b19 100644 --- a/include/internal/catch_test_case_info.h +++ b/include/internal/catch_test_case_info.h @@ -9,6 +9,7 @@ #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED #include "catch_common.h" +#include "catch_ptr.hpp" #include <string> #include <set> diff --git a/include/internal/catch_text.h b/include/internal/catch_text.h index 97288a72..8584da31 100644 --- a/include/internal/catch_text.h +++ b/include/internal/catch_text.h @@ -8,6 +8,8 @@ #ifndef TWOBLUECUBES_CATCH_TEXT_H_INCLUDED #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED +#include "catch_config.hpp" + #include <string> #include <vector> @@ -34,62 +36,8 @@ namespace Catch { class Text { public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - assert( lines.size() < 1000 ); - 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 ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos ) { - 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; - } - } - } - 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 ); - } + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ); + void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ); typedef std::vector<std::string>::const_iterator const_iterator; @@ -98,21 +46,9 @@ namespace Catch { std::string const& last() const { return lines.back(); } std::size_t size() const { return lines.size(); } std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } + std::string toString() const; - friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - std::string toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } + friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ); private: std::string str; diff --git a/include/internal/catch_text.hpp b/include/internal/catch_text.hpp new file mode 100644 index 00000000..bc502e8d --- /dev/null +++ b/include/internal/catch_text.hpp @@ -0,0 +1,92 @@ +/* + * Created by Phil on 20/4/2013. + * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED + +#include <string> +#include <vector> + +namespace Catch { + + Text::Text( std::string const& _str, TextAttributes const& _attr ) + : attr( _attr ) + { + std::string wrappableChars = " [({.,/|\\-"; + std::size_t indent = _attr.initialIndent != std::string::npos + ? _attr.initialIndent + : _attr.indent; + std::string remainder = _str; + + while( !remainder.empty() ) { + assert( lines.size() < 1000 ); + 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 ); + } + else if( remainder[width] == '\n' ) { + spliceLine( indent, remainder, width ); + if( width <= 1 || remainder.size() != 1 ) + remainder = remainder.substr( 1 ); + indent = _attr.indent; + } + else { + pos = remainder.find_last_of( wrappableChars, width ); + if( pos != std::string::npos && pos > 0 ) { + 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; + } + } + } + + void Text::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 ); + } + + std::string Text::toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + + std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_TEXT_HPP_INCLUDED |