Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_matchers_generic.hpp
Go to the documentation of this file.
1/*
2 * Created by Martin Hořeňovský on 03/04/2017.
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See accompanying
5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7#ifndef TWOBLUECUBES_CATCH_MATCHERS_GENERIC_HPP_INCLUDED
8#define TWOBLUECUBES_CATCH_MATCHERS_GENERIC_HPP_INCLUDED
9
10#include "catch_common.h"
11#include "catch_matchers.h"
12
13#include <functional>
14#include <string>
15
16namespace Catch {
17namespace Matchers {
18namespace Generic {
19
20namespace Detail {
21 std::string finalizeDescription(const std::string& desc);
22}
23
24template <typename T>
25class PredicateMatcher : public MatcherBase<T> {
26 std::function<bool(T const&)> m_predicate;
27 std::string m_description;
28public:
29
30 PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
31 :m_predicate(std::move(elem)),
32 m_description(Detail::finalizeDescription(descr))
33 {}
34
35 bool match( T const& item ) const override {
36 return m_predicate(item);
37 }
38
39 std::string describe() const override {
40 return m_description;
41 }
42};
43
44} // namespace Generic
45
46 // The following functions create the actual matcher objects.
47 // The user has to explicitly specify type to the function, because
48 // inferring std::function<bool(T const&)> is hard (but possible) and
49 // requires a lot of TMP.
50 template<typename T>
51 Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
52 return Generic::PredicateMatcher<T>(predicate, description);
53 }
54
55} // namespace Matchers
56} // namespace Catch
57
58#endif // TWOBLUECUBES_CATCH_MATCHERS_GENERIC_HPP_INCLUDED
PredicateMatcher(std::function< bool(T const &)> const &elem, std::string const &descr)
std::string finalizeDescription(const std::string &desc)
Generic::PredicateMatcher< T > Predicate(std::function< bool(T const &)> const &predicate, std::string const &description="")
Definition name.hpp:106
#define T(meth, val, expected)