mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-03 21:49:32 +01:00 
			
		
		
		
	Fully committed to new Text class.
- moved impl into .hpp - replaced last few uses of LineWrapper with Text - removed LineWrapper
This commit is contained in:
		@@ -13,7 +13,6 @@
 | 
			
		||||
#include "internal/catch_runner_impl.hpp"
 | 
			
		||||
#include "internal/catch_test_spec.h"
 | 
			
		||||
#include "internal/catch_version.h"
 | 
			
		||||
#include "internal/catch_line_wrap.h"
 | 
			
		||||
#include "internal/catch_text.h"
 | 
			
		||||
 | 
			
		||||
#include <fstream>
 | 
			
		||||
@@ -162,7 +161,6 @@ namespace Catch {
 | 
			
		||||
                displayedSpecificOption = true;
 | 
			
		||||
                std::cout   << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
 | 
			
		||||
                            << opt.optionSummary() << "\n\n"
 | 
			
		||||
//                            << LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ) << "\n" << std::endl;
 | 
			
		||||
                            << Text( opt.optionDescription(), TextAttributes().setIndent( 2 ) ) << "\n" << std::endl;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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() )
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include "catch_common.h"
 | 
			
		||||
#include "catch_ptr.hpp"
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <set>
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										92
									
								
								include/internal/catch_text.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								include/internal/catch_text.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
@@ -203,7 +203,7 @@ namespace Catch {
 | 
			
		||||
                if( result.hasExpandedExpression() ) {
 | 
			
		||||
                    stream << "with expansion:\n";
 | 
			
		||||
                    Colour colourGuard( Colour::ReconstructedExpression );
 | 
			
		||||
                    stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ) << "\n";
 | 
			
		||||
                    stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            void printMessage() const {
 | 
			
		||||
@@ -212,7 +212,7 @@ namespace Catch {
 | 
			
		||||
                for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
 | 
			
		||||
                        it != itEnd;
 | 
			
		||||
                        ++it ) {                    
 | 
			
		||||
                    stream << LineWrapper().setIndent(2).wrap( it->message ) << "\n";
 | 
			
		||||
                    stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            void printSourceInfo() const {
 | 
			
		||||
@@ -313,10 +313,9 @@ namespace Catch {
 | 
			
		||||
                i+=2;
 | 
			
		||||
            else
 | 
			
		||||
                i = 0;
 | 
			
		||||
            stream << LineWrapper()
 | 
			
		||||
                        .setIndent( indent+i)
 | 
			
		||||
                        .setInitialIndent( indent )
 | 
			
		||||
                        .wrap( _string ) << "\n";
 | 
			
		||||
            stream << Text( _string, TextAttributes()
 | 
			
		||||
                                        .setIndent( indent+i)
 | 
			
		||||
                                        .setInitialIndent( indent ) ) << "\n";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        void printTotals( const Totals& totals ) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user