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)
|
|
|
|
*/
|
2012-10-26 09:45:23 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|
2012-05-11 09:03:05 +02:00
|
|
|
|
2012-10-26 09:45:23 +02:00
|
|
|
#include "catch_expressionresult_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
|
|
|
|
2012-10-28 21:57:21 +01:00
|
|
|
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
2012-10-26 10:05:36 +02:00
|
|
|
|
|
|
|
// Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
|
|
|
|
// in an ExpressionResultBuilder object
|
2012-05-11 09:03:05 +02:00
|
|
|
template<typename T>
|
2012-10-24 23:09:01 +02:00
|
|
|
class ExpressionLhs {
|
|
|
|
void operator = ( const ExpressionLhs& );
|
2012-05-11 09:03:05 +02:00
|
|
|
|
|
|
|
public:
|
2012-11-06 20:13:25 +01:00
|
|
|
ExpressionLhs( const T& lhs ) : m_lhs( lhs ) {}
|
2012-10-24 22:59:47 +02:00
|
|
|
|
2012-05-11 09:03:05 +02:00
|
|
|
template<typename RhsT>
|
2012-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& 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-11-10 19:43:23 +01:00
|
|
|
ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition ) {
|
2012-10-28 21:57:21 +01:00
|
|
|
bool value = m_lhs ? true : false;
|
|
|
|
return m_result
|
|
|
|
.setLhs( Catch::toString( value ) )
|
|
|
|
.setResultType( value )
|
2012-11-10 19:43:23 +01:00
|
|
|
.endExpression( resultDisposition );
|
2012-05-11 09:03:05 +02:00
|
|
|
}
|
2012-10-19 09:01:05 +02:00
|
|
|
|
2012-10-26 09:45:23 +02:00
|
|
|
// Only simple binary expressions are allowed on the LHS.
|
|
|
|
// If more complex compositions are required then place the sub expression in parentheses
|
|
|
|
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
|
|
|
|
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
|
|
|
|
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( const RhsT& );
|
|
|
|
template<typename RhsT> 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>
|
2012-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder& captureExpression( const RhsT& rhs ) {
|
2012-10-09 21:58:33 +02:00
|
|
|
return m_result
|
2012-10-24 22:59:47 +02:00
|
|
|
.setResultType( Internal::compare<Op>( m_lhs, rhs ) )
|
2012-10-28 21:57:21 +01:00
|
|
|
.setLhs( Catch::toString( m_lhs ) )
|
2012-10-09 21:58:33 +02:00
|
|
|
.setRhs( Catch::toString( rhs ) )
|
|
|
|
.setOp( Internal::OperatorTraits<Op>::getName() );
|
|
|
|
}
|
|
|
|
|
2012-05-11 09:03:05 +02:00
|
|
|
private:
|
2012-10-26 09:45:23 +02:00
|
|
|
ExpressionResultBuilder m_result;
|
2012-05-11 09:03:05 +02:00
|
|
|
T m_lhs;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
2012-10-26 09:45:23 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|