2017-02-08 16:14:51 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil Nash on 08/02/2017.
|
|
|
|
* Copyright (c) 2017 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)
|
|
|
|
*/
|
2017-02-21 16:52:03 +01:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|
2017-02-08 16:14:51 +01:00
|
|
|
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_matchers.h"
|
2017-02-08 16:14:51 +01:00
|
|
|
|
2017-07-12 16:07:52 +02:00
|
|
|
#include <string>
|
|
|
|
|
2017-02-08 16:14:51 +01:00
|
|
|
namespace Catch {
|
|
|
|
namespace Matchers {
|
|
|
|
|
|
|
|
namespace StdString {
|
|
|
|
|
|
|
|
struct CasedString
|
|
|
|
{
|
|
|
|
CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
|
|
|
|
std::string adjustString( std::string const& str ) const;
|
|
|
|
std::string caseSensitivitySuffix() const;
|
|
|
|
|
|
|
|
CaseSensitive::Choice m_caseSensitivity;
|
|
|
|
std::string m_str;
|
|
|
|
};
|
|
|
|
|
2017-02-14 10:15:08 +01:00
|
|
|
struct StringMatcherBase : MatcherBase<std::string> {
|
2017-03-06 13:16:43 +01:00
|
|
|
StringMatcherBase( std::string const& operation, CasedString const& comparator );
|
2017-07-20 16:57:17 +02:00
|
|
|
std::string describe() const override;
|
2017-02-08 16:14:51 +01:00
|
|
|
|
|
|
|
CasedString m_comparator;
|
|
|
|
std::string m_operation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EqualsMatcher : StringMatcherBase {
|
|
|
|
EqualsMatcher( CasedString const& comparator );
|
2017-07-20 16:57:17 +02:00
|
|
|
bool match( std::string const& source ) const override;
|
2017-02-08 16:14:51 +01:00
|
|
|
};
|
|
|
|
struct ContainsMatcher : StringMatcherBase {
|
|
|
|
ContainsMatcher( CasedString const& comparator );
|
2017-07-20 16:57:17 +02:00
|
|
|
bool match( std::string const& source ) const override;
|
2017-02-08 16:14:51 +01:00
|
|
|
};
|
|
|
|
struct StartsWithMatcher : StringMatcherBase {
|
|
|
|
StartsWithMatcher( CasedString const& comparator );
|
2017-07-20 16:57:17 +02:00
|
|
|
bool match( std::string const& source ) const override;
|
2017-02-08 16:14:51 +01:00
|
|
|
};
|
|
|
|
struct EndsWithMatcher : StringMatcherBase {
|
|
|
|
EndsWithMatcher( CasedString const& comparator );
|
2017-07-20 16:57:17 +02:00
|
|
|
bool match( std::string const& source ) const override;
|
2017-02-08 16:14:51 +01:00
|
|
|
};
|
|
|
|
|
2017-11-13 15:35:31 +01:00
|
|
|
struct RegexMatcher : MatcherBase<std::string> {
|
|
|
|
RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
|
|
|
|
bool match( std::string const& matchee ) const override;
|
|
|
|
std::string describe() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_regex;
|
|
|
|
CaseSensitive::Choice m_caseSensitivity;
|
|
|
|
};
|
|
|
|
|
2017-02-08 16:14:51 +01:00
|
|
|
} // namespace StdString
|
|
|
|
|
|
|
|
|
|
|
|
// The following functions create the actual matcher objects.
|
|
|
|
// This allows the types to be inferred
|
|
|
|
|
|
|
|
StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
|
|
|
|
StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
|
|
|
|
StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
|
|
|
|
StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
|
2017-11-13 15:35:31 +01:00
|
|
|
StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
|
2017-02-08 16:14:51 +01:00
|
|
|
|
|
|
|
} // namespace Matchers
|
|
|
|
} // namespace Catch
|
|
|
|
|
2017-02-21 16:52:03 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|