Catch/include/internal/catch_matchers.hpp

94 lines
3.2 KiB
C++
Raw Normal View History

2012-05-09 14:37:14 -04: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 15:10:36 -05:00
#ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
2012-05-15 02:42:26 -04:00
namespace Catch {
namespace Matchers {
namespace Impl {
namespace StdString {
2012-05-24 03:27:50 -04:00
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 {
2012-03-04 15:10:36 -05: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 02:42:26 -04:00
struct StartsWith {
2012-03-04 15:10:36 -05: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 02:42:26 -04:00
struct EndsWith {
2012-03-04 15:10:36 -05: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
2012-05-24 03:27:50 -04:00
inline Impl::StdString::Equals Equals( const std::string& str ){ return Impl::StdString::Equals( str ); }
2012-03-04 15:10:36 -05:00
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