Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:07

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_MATCHERS_STRING_HPP_INCLUDED
0009 #define CATCH_MATCHERS_STRING_HPP_INCLUDED
0010 
0011 #include <catch2/matchers/catch_matchers.hpp>
0012 #include <catch2/internal/catch_case_sensitive.hpp>
0013 #include <catch2/internal/catch_stringref.hpp>
0014 
0015 #include <string>
0016 
0017 namespace Catch {
0018 namespace Matchers {
0019 
0020     struct CasedString {
0021         CasedString( std::string const& str, CaseSensitive caseSensitivity );
0022         std::string adjustString( std::string const& str ) const;
0023         StringRef caseSensitivitySuffix() const;
0024 
0025         CaseSensitive m_caseSensitivity;
0026         std::string m_str;
0027     };
0028 
0029     class StringMatcherBase : public MatcherBase<std::string> {
0030     protected:
0031         CasedString m_comparator;
0032         StringRef m_operation;
0033 
0034     public:
0035         StringMatcherBase( StringRef operation,
0036                            CasedString const& comparator );
0037         std::string describe() const override;
0038     };
0039 
0040     class StringEqualsMatcher final : public StringMatcherBase {
0041     public:
0042         StringEqualsMatcher( CasedString const& comparator );
0043         bool match( std::string const& source ) const override;
0044     };
0045     class StringContainsMatcher final : public StringMatcherBase {
0046     public:
0047         StringContainsMatcher( CasedString const& comparator );
0048         bool match( std::string const& source ) const override;
0049     };
0050     class StartsWithMatcher final : public StringMatcherBase {
0051     public:
0052         StartsWithMatcher( CasedString const& comparator );
0053         bool match( std::string const& source ) const override;
0054     };
0055     class EndsWithMatcher final : public StringMatcherBase {
0056     public:
0057         EndsWithMatcher( CasedString const& comparator );
0058         bool match( std::string const& source ) const override;
0059     };
0060 
0061     class RegexMatcher final : public MatcherBase<std::string> {
0062         std::string m_regex;
0063         CaseSensitive m_caseSensitivity;
0064 
0065     public:
0066         RegexMatcher( std::string regex, CaseSensitive caseSensitivity );
0067         bool match( std::string const& matchee ) const override;
0068         std::string describe() const override;
0069     };
0070 
0071     //! Creates matcher that accepts strings that are exactly equal to `str`
0072     StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
0073     //! Creates matcher that accepts strings that contain `str`
0074     StringContainsMatcher ContainsSubstring( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
0075     //! Creates matcher that accepts strings that _end_ with `str`
0076     EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
0077     //! Creates matcher that accepts strings that _start_ with `str`
0078     StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
0079     //! Creates matcher that accepts strings matching `regex`
0080     RegexMatcher Matches( std::string const& regex, CaseSensitive caseSensitivity = CaseSensitive::Yes );
0081 
0082 } // namespace Matchers
0083 } // namespace Catch
0084 
0085 #endif // CATCH_MATCHERS_STRING_HPP_INCLUDED