6#ifndef MIMICPP_EXPECTATION_POLICIES_HPP
7#define MIMICPP_EXPECTATION_POLICIES_HPP
24 template <
typename Return,
typename... Args>
30 template <ValueCategory expected>
39 template <
typename Return,
typename... Args>
45 template <
typename Return,
typename... Args>
54 return format::format(
55 "expect: from {} category overload",
60 template <Constness constness>
69 template <
typename Return,
typename... Args>
75 template <
typename Return,
typename... Args>
84 return format::format(
85 "expect: from {} qualified overload",
90 template <
typename Action>
91 requires std::same_as<Action, std::remove_cvref_t<Action>>
92 && std::is_move_constructible_v<Action>
98 Action&& action)
noexcept(std::is_nothrow_move_constructible_v<Action>)
99 : m_Action{std::move(action)}
103 template <
typename Return,
typename... Args>
104 requires std::invocable<Action&,
const call::Info<Return, Args...>&>
106 std::invoke_result_t<Action&,
const call::Info<Return, Args...>&>,
112 return static_cast<Return
>(
113 std::invoke(m_Action, call));
120 template <
typename Exception>
121 requires(!std::is_reference_v<Exception>)
122 && std::copyable<Exception>
127 explicit constexpr Throws(Exception exception)
noexcept(std::is_nothrow_move_constructible_v<Exception>)
128 : m_Exception{std::move(exception)}
132 template <
typename Return,
typename... Args>
140 Exception m_Exception;
143 template <
typename Matcher,
typename Projection,
typename Describer>
144 requires std::same_as<Matcher, std::remove_cvref_t<Matcher>>
145 && std::same_as<Projection, std::remove_cvref_t<Projection>>
146 && std::same_as<Describer, std::remove_cvref_t<Describer>>
147 && std::is_move_constructible_v<Matcher>
148 && std::is_move_constructible_v<Projection>
149 && std::is_move_constructible_v<Describer>
156 Projection projection = {},
157 Describer describer = {})
noexcept(std::is_nothrow_move_constructible_v<Matcher> && std::is_nothrow_move_constructible_v<Projection> && std::is_nothrow_move_constructible_v<Describer>)
158 : m_Matcher{std::move(matcher)},
159 m_Projection{std::move(projection)},
160 m_Describer{std::move(describer)}
169 template <
typename Return,
typename... Args>
170 requires std::invocable<
const Projection&,
const call::Info<Return, Args...>&>
173 std::invoke_result_t<
const Projection&,
const call::Info<Return, Args...>&>>
177 decltype(
auto) projected = std::invoke(m_Projection, info);
178 return detail::matches_hook::matches(
183 template <
typename Return,
typename... Args>
193 detail::describe_hook::describe(m_Matcher));
197 [[no_unique_address]] Matcher m_Matcher;
198 [[no_unique_address]] Projection m_Projection;
199 [[no_unique_address]] Describer m_Describer;
202 template <
typename Action>
210 Action&& action)
noexcept(std::is_nothrow_move_constructible_v<Action>)
211 : m_Action{std::move(action)}
227 template <
typename Return,
typename... Args>
240 template <
typename Return,
typename... Args>
241 requires std::invocable<Action&,
const call::Info<Return, Args...>&>
245 std::invoke(m_Action, info);
252 template <
typename Action,
template <
typename>
typename Projection>
253 requires std::same_as<Action, std::remove_cvref_t<Action>>
259 Action action = {})
noexcept(std::is_nothrow_move_constructible_v<Action>)
260 : m_Action{std::move(action)}
264 template <
typename Arg>
267 template <
typename Return,
typename... Args>
268 requires std::invocable<
276 "Projection can not be applied.");
279 [
this](
auto&... args) ->
decltype(
auto) {
292 template <
typename Action,
template <
typename>
typename Projection, std::size_t... indices>
293 requires std::same_as<Action, std::remove_cvref_t<Action>>
299 Action action = {})
noexcept(std::is_nothrow_move_constructible_v<Action>)
300 : m_Action{std::move(action)}
304 template <std::size_t index,
typename... Args>
307 template <std::size_t index,
typename... Args>
310 template <
typename Return,
typename... Args>
311 requires(... && (indices <
sizeof...(Args)))
323 "Projection can not be applied.");
328 std::get<indices>(callInfo.args).get())...);
332 [[no_unique_address]] Action m_Action;
340 template <std::
size_t index>
341 struct arg_requirement_describer
347 return format::format(
348 "expect: arg[{}] {}",
378 template <std::
size_t index,
typename Matcher,
typename Projection = std::
identity>
382 Projection projection = {})
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher> && std::is_nothrow_move_constructible_v<Projection>)
386 std::add_lvalue_reference_t,
389 std::remove_cvref_t<Matcher>,
391 detail::arg_requirement_describer<index>>;
394 std::forward<Matcher>(matcher),
395 ProjectionT{std::move(projection)}};
436 template <
typename Fun>
437 requires std::invocable<std::remove_cvref_t<Fun>&>
438 && (!std::is_void_v<std::invoke_result_t<std::remove_cvref_t<Fun>&>>)
441 Fun&& fun)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Fun>, Fun>)
444 [fn = std::forward<Fun>(fun)]([[maybe_unused]]
const auto& call)
mutable noexcept(std::is_nothrow_invocable_v<
decltype(fun)>) ->
decltype(
auto) {
445 return std::invoke(fn);
466 template <
typename T>
467 requires std::copyable<std::remove_cvref_t<T>>
471 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<T>, T>)
474 [v = std::forward<T>(value)]([[maybe_unused]]
const auto& call)
mutable noexcept ->
auto& {
475 return static_cast<std::unwrap_reference_t<decltype(v)
>&>(v);
491 template <std::size_t index, std::size_t... otherIndices,
typename Action>
494 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
497 std::remove_cvref_t<Action>,
498 std::add_lvalue_reference_t,
503 ActionT{std::forward<Action>(action)}};
516 template <
typename Action>
519 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
522 std::remove_cvref_t<Action>,
523 std::add_lvalue_reference_t>;
526 ActionT{std::forward<Action>(action)}};
536 template <std::
size_t index>
542 std::add_rvalue_reference_t,
558 template <
typename T>
559 requires std::copyable<std::remove_cvref_t<T>>
562 T&& exception)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<T>, T>)
565 std::forward<T>(exception)};
605 template <std::
size_t index,
typename Action>
608 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
611 std::remove_cvref_t<Action>,
612 std::add_lvalue_reference_t,
616 ActionT{std::forward<Action>(action)}};
629 template <std::size_t index, std::size_t... additionalIndices,
typename Action>
632 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
635 std::remove_cvref_t<Action>,
636 std::add_lvalue_reference_t,
638 additionalIndices...>;
641 ActionT{std::forward<Action>(action)}};
650 template <
typename Action>
653 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
656 std::remove_cvref_t<Action>,
657 std::add_lvalue_reference_t>;
660 ActionT{std::forward<Action>(action)}};
669 template <std::invocable Action>
672 Action&& action)
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
675 [fn = std::forward<Action>(action)]([[maybe_unused]]
const auto& call)
mutable noexcept(std::is_nothrow_invocable_v<Action&>) {
Definition ExpectationPolicies.hpp:255
constexpr decltype(auto) operator()(const call::Info< Return, Args... > &callInfo) const noexcept(std::is_nothrow_invocable_v< const Action &, ProjectedArgT< Args >... >)
Definition ExpectationPolicies.hpp:271
constexpr ApplyAllArgsAction(Action action={}) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:258
Projection< Arg > ProjectedArgT
Definition ExpectationPolicies.hpp:265
Definition ExpectationPolicies.hpp:295
constexpr decltype(auto) operator()(const call::Info< Return, Args... > &callInfo) const noexcept(std::is_nothrow_invocable_v< const Action &, ProjectedArgListElementT< indices, Args... >... >)
Definition ExpectationPolicies.hpp:315
std::tuple_element_t< index, std::tuple< Args... > > ArgListElementT
Definition ExpectationPolicies.hpp:305
constexpr ApplyArgsAction(Action action={}) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:298
Projection< ArgListElementT< index, Args... > > ProjectedArgListElementT
Definition ExpectationPolicies.hpp:308
Definition ExpectationPolicies.hpp:32
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:34
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:46
static StringT describe()
Definition ExpectationPolicies.hpp:52
static constexpr bool matches(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:40
Definition ExpectationPolicies.hpp:62
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:64
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:76
static constexpr bool matches(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:70
static StringT describe()
Definition ExpectationPolicies.hpp:82
Definition ExpectationPolicies.hpp:22
static constexpr void finalize_call(const call::Info< Return, Args... > &) noexcept
Definition ExpectationPolicies.hpp:25
Definition ExpectationPolicies.hpp:151
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:184
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:164
constexpr bool matches(const call::Info< Return, Args... > &info) const
Definition ExpectationPolicies.hpp:175
constexpr Requirement(Matcher matcher, Projection projection={}, Describer describer={}) noexcept(std::is_nothrow_move_constructible_v< Matcher > &&std::is_nothrow_move_constructible_v< Projection > &&std::is_nothrow_move_constructible_v< Describer >)
Definition ExpectationPolicies.hpp:154
StringT describe() const
Definition ExpectationPolicies.hpp:189
Definition ExpectationPolicies.hpp:94
constexpr Return finalize_call(const call::Info< Return, Args... > &call) noexcept(std::is_nothrow_invocable_v< Action &, const call::Info< Return, Args... > & > &¬hrow_explicitly_convertible_to< std::invoke_result_t< Action &, const call::Info< Return, Args... > & >, Return >)
Definition ExpectationPolicies.hpp:109
constexpr ReturnsResultOf(Action &&action) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:97
Definition ExpectationPolicies.hpp:204
static constexpr bool matches(const call::Info< Return, Args... > &) noexcept
Definition ExpectationPolicies.hpp:229
static std::nullopt_t describe() noexcept
Definition ExpectationPolicies.hpp:235
~SideEffectAction()=default
constexpr void consume(const call::Info< Return, Args... > &info) noexcept(std::is_nothrow_invocable_v< Action &, const call::Info< Return, Args... > & >)
Definition ExpectationPolicies.hpp:242
SideEffectAction & operator=(const SideEffectAction &)=delete
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:222
SideEffectAction(SideEffectAction &&)=default
constexpr SideEffectAction(Action &&action) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:209
SideEffectAction & operator=(SideEffectAction &&)=default
SideEffectAction(const SideEffectAction &)=delete
Definition ExpectationPolicies.hpp:124
constexpr Return finalize_call(const call::Info< Return, Args... > &call)
Definition ExpectationPolicies.hpp:133
constexpr Throws(Exception exception) noexcept(std::is_nothrow_move_constructible_v< Exception >)
Definition ExpectationPolicies.hpp:127
Definition Utility.hpp:51
Definition Matcher.hpp:110
Definition Utility.hpp:57
constexpr auto returns_apply_all_result_of(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
During the finalization step, all call arguments are applied on the given action.
Definition ExpectationPolicies.hpp:518
constexpr auto returns_apply_result_of(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
During the finalization step, the selected call arguments are applied on the given action.
Definition ExpectationPolicies.hpp:493
constexpr auto returns(T &&value) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< T >, T >)
During the finalization step, the stored value is returned.
Definition ExpectationPolicies.hpp:469
constexpr auto returns_arg() noexcept
During the finalization step, the selected call argument is returned.
Definition ExpectationPolicies.hpp:538
constexpr auto returns_result_of(Fun &&fun) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Fun >, Fun >)
During the finalization step, the invocation result of the given function is returned.
Definition ExpectationPolicies.hpp:440
constexpr auto arg(Matcher &&matcher, Projection projection={}) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Matcher >, Matcher > &&std::is_nothrow_move_constructible_v< Projection >)
Checks, whether the selected argument matches the given matcher.
Definition ExpectationPolicies.hpp:380
constexpr auto apply_all(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
Applies all arguments on the given action.
Definition ExpectationPolicies.hpp:652
constexpr auto apply_arg(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
Applies the argument at the specified index on the given action.
Definition ExpectationPolicies.hpp:607
constexpr auto invoke(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
Invokes the given function.
Definition ExpectationPolicies.hpp:671
constexpr auto apply_args(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
Applies the arguments at the specified index and in that order on the given action.
Definition ExpectationPolicies.hpp:631
Definition ControlPolicy.hpp:252
Definition ExpectationPolicies.hpp:20
Definition ExpectationPolicies.hpp:404
Definition ExpectationPolicies.hpp:576
constexpr bool is_matching(const Constness lhs, const Constness rhs) noexcept
Definition Utility.hpp:107
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:343
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:342