2012-05-11 09:03:05 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2012-08-08 09:58:28 +02:00
|
|
|
#include "catch_resultinfo_builder.h"
|
2012-05-11 09:03:05 +02:00
|
|
|
#include "catch_evaluate.hpp"
|
|
|
|
|
2012-05-15 08:42:26 +02:00
|
|
|
namespace Catch {
|
2012-05-11 09:03:05 +02:00
|
|
|
|
|
|
|
template<typename T>
|
2012-05-15 08:42:26 +02:00
|
|
|
class Expression {
|
2012-05-11 09:03:05 +02:00
|
|
|
void operator = ( const Expression& );
|
|
|
|
|
|
|
|
public:
|
2012-05-11 09:16:12 +02:00
|
|
|
Expression( ResultInfoBuilder& result, T lhs )
|
2012-10-09 21:58:33 +02:00
|
|
|
: m_result( result.setLhs( Catch::toString( lhs ) ) ),
|
2012-05-11 09:03:05 +02:00
|
|
|
m_lhs( lhs )
|
2012-05-11 09:16:12 +02:00
|
|
|
{}
|
2012-05-11 09:03:05 +02:00
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
2012-10-05 19:35:01 +02:00
|
|
|
|
2012-05-11 09:03:05 +02:00
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsLessThan>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsGreaterThan>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator == ( bool rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 09:16:12 +02:00
|
|
|
ResultInfoBuilder& operator != ( bool rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-11 09:16:12 +02:00
|
|
|
operator ResultInfoBuilder& () {
|
2012-10-09 21:58:33 +02:00
|
|
|
return m_result.setResultType( m_lhs ? ResultWas::Ok : ResultWas::ExpressionFailed );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
|
2012-05-11 09:03:05 +02:00
|
|
|
|
|
|
|
template<typename RhsT>
|
2012-05-11 09:16:12 +02:00
|
|
|
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
2012-05-11 09:03:05 +02:00
|
|
|
|
2012-10-09 21:58:33 +02:00
|
|
|
private:
|
|
|
|
template<Internal::Operator Op, typename RhsT>
|
|
|
|
ResultInfoBuilder& captureExpression( const RhsT& rhs ) {
|
|
|
|
return m_result
|
|
|
|
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed )
|
|
|
|
.setRhs( Catch::toString( rhs ) )
|
|
|
|
.setOp( Internal::OperatorTraits<Op>::getName() );
|
|
|
|
}
|
|
|
|
|
2012-05-11 09:03:05 +02:00
|
|
|
private:
|
|
|
|
ResultInfoBuilder& m_result;
|
|
|
|
T m_lhs;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|