State for DoubleDown.Double.canonical_handler/5.
Stored inline in HandlerMeta.Stateful.state when Double installs
its canonical stateful handler. Tracks queued expectations,
per-operation stubs, per-operation fakes, and the fallback handler
(function, stateful fake, or module) with its associated state.
Fields
contract— the contract module this state belongs to (never nil)expects—%{operation => [fun | :passthrough]}queued expectationsfakes—%{operation => fun}per-operation stateful fake overridesstubs—%{operation => fun}per-operation stateless stub functionsfallback— the fallback handler, one of:nil— no fallback configured{:stateless, fun}— stateless 3-arity function fallback{:stateful, fun}— 4/5-arity stateful fake function{:module, module}— module implementing the contract behaviour
fallback_state— domain state for stateful fakes (only meaningful whenfallbackis{:stateful, _})
Summary
Functions
Add a single expect entry for an operation.
Add multiple expect entries for an operation (e.g. from times: n).
Create a new canonical handler state for the given contract.
Pop the next expect entry for an operation.
Set a per-operation fake.
Update the fallback_state (used during dispatch).
Set a per-operation stub.
Set a module fallback.
Set a stateful function fallback with initial state.
Set a stateless function fallback.
Check if a stateful fallback is configured.
Types
@type fallback() :: nil | {:stateless, DoubleDown.Contract.Dispatch.Types.stateless_fun()} | {:stateful, DoubleDown.Contract.Dispatch.Types.stateful_fun()} | {:module, module()}
@type t() :: %DoubleDown.Double.CanonicalHandlerState{ contract: module(), expects: %{ required(atom()) => [DoubleDown.Double.Types.expect_fun() | :passthrough] }, fakes: %{required(atom()) => DoubleDown.Double.Types.fake_fun()}, fallback: fallback(), fallback_state: term(), stubs: %{required(atom()) => DoubleDown.Double.Types.stub_fun()} }
Functions
@spec add_expect(t(), atom(), DoubleDown.Double.Types.expect_fun() | :passthrough) :: t()
Add a single expect entry for an operation.
@spec add_expects(t(), atom(), [DoubleDown.Double.Types.expect_fun() | :passthrough]) :: t()
Add multiple expect entries for an operation (e.g. from times: n).
Create a new canonical handler state for the given contract.
@spec pop_expect(t(), atom()) :: {:ok, DoubleDown.Double.Types.expect_fun() | :passthrough, t()} | :none
Pop the next expect entry for an operation.
@spec put_fake(t(), atom(), DoubleDown.Double.Types.fake_fun()) :: t()
Set a per-operation fake.
Update the fallback_state (used during dispatch).
@spec put_stub(t(), atom(), DoubleDown.Double.Types.stub_fun()) :: t()
Set a per-operation stub.
Set a module fallback.
@spec set_stateful_fallback( t(), DoubleDown.Contract.Dispatch.Types.stateful_fun(), term() ) :: t()
Set a stateful function fallback with initial state.
@spec set_stateless_fallback(t(), DoubleDown.Contract.Dispatch.Types.stateless_fun()) :: t()
Set a stateless function fallback.
Check if a stateful fallback is configured.