catch2/include/internal/catch_expressionresult_buil...

64 lines
2.3 KiB
C
Raw Normal View History

2012-08-08 09:58:28 +02:00
/*
* Created by Phil on 8/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-16 09:27:21 +02:00
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
2012-08-08 09:58:28 +02:00
#include "catch_tostring.hpp"
#include "catch_assertionresult.h"
2012-08-08 09:58:28 +02:00
#include "catch_result_type.h"
#include "catch_evaluate.hpp"
#include "catch_common.h"
namespace Catch {
2012-10-26 10:05:36 +02:00
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
2012-10-26 10:05:36 +02:00
// Wraps the (stringised versions of) the lhs, operator and rhs of an expression - as well as
// the result of evaluating it. This is used to build an AssertionResult object
class ExpressionResultBuilder {
2012-08-08 09:58:28 +02:00
public:
ExpressionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown );
ExpressionResultBuilder( ExpressionResultBuilder const& other );
ExpressionResultBuilder& operator=(ExpressionResultBuilder const& other );
2012-10-16 09:27:21 +02:00
ExpressionResultBuilder& setResultType( ResultWas::OfType result );
ExpressionResultBuilder& setResultType( bool result );
ExpressionResultBuilder& setLhs( std::string const& lhs );
ExpressionResultBuilder& setRhs( std::string const& rhs );
ExpressionResultBuilder& setOp( std::string const& op );
2012-10-24 22:59:47 +02:00
ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition );
template<typename T>
ExpressionResultBuilder& operator << ( T const& value ) {
m_stream << value;
return *this;
}
std::string reconstructExpression( AssertionInfo const& info ) const;
AssertionResult buildResult( AssertionInfo const& info ) const;
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
private:
2012-10-16 09:33:13 +02:00
AssertionResultData m_data;
struct ExprComponents {
2012-10-24 22:59:47 +02:00
ExprComponents() : shouldNegate( false ) {}
bool shouldNegate;
std::string lhs, rhs, op;
} m_exprComponents;
std::ostringstream m_stream;
};
2012-08-08 09:58:28 +02:00
} // end namespace Catch
2012-10-16 09:27:21 +02:00
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED