2012-05-08 14:29:51 -04:00
/*
2012-08-08 03:58:28 -04:00
* Created by Phil on 8 / 8 / 2012.
2012-05-08 14:29:51 -04:00
* Copyright 2012 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_RESULTINFO_BUILDER_HPP_INCLUDED
# define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
2012-08-08 03:58:28 -04:00
# include "catch_resultinfo_builder.h"
2012-05-08 14:29:51 -04:00
2012-05-15 02:42:26 -04:00
namespace Catch {
2012-05-08 14:29:51 -04:00
2012-10-04 03:09:09 -04:00
ResultInfoBuilder : : ResultInfoBuilder ( ) { }
ResultInfoBuilder & ResultInfoBuilder : : setResultType ( ResultWas : : OfType result ) {
2012-05-08 14:29:51 -04:00
// Flip bool results if isNot is set
if ( m_isNot & & result = = ResultWas : : Ok )
2012-10-09 06:48:55 -04:00
m_data . resultType = ResultWas : : ExpressionFailed ;
2012-05-08 14:29:51 -04:00
else if ( m_isNot & & result = = ResultWas : : ExpressionFailed )
2012-10-09 06:48:55 -04:00
m_data . resultType = ResultWas : : Ok ;
2012-05-08 14:29:51 -04:00
else
2012-10-09 06:48:55 -04:00
m_data . resultType = result ;
2012-10-05 13:35:01 -04:00
return * this ;
}
ResultInfoBuilder & ResultInfoBuilder : : setCapturedExpression ( const std : : string & capturedExpression ) {
m_data . capturedExpression = capturedExpression ;
return * this ;
}
ResultInfoBuilder & ResultInfoBuilder : : setIsFalse ( bool isFalse ) {
m_isNot = isFalse ;
2012-10-04 03:09:09 -04:00
return * this ;
2012-05-08 14:29:51 -04:00
}
2012-10-04 03:09:09 -04:00
ResultInfoBuilder & ResultInfoBuilder : : setMessage ( const std : : string & message ) {
2012-10-05 13:35:01 -04:00
m_data . message = message ;
2012-10-04 03:09:09 -04:00
return * this ;
2012-05-08 14:29:51 -04:00
}
2012-08-08 03:58:28 -04:00
2012-10-04 03:09:09 -04:00
ResultInfoBuilder & ResultInfoBuilder : : setLineInfo ( const SourceLineInfo & lineInfo ) {
2012-10-05 13:35:01 -04:00
m_data . lineInfo = lineInfo ;
return * this ;
}
ResultInfoBuilder & ResultInfoBuilder : : setMacroName ( const std : : string & macroName ) {
m_data . macroName = macroName ;
2012-10-04 03:09:09 -04:00
return * this ;
2012-05-08 14:29:51 -04:00
}
2012-08-08 03:58:28 -04:00
2012-10-04 03:09:09 -04:00
ResultInfoBuilder & ResultInfoBuilder : : setLhs ( const std : : string & lhs ) {
2012-05-08 14:29:51 -04:00
m_lhs = lhs ;
2012-10-04 03:09:09 -04:00
return * this ;
2012-05-08 14:29:51 -04:00
}
2012-08-08 03:58:28 -04:00
2012-10-04 03:09:09 -04:00
ResultInfoBuilder & ResultInfoBuilder : : setRhs ( const std : : string & rhs ) {
2012-05-08 14:29:51 -04:00
m_rhs = rhs ;
2012-10-04 03:09:09 -04:00
return * this ;
2012-05-08 14:29:51 -04:00
}
2012-10-04 03:09:09 -04:00
ResultInfoBuilder & ResultInfoBuilder : : setOp ( const std : : string & op ) {
2012-05-08 14:29:51 -04:00
m_op = op ;
2012-10-04 03:09:09 -04:00
return * this ;
}
2012-10-09 06:48:55 -04:00
ResultInfo ResultInfoBuilder : : build ( ) const
2012-10-05 13:35:01 -04:00
{
ResultData data = m_data ;
data . reconstructedExpression = reconstructExpression ( ) ;
2012-10-09 06:48:55 -04:00
if ( m_isNot ) {
if ( m_op = = " " ) {
data . capturedExpression = " ! " + data . capturedExpression ;
data . reconstructedExpression = " ! " + data . reconstructedExpression ;
}
else {
data . capturedExpression = " !( " + data . capturedExpression + " ) " ;
data . reconstructedExpression = " !( " + data . reconstructedExpression + " ) " ;
}
}
return ResultInfo ( data ) ;
2012-05-08 14:29:51 -04:00
}
2012-10-05 13:35:01 -04:00
std : : string ResultInfoBuilder : : reconstructExpression ( ) const {
2012-10-09 06:48:55 -04:00
if ( m_op = = " " )
return m_lhs . empty ( ) ? m_data . capturedExpression : m_op + m_lhs ;
2012-10-05 13:35:01 -04:00
else if ( m_op = = " matches " )
return m_lhs + " " + m_rhs ;
2012-10-09 06:48:55 -04:00
else if ( m_op ! = " ! " ) {
2012-10-05 13:35:01 -04:00
if ( m_lhs . size ( ) + m_rhs . size ( ) < 30 )
return m_lhs + " " + m_op + " " + m_rhs ;
else if ( m_lhs . size ( ) < 70 & & m_rhs . size ( ) < 70 )
return " \n \t " + m_lhs + " \n \t " + m_op + " \n \t " + m_rhs ;
else
return " \n " + m_lhs + " \n " + m_op + " \n " + m_rhs + " \n \n " ;
}
else
2012-10-09 06:48:55 -04:00
return " {can't expand - use " + m_data . macroName + " _FALSE( " + m_data . capturedExpression . substr ( 1 ) + " ) instead of " + m_data . macroName + " ( " + m_data . capturedExpression + " ) for better diagnostics} " ;
2012-10-05 13:35:01 -04:00
}
2012-05-08 14:29:51 -04:00
} // end namespace Catch
# endif // TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED