| 
									
										
										
										
											2012-11-01 08:27:09 +00: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)
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifndef TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 18:53:01 +01:00
										 |  |  | #include "catch_result_builder.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | #include "catch_evaluate.hpp"
 | 
					
						
							| 
									
										
										
										
											2014-04-23 06:51:58 +01:00
										 |  |  | #include "catch_tostring.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Catch { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  | // Wraps the LHS of an expression and captures the operator and RHS (if any) -
 | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  | // wrapping them all in a ResultBuilder object
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | template<typename T> | 
					
						
							|  |  |  | class ExpressionLhs { | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  |     ExpressionLhs& operator = ( ExpressionLhs const& ); | 
					
						
							| 
									
										
										
										
											2015-05-19 18:37:58 +01:00
										 |  |  | #  ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
 | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  |     ExpressionLhs& operator = ( ExpressionLhs && ) = delete; | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} | 
					
						
							| 
									
										
										
										
											2015-05-19 18:37:58 +01:00
										 |  |  | #  ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
 | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  |     ExpressionLhs( ExpressionLhs const& ) = default; | 
					
						
							|  |  |  |     ExpressionLhs( ExpressionLhs && )     = default; | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator == ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator != ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsNotEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator < ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsLessThan>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator > ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsGreaterThan>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator <= ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator >= ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator == ( bool rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& operator != ( bool rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsNotEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 18:53:01 +01:00
										 |  |  |     void endExpression() { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         bool value = m_lhs ? true : false; | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |         m_rb | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |             .setLhs( Catch::toString( value ) ) | 
					
						
							|  |  |  |             .setResultType( value ) | 
					
						
							| 
									
										
										
										
											2014-05-28 18:53:01 +01:00
										 |  |  |             .endExpression(); | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Only simple binary expressions are allowed on the LHS.
 | 
					
						
							|  |  |  |     // If more complex compositions are required then place the sub expression in parentheses
 | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     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& ); | 
					
						
							|  |  |  |     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& ); | 
					
						
							| 
									
										
										
										
											2013-06-29 12:07:33 +01:00
										 |  |  |     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& ); | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     template<Internal::Operator Op, typename RhsT> | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& captureExpression( RhsT const& rhs ) { | 
					
						
							|  |  |  |         return m_rb | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |             .setResultType( Internal::compare<Op>( m_lhs, rhs ) ) | 
					
						
							|  |  |  |             .setLhs( Catch::toString( m_lhs ) ) | 
					
						
							|  |  |  |             .setRhs( Catch::toString( rhs ) ) | 
					
						
							|  |  |  |             .setOp( Internal::OperatorTraits<Op>::getName() ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2014-05-29 07:50:19 +01:00
										 |  |  |     ResultBuilder& m_rb; | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     T m_lhs; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // end namespace Catch
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
 |