diff --git a/src/libraries/turtle/constraints.hpp b/src/libraries/turtle/constraints.hpp index 22c67cf..8bac47c 100644 --- a/src/libraries/turtle/constraints.hpp +++ b/src/libraries/turtle/constraints.hpp @@ -13,7 +13,6 @@ #include "format.hpp" #include #include -#include #include namespace mock @@ -82,7 +81,6 @@ namespace mock MOCK_CONSTRAINT( greater, actual > expected_ ) MOCK_CONSTRAINT( less_equal, actual <= expected_ ) MOCK_CONSTRAINT( greater_equal, actual >= expected_ ) - MOCK_CONSTRAINT( contain, boost::algorithm::contains( actual, expected_ ) ) namespace detail { @@ -161,6 +159,23 @@ namespace detail } Expected* expected_; }; + + template< typename Expected > + struct contain + { + explicit contain( const Expected& expected ) + : expected_( expected ) + {} + bool operator()( const std::string& actual ) const + { + return actual.find( expected_ ) != std::string::npos; + } + friend std::ostream& operator<<( std::ostream& s, const contain& n ) + { + return s << "contain ( " << mock::format( n.expected_ ) << " )"; + } + Expected expected_; + }; } template< typename T > @@ -178,6 +193,11 @@ namespace detail { return detail::assign< T >( t ); } + template< typename T > + constraint< detail::contain< T > > contain( T t ) + { + return detail::contain< T >( t ); + } template< typename T > constraint< T > call( T t ) diff --git a/src/tests/turtle_test/constraints_test.cpp b/src/tests/turtle_test/constraints_test.cpp index 40b4f76..6ef92a1 100644 --- a/src/tests/turtle_test/constraints_test.cpp +++ b/src/tests/turtle_test/constraints_test.cpp @@ -178,8 +178,18 @@ BOOST_AUTO_TEST_CASE( evaluate ) BOOST_CHECK( ! mock::evaluate.f_( &return_false ) ); } -BOOST_AUTO_TEST_CASE( contain ) +BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr ) { BOOST_CHECK( mock::contain( "string" ).f_( "this is a string" ) ); + BOOST_CHECK( mock::contain( "string" ).f_( std::string( "this is a string" ) ) ); BOOST_CHECK( ! mock::contain( "not found" ).f_( "this is a string" ) ); + BOOST_CHECK( ! mock::contain( "not found" ).f_( std::string( "this is a string" ) ) ); +} + +BOOST_AUTO_TEST_CASE( contain_with_strings ) +{ + BOOST_CHECK( mock::contain( std::string( "string" ) ).f_( "this is a string" ) ); + BOOST_CHECK( mock::contain( std::string( "string" ) ).f_( std::string( "this is a string" ) ) ); + BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).f_( "this is a string" ) ); + BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).f_( std::string( "this is a string" ) ) ); }