From 05f7625d1cab4af209b3382257e66adf67616f1f Mon Sep 17 00:00:00 2001 From: mat007 Date: Mon, 1 Feb 2010 22:41:16 +0000 Subject: [PATCH] Added mock::contain constraint git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@109 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/constraint.hpp | 6 ++++++ src/libraries/turtle/functional.hpp | 17 +++++++++++++++++ src/tests/turtle_test/constraint_test.cpp | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/src/libraries/turtle/constraint.hpp b/src/libraries/turtle/constraint.hpp index 00c0b40..ae2a322 100644 --- a/src/libraries/turtle/constraint.hpp +++ b/src/libraries/turtle/constraint.hpp @@ -127,6 +127,12 @@ namespace detail return constraint( detail::retrieval< T >( boost::ref( t ) ), "retrieve", t ); } + + template< typename T > + detail::placeholder< detail::container< T > > contain( T t ) + { + return constraint( detail::container< T >( t ), "contain", t ); + } } #endif // #ifndef MOCK_CONSTRAINT_HPP_INCLUDED diff --git a/src/libraries/turtle/functional.hpp b/src/libraries/turtle/functional.hpp index d319e93..91e9154 100644 --- a/src/libraries/turtle/functional.hpp +++ b/src/libraries/turtle/functional.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace mock { @@ -154,6 +155,22 @@ namespace detail private: boost::reference_wrapper< T > t_; }; + + template< typename T > + class container + { + public: + explicit container( const T& t ) + : t_( t ) + {} + template< typename Y > + bool operator()( const Y& y ) const + { + return boost::algorithm::contains( y, t_ ); + } + private: + T t_; + }; } } diff --git a/src/tests/turtle_test/constraint_test.cpp b/src/tests/turtle_test/constraint_test.cpp index f481e64..466e423 100644 --- a/src/tests/turtle_test/constraint_test.cpp +++ b/src/tests/turtle_test/constraint_test.cpp @@ -165,3 +165,9 @@ BOOST_AUTO_TEST_CASE( evaluate ) BOOST_CHECK( mock::evaluate.functor_( &return_true ) ); BOOST_CHECK( ! mock::evaluate.functor_( &return_false ) ); } + +BOOST_AUTO_TEST_CASE( contain ) +{ + BOOST_CHECK( mock::contain( "string" ).functor_( "this is a string" ) ); + BOOST_CHECK( ! mock::contain( "not found" ).functor_( "this is a string" ) ); +}