mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-20 11:35:39 +02:00
Folded ExpressionResultBuilder into ResultBuilder
(even more SRP violations!)
This commit is contained in:
@@ -9,20 +9,13 @@
|
||||
#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
|
||||
|
||||
#include "catch_result_builder.h"
|
||||
#include "catch_expressionresult_builder.h"
|
||||
#include "catch_evaluate.hpp"
|
||||
#include "catch_tostring.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct ResultBuilder;
|
||||
|
||||
ExpressionResultBuilder& getResultBuilder( ResultBuilder* rb );
|
||||
|
||||
// Wraps the LHS of an expression and captures the operator and RHS (if any) -
|
||||
// wrapping them all in an ExpressionResultBuilder object
|
||||
// wrapping them all in a ResultBuilder object
|
||||
template<typename T>
|
||||
class ExpressionLhs {
|
||||
ExpressionLhs& operator = ( ExpressionLhs const& );
|
||||
@@ -31,54 +24,53 @@ class ExpressionLhs {
|
||||
# endif
|
||||
|
||||
public:
|
||||
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( &rb ), m_lhs( lhs ) {}
|
||||
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {}
|
||||
# ifdef CATCH_CPP11_OR_GREATER
|
||||
ExpressionLhs( ExpressionLhs const& ) = default;
|
||||
ExpressionLhs( ExpressionLhs && ) = default;
|
||||
# endif
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator == ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator == ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator != ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator != ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator < ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator < ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsLessThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator > ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator > ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThan>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator <= ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator <= ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
template<typename RhsT>
|
||||
ExpressionResultBuilder& operator >= ( RhsT const& rhs ) {
|
||||
ResultBuilder& operator >= ( RhsT const& rhs ) {
|
||||
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& operator == ( bool rhs ) {
|
||||
ResultBuilder& operator == ( bool rhs ) {
|
||||
return captureExpression<Internal::IsEqualTo>( rhs );
|
||||
}
|
||||
|
||||
ExpressionResultBuilder& operator != ( bool rhs ) {
|
||||
ResultBuilder& operator != ( bool rhs ) {
|
||||
return captureExpression<Internal::IsNotEqualTo>( rhs );
|
||||
}
|
||||
|
||||
void endExpression() {
|
||||
assert( m_rb );
|
||||
bool value = m_lhs ? true : false;
|
||||
getResultBuilder( m_rb )
|
||||
m_rb
|
||||
.setLhs( Catch::toString( value ) )
|
||||
.setResultType( value )
|
||||
.endExpression();
|
||||
@@ -95,9 +87,8 @@ public:
|
||||
|
||||
private:
|
||||
template<Internal::Operator Op, typename RhsT>
|
||||
ExpressionResultBuilder& captureExpression( RhsT const& rhs ) {
|
||||
assert( m_rb );
|
||||
return getResultBuilder( m_rb )
|
||||
ResultBuilder& captureExpression( RhsT const& rhs ) {
|
||||
return m_rb
|
||||
.setResultType( Internal::compare<Op>( m_lhs, rhs ) )
|
||||
.setLhs( Catch::toString( m_lhs ) )
|
||||
.setRhs( Catch::toString( rhs ) )
|
||||
@@ -105,7 +96,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
ResultBuilder* m_rb;
|
||||
ResultBuilder& m_rb;
|
||||
T m_lhs;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user