mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
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:
parent
89d972bda5
commit
05f7625d1c
3 changed files with 29 additions and 0 deletions
|
|
@ -127,6 +127,12 @@ namespace detail
|
||||||
return constraint( detail::retrieval< T >( boost::ref( t ) ),
|
return constraint( detail::retrieval< T >( boost::ref( t ) ),
|
||||||
"retrieve", 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
|
#endif // #ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <boost/type_traits/is_convertible.hpp>
|
#include <boost/type_traits/is_convertible.hpp>
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
|
@ -154,6 +155,22 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
boost::reference_wrapper< T > t_;
|
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_;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,3 +165,9 @@ BOOST_AUTO_TEST_CASE( evaluate )
|
||||||
BOOST_CHECK( mock::evaluate.functor_( &return_true ) );
|
BOOST_CHECK( mock::evaluate.functor_( &return_true ) );
|
||||||
BOOST_CHECK( ! mock::evaluate.functor_( &return_false ) );
|
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" ) );
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue