scamper/testing

Test helpers for scamper FSMs.

Provides convenience functions for testing state machine behavior. These functions use let assert which panics on failure — they are designed for test code only, not for library or application code.

Values

pub fn assert_final(
  machine: scamper.Machine(state, context, event),
) -> scamper.Machine(state, context, event)

Assert that the machine is in a final state. Panics if the machine is not in a final state. Returns the machine for chaining.

pub fn assert_transition(
  machine: scamper.Machine(state, context, event),
  event: event,
  expected_state: state,
) -> scamper.Machine(state, context, event)

Attempt a transition and assert the machine reaches the expected state. Panics if the transition fails or the machine is not in the expected state. Returns the new machine for chaining.

pub fn reachable_states(
  config: config.Config(state, context, event),
  initial_state: state,
) -> List(state)

Find all states reachable from the initial state via transition rules. Delegates to validation.reachable_states.

pub fn run_events(
  machine: scamper.Machine(state, context, event),
  events: List(event),
) -> Result(
  scamper.Machine(state, context, event),
  error.TransitionError(state, event),
)

Run a sequence of events against the machine. Returns the final machine if all transitions succeed, or the first TransitionError encountered.

Search Document