Added mock::contain constraint

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@109 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2010-02-01 22:41:16 +00:00
parent 89d972bda5
commit 05f7625d1c
3 changed files with 29 additions and 0 deletions

View file

@ -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

View file

@ -12,6 +12,7 @@
#include <boost/ref.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/algorithm/string/predicate.hpp>
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_;
};
}
}

View file

@ -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" ) );
}