/* * Created by Phil on 11/5/2012. * 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_EXPRESSION_HPP_INCLUDED #define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED #include "catch_assertionresult_builder.h" #include "catch_evaluate.hpp" namespace Catch { template class Expression { void operator = ( const Expression& ); public: Expression( AssertionResultBuilder& result, T lhs ) : m_result( result.setLhs( Catch::toString( lhs ) ) ), m_lhs( lhs ) {} template AssertionResultBuilder& operator == ( const RhsT& rhs ) { return captureExpression( rhs ); } template AssertionResultBuilder& operator != ( const RhsT& rhs ) { return captureExpression( rhs ); } template AssertionResultBuilder& operator < ( const RhsT& rhs ) { return captureExpression( rhs ); } template AssertionResultBuilder& operator > ( const RhsT& rhs ) { return captureExpression( rhs ); } template AssertionResultBuilder& operator <= ( const RhsT& rhs ) { return captureExpression( rhs ); } template AssertionResultBuilder& operator >= ( const RhsT& rhs ) { return captureExpression( rhs ); } AssertionResultBuilder& operator == ( bool rhs ) { return captureExpression( rhs ); } AssertionResultBuilder& operator != ( bool rhs ) { return captureExpression( rhs ); } operator AssertionResultBuilder& () { return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed ); } template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& ); private: template AssertionResultBuilder& captureExpression( const RhsT& rhs ) { return m_result .setResultType( Internal::compare( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed ) .setRhs( Catch::toString( rhs ) ) .setOp( Internal::OperatorTraits::getName() ); } private: AssertionResultBuilder& m_result; T m_lhs; }; } // end namespace Catch #endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED