First cut of Evaluate refactoring to remove int specialisations, among other things

This commit is contained in:
Phil Nash
2017-02-06 15:15:43 +00:00
parent e991c006b7
commit 39753558eb
5 changed files with 77 additions and 150 deletions

View File

@@ -21,7 +21,25 @@ namespace Catch {
virtual bool isBinaryExpression() const {
return false;
}
virtual void reconstructExpression( std::string& dest ) const = 0;
virtual std::string reconstructExpression() const = 0;
std::string reconstructExpressionImpl( std::string const& lhs, std::string const& rhs, std::string const& op ) const {
std::string dest;
char delim = lhs.size() + rhs.size() < 40 &&
lhs.find('\n') == std::string::npos &&
rhs.find('\n') == std::string::npos ? ' ' : '\n';
dest.reserve( 7 + lhs.size() + rhs.size() );
// 2 for spaces around operator
// 2 for operator
// 2 for parentheses (conditionally added later)
// 1 for negation (conditionally added later)
dest = lhs;
dest += delim;
dest += op;
dest += delim;
dest += rhs;
return dest;
}
// Only simple binary comparisons can be decomposed.
// If more complex check is required then wrap sub-expressions in parentheses.
@@ -66,7 +84,7 @@ namespace Catch {
std::string const& reconstructExpression() const {
if( decomposedExpression != CATCH_NULL ) {
decomposedExpression->reconstructExpression( reconstructedExpression );
reconstructedExpression = decomposedExpression->reconstructExpression();
if( parenthesized ) {
reconstructedExpression.insert( 0, 1, '(' );
reconstructedExpression.append( 1, ')' );