pub struct ProgramSimulator<M: Model> { /* private fields */ }Expand description
Deterministic simulator for Model testing.
Runs model logic without any terminal or IO dependencies. Events can be injected, messages sent directly, and frames captured for snapshot testing.
Implementations§
Source§impl<M: Model> ProgramSimulator<M>
impl<M: Model> ProgramSimulator<M>
Sourcepub fn new(model: M) -> Self
pub fn new(model: M) -> Self
Create a new simulator with the given model.
The model is not initialized until init is called.
Sourcepub fn with_registry(model: M, registry: Arc<StateRegistry>) -> Self
pub fn with_registry(model: M, registry: Arc<StateRegistry>) -> Self
Create a new simulator with the given model and persistence registry.
When provided, Cmd::SaveState/Cmd::RestoreState will flush/load
through the registry, mirroring runtime behavior.
Sourcepub fn init(&mut self)
pub fn init(&mut self)
Initialize the model by calling Model::init() and executing returned commands.
Should be called once before injecting events or capturing frames.
Sourcepub fn inject_events(&mut self, events: &[Event])
pub fn inject_events(&mut self, events: &[Event])
Inject terminal events into the model.
Each event is converted to a message via From<Event> and dispatched
through Model::update(). Commands returned from update are executed.
Sourcepub fn inject_event(&mut self, event: Event)
pub fn inject_event(&mut self, event: Event)
Inject a single terminal event into the model.
The event is converted to a message via From<Event> and dispatched
through Model::update(). Commands returned from update are executed.
Sourcepub fn send(&mut self, msg: M::Message)
pub fn send(&mut self, msg: M::Message)
Send a specific message to the model.
The message is dispatched through Model::update() and returned
commands are executed.
Sourcepub fn capture_frame(&mut self, width: u16, height: u16) -> &Buffer
pub fn capture_frame(&mut self, width: u16, height: u16) -> &Buffer
Capture the current frame at the given dimensions.
Calls Model::view() to render into a fresh buffer and stores the
result. Returns a reference to the captured buffer.
Sourcepub fn last_frame(&self) -> Option<&Buffer>
pub fn last_frame(&self) -> Option<&Buffer>
Get the most recently captured frame buffer, if any.
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Get the number of captured frames.
Sourcepub fn pool(&self) -> &GraphemePool
pub fn pool(&self) -> &GraphemePool
Access the simulator grapheme pool used to render captured frames.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the simulated program is still running.
Returns false after a Cmd::Quit has been executed.
Sourcepub fn command_log(&self) -> &[CmdRecord]
pub fn command_log(&self) -> &[CmdRecord]
Get the command execution log.
Sourcepub fn clear_frames(&mut self)
pub fn clear_frames(&mut self)
Clear all captured frames.
Sourcepub fn clear_logs(&mut self)
pub fn clear_logs(&mut self)
Clear all logs.