Expression has its own result builder - not passed in from expression builder

This commit is contained in:
Phil Nash 2012-10-19 08:01:05 +01:00
parent e3b111a39a
commit f2d5f1b3e4
2 changed files with 11 additions and 20 deletions

View File

@ -18,10 +18,9 @@ class Expression {
void operator = ( const Expression& );
public:
Expression( AssertionResultBuilder& result, T lhs )
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
m_lhs( lhs )
{}
Expression( T lhs ) : m_lhs( lhs ) {
m_result.setLhs( Catch::toString( lhs ) );
}
template<typename RhsT>
AssertionResultBuilder& operator == ( const RhsT& rhs ) {
@ -61,10 +60,12 @@ public:
return captureExpression<Internal::IsNotEqualTo>( rhs );
}
operator AssertionResultBuilder& () {
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
AssertionResultBuilder setIsFalse( bool isFalse ) {
return m_result
.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed )
.setIsFalse( isFalse );
}
template<typename RhsT>
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
@ -81,7 +82,7 @@ private:
}
private:
AssertionResultBuilder& m_result;
AssertionResultBuilder m_result;
T m_lhs;
};

View File

@ -16,24 +16,14 @@ namespace Catch {
class ExpressionBuilder {
public:
ExpressionBuilder( bool isFalse = false )
{
m_result.setIsFalse( isFalse );
}
template<typename T>
Expression<const T&> operator->* ( const T & operand ) {
Expression<const T&> expr( m_result, operand );
return expr;
return Expression<const T&>( operand );
}
Expression<bool> operator->* ( bool value ) {
Expression<bool> expr( m_result, value );
return expr;
return Expression<bool>( value );
}
private:
AssertionResultBuilder m_result;
};
} // end namespace Catch