6#ifndef MIMICPP_POLICIES_ARG_REQUIREMENT_POLICIES_HPP
7#define MIMICPP_POLICIES_ARG_REQUIREMENT_POLICIES_HPP
17#ifndef MIMICPP_DETAIL_IS_MODULE
23 #include <type_traits>
29 template <
typename Matcher>
35 template <
typename... Args>
36 requires std::invocable<detail::matches_hook::matches_fn, Matcher
const&, Args&...>
42 std::is_nothrow_invocable_v<
43 decltype(detail::matches_hook::matches),
47 return detail::matches_hook::matches(
matcher, args...);
51 template <
typename Matcher,
typename MatchesStrategy,
typename DescribeStrategy>
58 MatchesStrategy matchesStrategy,
59 DescribeStrategy describeStrategy)
61 std::is_nothrow_move_constructible_v<Matcher>
62 && std::is_nothrow_move_constructible_v<MatchesStrategy>
63 && std::is_nothrow_move_constructible_v<DescribeStrategy>)
64 : m_Matcher{std::move(matcher)},
65 m_MatchesStrategy{std::move(matchesStrategy)},
66 m_DescribeStrategy{std::move(describeStrategy)}
76 template <
typename Return,
typename... Args>
77 requires std::is_invocable_r_v<bool, MatchesStrategy const&, matcher_matches_fn<Matcher>,
call::Info<Return, Args...>
const&>
80 noexcept(std::is_nothrow_invocable_v<MatchesStrategy const&, matcher_matches_fn<Matcher>,
call::Info<Return, Args...>
const&>)
88 template <
typename Return,
typename... Args>
96 [[maybe_unused]]
auto const description = detail::describe_hook::describe(m_Matcher);
102 return std::invoke(m_DescribeStrategy, *description);
107 else if constexpr (std::convertible_to<
decltype(description),
StringViewT>)
109 return std::invoke(m_DescribeStrategy, description);
119 [[no_unique_address]] MatchesStrategy m_MatchesStrategy;
120 [[no_unique_address]] DescribeStrategy m_DescribeStrategy;
124namespace mimicpp::expect::detail
126 template <std::size_t index, std::size_t... others>
127 struct arg_requirement_describer
133 out <<
"expect: arg[" << index;
134 ((out <<
", " << others), ...);
135 out <<
"] " << matcherDescription;
136 return std::move(out).str();
140 struct all_args_requirement_describer
146 out <<
"expect: arg[all] " << matcherDescription;
147 return std::move(out).str();
152 std::size_t... indices,
154 typename... Projections>
156 constexpr auto make_args_policy(
158 std::tuple<Projections...>&& projections)
161 sizeof...(indices) ==
sizeof...(Projections),
162 "Indices and projections size mismatch.");
164 using arg_selector_t = mimicpp::detail::args_selector_fn<
165 std::add_lvalue_reference_t,
166 std::index_sequence<indices...>>;
167 using apply_strategy_t = mimicpp::detail::arg_list_indirect_apply_fn<std::remove_cvref_t<Projections>...>;
168 using describe_strategy_t = arg_requirement_describer<indices...>;
171 std::forward<Matcher>(matcher),
172 mimicpp::detail::apply_args_fn(
174 apply_strategy_t{std::move(projections)}),
175 describe_strategy_t{}};
205 template <std::
size_t index,
typename Matcher,
typename Projection = std::
identity>
209 Projection&& projection = {})
211 std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>
212 && std::is_nothrow_constructible_v<std::remove_cvref_t<Projection>, Projection>)
214 return detail::make_args_policy<index>(
215 std::forward<Matcher>(matcher),
216 std::forward_as_tuple(std::forward<Projection>(projection)));
242 std::size_t... others,
244 typename... Projections>
246 constexpr auto args(Matcher&& matcher, Projections&&... projections)
248 std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>
249 && (... && std::is_nothrow_move_constructible_v<std::remove_cvref_t<Projections>>))
252 sizeof...(projections) <= 1u +
sizeof...(others),
253 "The projection count exceeds the amount of indices.");
255 return detail::make_args_policy<first, others...>(
256 std::forward<Matcher>(matcher),
257 util::detail::expand_tuple<std::identity, 1u +
sizeof...(others)>(
258 std::forward_as_tuple(std::forward<Projections>(projections)...)));
273 template <
typename Matcher>
276 noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>)
278 using arg_selector_t = mimicpp::detail::all_args_selector_fn<std::add_lvalue_reference_t>;
279 using apply_strategy_t = mimicpp::detail::arg_list_forward_apply_fn;
280 using describe_strategy_t = detail::all_args_requirement_describer;
283 std::forward<Matcher>(matcher),
284 mimicpp::detail::apply_args_fn(
287 describe_strategy_t{}};
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
Definition ArgRequirementPolicies.hpp:53
constexpr ArgsRequirement(Matcher matcher, MatchesStrategy matchesStrategy, DescribeStrategy describeStrategy) noexcept(std::is_nothrow_move_constructible_v< Matcher > &&std::is_nothrow_move_constructible_v< MatchesStrategy > &&std::is_nothrow_move_constructible_v< DescribeStrategy >)
Definition ArgRequirementPolicies.hpp:56
constexpr bool matches(const call::Info< Return, Args... > &info) const noexcept(std::is_nothrow_invocable_v< MatchesStrategy const &, matcher_matches_fn< Matcher >, call::Info< Return, Args... > const & >)
Definition ArgRequirementPolicies.hpp:79
static constexpr void consume(call::Info< Return, Args... > const &info) noexcept
Definition ArgRequirementPolicies.hpp:89
std::optional< StringT > describe() const
Definition ArgRequirementPolicies.hpp:94
static constexpr bool is_satisfied() noexcept
Definition ArgRequirementPolicies.hpp:71
Determines, whether B behaves as a the builtin type bool.
Definition Concepts.hpp:66
constexpr auto arg(Matcher &&matcher, Projection &&projection={}) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&std::is_nothrow_constructible_v< std::remove_cvref_t< Projection >, Projection >)
Checks whether the selected argument satisfies the given matcher.
Definition ArgRequirementPolicies.hpp:207
constexpr auto all_args(Matcher &&matcher) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher >)
Checks whether the all arguments satisfy the given matcher.
Definition ArgRequirementPolicies.hpp:275
constexpr auto args(Matcher &&matcher, Projections &&... projections) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&(... &&std::is_nothrow_move_constructible_v< std::remove_cvref_t< Projections > >))
Checks whether the selected arguments satisfy the given matcher.
Definition ArgRequirementPolicies.hpp:246
Definition ArgRequirementPolicies.hpp:125
Definition ArgRequirementPolicies.hpp:28
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Format.hpp:35
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:392
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:391
Definition ArgRequirementPolicies.hpp:31
Matcher const & matcher
Definition ArgRequirementPolicies.hpp:33
constexpr bool operator()(Args &&... args) const noexcept(std::is_nothrow_invocable_v< decltype(detail::matches_hook::matches), Matcher const &, Args &... >)
Definition ArgRequirementPolicies.hpp:40