mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-27 13:13:30 +01:00
Move expression classes into own file
This commit is contained in:
parent
d10d2d3485
commit
a6855f7eab
@ -8,6 +8,7 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||
|
||||
#include "catch_expression.hpp"
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
@ -24,197 +25,7 @@ namespace Catch
|
||||
|
||||
struct TestFailureException{};
|
||||
struct DummyExceptionType_DontUse{};
|
||||
|
||||
template<typename T>
|
||||
class Expression
|
||||
{
|
||||
void operator = ( const Expression& );
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression
|
||||
(
|
||||
ResultInfoBuilder& result,
|
||||
T lhs
|
||||
)
|
||||
: m_result( result ),
|
||||
m_lhs( lhs )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator <
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator >
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator <=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator >=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
bool rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
bool rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
return m_result.captureBoolExpression( m_lhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
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&
|
||||
);
|
||||
|
||||
private:
|
||||
ResultInfoBuilder& m_result;
|
||||
T m_lhs;
|
||||
};
|
||||
|
||||
template<typename LhsT>
|
||||
class PtrExpression
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
PtrExpression
|
||||
(
|
||||
ResultInfoBuilder& result,
|
||||
const LhsT* lhs
|
||||
)
|
||||
: m_result( &result ),
|
||||
m_lhs( lhs )
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
return m_result->captureBoolExpression( m_lhs );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
ResultInfoBuilder* m_result;
|
||||
const LhsT* m_lhs;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ResultBuilder
|
||||
{
|
||||
public:
|
||||
|
208
include/internal/catch_expression.hpp
Normal file
208
include/internal/catch_expression.hpp
Normal file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_evaluate.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class Expression
|
||||
{
|
||||
void operator = ( const Expression& );
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Expression
|
||||
(
|
||||
ResultInfoBuilder& result,
|
||||
T lhs
|
||||
)
|
||||
: m_result( result ),
|
||||
m_lhs( lhs )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator <
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator >
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator <=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator >=
|
||||
(
|
||||
const RhsT& rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
bool rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
bool rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
return m_result.captureBoolExpression( m_lhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
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&
|
||||
);
|
||||
|
||||
private:
|
||||
ResultInfoBuilder& m_result;
|
||||
T m_lhs;
|
||||
};
|
||||
|
||||
template<typename LhsT>
|
||||
class PtrExpression
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
PtrExpression
|
||||
(
|
||||
ResultInfoBuilder& result,
|
||||
const LhsT* lhs
|
||||
)
|
||||
: m_result( &result ),
|
||||
m_lhs( lhs )
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
ResultInfoBuilder& operator ==
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
ResultInfoBuilder& operator !=
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
operator ResultInfoBuilder&
|
||||
()
|
||||
{
|
||||
return m_result->captureBoolExpression( m_lhs );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
ResultInfoBuilder* m_result;
|
||||
const LhsT* m_lhs;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
|
@ -92,6 +92,7 @@
|
||||
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = "<group>"; };
|
||||
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_section_info.hpp; sourceTree = "<group>"; };
|
||||
4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_running_test.hpp; sourceTree = "<group>"; };
|
||||
4AC91CCE155CF02800DC5117 /* catch_expression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression.hpp; sourceTree = "<group>"; };
|
||||
4AE1840A14EE4F230066340D /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -214,6 +215,7 @@
|
||||
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
|
||||
4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */,
|
||||
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */,
|
||||
4AC91CCE155CF02800DC5117 /* catch_expression.hpp */,
|
||||
);
|
||||
name = Assertions;
|
||||
sourceTree = "<group>";
|
||||
|
Loading…
Reference in New Issue
Block a user