catch2/include/internal/catch_matchers.hpp

77 lines
2.6 KiB
C++
Raw Normal View History

2012-05-09 20:37:14 +02:00
/*
* Created by Phil Nash on 04/03/2012.
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
2012-03-04 21:10:36 +01:00
#ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
2012-05-15 08:42:26 +02:00
namespace Catch {
namespace Matchers {
namespace Impl {
namespace StdString {
struct Contains {
2012-03-04 21:10:36 +01:00
Contains( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const
{
return str.find( m_substr ) != std::string::npos;
}
friend std::ostream& operator<<( std::ostream& os, const Contains& matcher )
{
os << "contains: \"" << matcher.m_substr << "\"";
return os;
}
std::string m_substr;
};
2012-05-15 08:42:26 +02:00
struct StartsWith {
2012-03-04 21:10:36 +01:00
StartsWith( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const
{
return str.find( m_substr ) == 0;
}
friend std::ostream& operator<<( std::ostream& os, const StartsWith& matcher )
{
os << "starts with: \"" << matcher.m_substr << "\"";
return os;
}
std::string m_substr;
};
2012-05-15 08:42:26 +02:00
struct EndsWith {
2012-03-04 21:10:36 +01:00
EndsWith( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const
{
return str.find( m_substr ) == str.size() - m_substr.size();
}
friend std::ostream& operator<<( std::ostream& os, const EndsWith& matcher )
{
os << "ends with: \"" << matcher.m_substr << "\"";
return os;
}
std::string m_substr;
};
} // namespace StdString
} // namespace Impl
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::EndsWith EndsWith( const std::string& substr ){ return Impl::StdString::EndsWith( substr ); }
} // namespace Matchers
using namespace Matchers;
} // namespace Catch
#endif // TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED