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>
99 )
noexcept(std::is_nothrow_move_constructible_v<Action>)
100 : m_Action{std::move(action)}
104 template <
typename Return,
typename... Args>
105 requires std::invocable<Action&,
const call::Info<Return, Args...>&>
107 std::invoke_result_t<Action&,
const call::Info<Return, Args...>&>,
113 std::is_nothrow_invocable_v<Action&,
const call::Info<Return, Args...>&>
115 std::invoke_result_t<Action&,
const call::Info<Return, Args...>&>,
118 return static_cast<Return
>(
119 std::invoke(m_Action, call));
126 template <
typename Exception>
127 requires (!std::is_reference_v<Exception>)
128 && std::copyable<Exception>
133 explicit constexpr Throws(Exception exception)
noexcept(std::is_nothrow_move_constructible_v<Exception>)
134 : m_Exception{std::move(exception)}
138 template <
typename Return,
typename... Args>
147 Exception m_Exception;
150 template <
typename Matcher,
typename Projection,
typename Describer>
151 requires std::same_as<Matcher, std::remove_cvref_t<Matcher>>
152 && std::same_as<Projection, std::remove_cvref_t<Projection>>
153 && std::same_as<Describer, std::remove_cvref_t<Describer>>
154 && std::is_move_constructible_v<Matcher>
155 && std::is_move_constructible_v<Projection>
156 && std::is_move_constructible_v<Describer>
163 Projection projection = {},
164 Describer describer = {}
166 std::is_nothrow_move_constructible_v<Matcher>
167 && std::is_nothrow_move_constructible_v<Projection>
168 && std::is_nothrow_move_constructible_v<Describer>)
169 : m_Matcher{std::move(matcher)},
170 m_Projection{std::move(projection)},
171 m_Describer{std::move(describer)}
180 template <
typename Return,
typename... Args>
181 requires std::invocable<
const Projection&,
const call::Info<Return, Args...>&>
184 std::invoke_result_t<
const Projection&,
const call::Info<Return, Args...>&>>
188 decltype(
auto) projected = std::invoke(m_Projection, info);
189 return detail::matches_hook::matches(
194 template <
typename Return,
typename... Args>
204 detail::describe_hook::describe(m_Matcher));
208 [[no_unique_address]] Matcher m_Matcher;
209 [[no_unique_address]] Projection m_Projection;
210 [[no_unique_address]] Describer m_Describer;
213 template <
typename Action>
222 )
noexcept(std::is_nothrow_move_constructible_v<Action>)
223 : m_Action{std::move(action)}
239 template <
typename Return,
typename... Args>
252 template <
typename Return,
typename... Args>
253 requires std::invocable<Action&,
const call::Info<Return, Args...>&>
256 )
noexcept(std::is_nothrow_invocable_v<Action&,
const call::Info<Return, Args...>&>)
258 std::invoke(m_Action, info);
265 template <
typename Action,
template <
typename>
typename Projection>
266 requires std::same_as<Action, std::remove_cvref_t<Action>>
273 )
noexcept(std::is_nothrow_move_constructible_v<Action>)
274 : m_Action{std::move(action)}
278 template <
typename Arg>
281 template <
typename Return,
typename... Args>
282 requires std::invocable<
288 std::is_nothrow_invocable_v<
294 "Projection can not be applied.");
297 [
this](
auto&... args) ->
decltype(
auto)
311 template <
typename Action,
template <
typename>
typename Projection, std::size_t... indices>
312 requires std::same_as<Action, std::remove_cvref_t<Action>>
319 )
noexcept(std::is_nothrow_move_constructible_v<Action>)
320 : m_Action{std::move(action)}
324 template <std::size_t index,
typename... Args>
327 template <std::size_t index,
typename... Args>
330 template <
typename Return,
typename... Args>
331 requires (... && (indices <
sizeof...(Args)))
338 std::is_nothrow_invocable_v<
347 "Projection can not be applied.");
352 std::get<indices>(callInfo.args).get())...);
356 [[no_unique_address]] Action m_Action;
364 template <std::
size_t index>
365 struct arg_requirement_describer
372 return format::format(
373 "expect: arg[{}] {}",
403 template <std::
size_t index,
typename Matcher,
typename Projection = std::
identity>
407 Projection projection = {}
409 std::is_nothrow_constructible_v<std::remove_cvref_t<Matcher>, Matcher>
410 && std::is_nothrow_move_constructible_v<Projection>)
414 std::add_lvalue_reference_t,
417 std::remove_cvref_t<Matcher>,
419 detail::arg_requirement_describer<index>>;
422 std::forward<Matcher>(matcher),
423 ProjectionT{std::move(projection)}
465 template <
typename Fun>
466 requires std::invocable<std::remove_cvref_t<Fun>&>
467 && (!std::is_void_v<std::invoke_result_t<std::remove_cvref_t<Fun>&>>)
471 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Fun>, Fun>)
475 fn = std::forward<Fun>(fun)
476 ]([[maybe_unused]]
const auto& call)
mutable noexcept(std::is_nothrow_invocable_v<
decltype(fun)>) ->
decltype(
auto)
478 return std::invoke(fn);
500 template <
typename T>
501 requires std::copyable<std::remove_cvref_t<T>>
505 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<T>, T>)
508 [v = std::forward<T>(value)]([[maybe_unused]]
const auto& call)
mutable noexcept ->
auto& {
509 return static_cast<std::unwrap_reference_t<decltype(v)
>&>(v);
526 template <std::size_t index, std::size_t... otherIndices,
typename Action>
530 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
533 std::remove_cvref_t<Action>,
534 std::add_lvalue_reference_t,
539 ActionT{std::forward<Action>(action)}
553 template <
typename Action>
557 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
560 std::remove_cvref_t<Action>,
561 std::add_lvalue_reference_t>;
564 ActionT{std::forward<Action>(action)}
575 template <std::
size_t index>
581 std::add_rvalue_reference_t,
598 template <
typename T>
599 requires std::copyable<std::remove_cvref_t<T>>
603 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<T>, T>)
606 std::forward<T>(exception)
647 template <std::
size_t index,
typename Action>
651 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
654 std::remove_cvref_t<Action>,
655 std::add_lvalue_reference_t,
659 ActionT{std::forward<Action>(action)}
673 template <std::size_t index, std::size_t... additionalIndices,
typename Action>
677 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
680 std::remove_cvref_t<Action>,
681 std::add_lvalue_reference_t,
683 additionalIndices...>;
686 ActionT{std::forward<Action>(action)}
696 template <
typename Action>
700 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
703 std::remove_cvref_t<Action>,
704 std::add_lvalue_reference_t>;
707 ActionT{std::forward<Action>(action)}
717 template <std::invocable Action>
721 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Action>, Action>)
725 fn = std::forward<Action>(action)
726 ]([[maybe_unused]]
const auto& call)
mutable noexcept(std::is_nothrow_invocable_v<Action&>)
Definition ExpectationPolicies.hpp:268
constexpr decltype(auto) operator()(const call::Info< Return, Args... > &callInfo) const noexcept(std::is_nothrow_invocable_v< const Action &, ProjectedArgT< Args >... >)
Definition ExpectationPolicies.hpp:285
constexpr ApplyAllArgsAction(Action action={}) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:271
Projection< Arg > ProjectedArgT
Definition ExpectationPolicies.hpp:279
Definition ExpectationPolicies.hpp:314
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:335
std::tuple_element_t< index, std::tuple< Args... > > ArgListElementT
Definition ExpectationPolicies.hpp:325
constexpr ApplyArgsAction(Action action={}) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:317
Projection< ArgListElementT< index, Args... > > ProjectedArgListElementT
Definition ExpectationPolicies.hpp:328
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:158
static constexpr void consume(const call::Info< Return, Args... > &info) noexcept
Definition ExpectationPolicies.hpp:195
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:175
constexpr bool matches(const call::Info< Return, Args... > &info) const
Definition ExpectationPolicies.hpp:186
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:161
StringT describe() const
Definition ExpectationPolicies.hpp:200
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:110
constexpr ReturnsResultOf(Action &&action) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:97
Definition ExpectationPolicies.hpp:215
static constexpr bool matches(const call::Info< Return, Args... > &) noexcept
Definition ExpectationPolicies.hpp:241
static std::nullopt_t describe() noexcept
Definition ExpectationPolicies.hpp:247
~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:254
SideEffectAction & operator=(const SideEffectAction &)=delete
static constexpr bool is_satisfied() noexcept
Definition ExpectationPolicies.hpp:234
SideEffectAction(SideEffectAction &&)=default
constexpr SideEffectAction(Action &&action) noexcept(std::is_nothrow_move_constructible_v< Action >)
Definition ExpectationPolicies.hpp:220
SideEffectAction(const SideEffectAction &)=delete
Definition ExpectationPolicies.hpp:130
constexpr Return finalize_call(const call::Info< Return, Args... > &call)
Definition ExpectationPolicies.hpp:139
constexpr Throws(Exception exception) noexcept(std::is_nothrow_move_constructible_v< Exception >)
Definition ExpectationPolicies.hpp:133
Definition Utility.hpp:53
Definition Matcher.hpp:116
Definition Utility.hpp:60
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:555
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:528
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:503
constexpr auto returns_arg() noexcept
During the finalization step, the selected call argument is returned.
Definition ExpectationPolicies.hpp:577
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:469
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:405
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:698
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:649
constexpr auto invoke(Action &&action) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< Action >, Action >)
Invokes the given function.
Definition ExpectationPolicies.hpp:719
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:675
Definition ControlPolicy.hpp:266
Definition ExpectationPolicies.hpp:20
Definition ExpectationPolicies.hpp:433
Definition ExpectationPolicies.hpp:618
constexpr bool is_matching(const Constness lhs, const Constness rhs) noexcept
Definition Utility.hpp:111
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:208
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:207