Added Equals matcher for strings

This commit is contained in:
Phil Nash 2012-05-24 08:27:50 +01:00
parent be838671ab
commit 1c98fc98ef

View File

@ -13,6 +13,22 @@ namespace Matchers {
namespace Impl { namespace Impl {
namespace StdString { namespace StdString {
struct Equals {
Equals( const std::string& str ) : m_str( str ){}
bool operator()( const std::string& str ) const
{
return str == m_str;
}
friend std::ostream& operator<<( std::ostream& os, const Equals& matcher )
{
os << "equals: \"" << matcher.m_str << "\"";
return os;
}
std::string m_str;
};
struct Contains { struct Contains {
Contains( const std::string& substr ) : m_substr( substr ){} Contains( const std::string& substr ) : m_substr( substr ){}
@ -63,6 +79,7 @@ namespace Matchers {
} // namespace StdString } // namespace StdString
} // namespace Impl } // namespace Impl
inline Impl::StdString::Equals Equals( const std::string& str ){ return Impl::StdString::Equals( str ); }
inline Impl::StdString::Contains Contains( const std::string& substr ){ return Impl::StdString::Contains( substr ); } inline Impl::StdString::Contains Contains( const std::string& substr ){ return Impl::StdString::Contains( substr ); }
inline Impl::StdString::StartsWith StartsWith( const std::string& substr ){ return Impl::StdString::StartsWith( substr ); } inline Impl::StdString::StartsWith StartsWith( const std::string& substr ){ return Impl::StdString::StartsWith( substr ); }
inline Impl::StdString::EndsWith EndsWith( const std::string& substr ){ return Impl::StdString::EndsWith( substr ); } inline Impl::StdString::EndsWith EndsWith( const std::string& substr ){ return Impl::StdString::EndsWith( substr ); }