Catch/include/internal/catch_expressionresult_builder.h

59 lines
2.0 KiB
C
Raw Normal View History

2012-08-08 03:58:28 -04: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 03:27:21 -04:00
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
2012-08-08 03:58:28 -04:00
#include "catch_tostring.hpp"
#include "catch_assertionresult.h"
2012-08-08 03:58:28 -04:00
#include "catch_result_type.h"
#include "catch_evaluate.hpp"
#include "catch_common.h"
namespace Catch {
2012-10-26 04:05:36 -04: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 03:58:28 -04:00
public:
ExpressionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown );
ExpressionResultBuilder( const ExpressionResultBuilder& other );
ExpressionResultBuilder& operator=(const ExpressionResultBuilder& other );
2012-10-16 03:27:21 -04:00
ExpressionResultBuilder& setResultType( ResultWas::OfType result );
ExpressionResultBuilder& setResultType( bool result );
ExpressionResultBuilder& setLhs( const std::string& lhs );
ExpressionResultBuilder& setRhs( const std::string& rhs );
ExpressionResultBuilder& setOp( const std::string& op );
2012-10-24 16:59:47 -04:00
ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition );
template<typename T>
ExpressionResultBuilder& operator << ( const T& value ) {
m_stream << value;
return *this;
}
2012-10-24 16:59:47 -04:00
std::string reconstructExpression( const AssertionInfo& info ) const;
2012-10-26 04:05:36 -04:00
AssertionResult buildResult( const AssertionInfo& info ) const;
private:
2012-10-16 03:33:13 -04:00
AssertionResultData m_data;
struct ExprComponents {
2012-10-24 16:59:47 -04:00
ExprComponents() : shouldNegate( false ) {}
bool shouldNegate;
std::string lhs, rhs, op;
} m_exprComponents;
std::ostringstream m_stream;
};
2012-08-08 03:58:28 -04:00
} // end namespace Catch
2012-10-16 03:27:21 -04:00
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED