pub struct TestBackend { /* private fields */ }Expand description
Headless rendering backend for tests.
Renders a UI closure to an in-memory Buffer without a real terminal.
Use render to run one frame, then inspect the
output with line, assert_contains,
or to_string_trimmed.
§Example
use slt::TestBackend;
let mut backend = TestBackend::new(40, 10);
backend.render(|ui| {
ui.text("hello");
});
backend.assert_contains("hello");Implementations§
Source§impl TestBackend
impl TestBackend
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Create a test backend with the given terminal dimensions.
Sourcepub fn render(&mut self, f: impl FnOnce(&mut Context))
pub fn render(&mut self, f: impl FnOnce(&mut Context))
Run a UI closure for one frame and render to the internal buffer.
Sourcepub fn render_with_events(
&mut self,
events: Vec<Event>,
focus_index: usize,
prev_focus_count: usize,
f: impl FnOnce(&mut Context),
)
pub fn render_with_events( &mut self, events: Vec<Event>, focus_index: usize, prev_focus_count: usize, f: impl FnOnce(&mut Context), )
Render with injected events and focus state for interaction testing.
Sourcepub fn run_with_events(
&mut self,
events: Vec<Event>,
f: impl FnOnce(&mut Context),
)
pub fn run_with_events( &mut self, events: Vec<Event>, f: impl FnOnce(&mut Context), )
Convenience wrapper: render with events using default focus state.
Sourcepub fn line(&self, y: u32) -> String
pub fn line(&self, y: u32) -> String
Get the rendered text content of row y (trimmed trailing spaces)
Sourcepub fn assert_line(&self, y: u32, expected: &str)
pub fn assert_line(&self, y: u32, expected: &str)
Assert that row y contains expected as a substring
Sourcepub fn assert_line_contains(&self, y: u32, expected: &str)
pub fn assert_line_contains(&self, y: u32, expected: &str)
Assert that row y contains expected as a substring
Sourcepub fn assert_contains(&self, expected: &str)
pub fn assert_contains(&self, expected: &str)
Assert that any line in the buffer contains expected
Sourcepub fn to_string_trimmed(&self) -> String
pub fn to_string_trimmed(&self) -> String
Return the full rendered buffer as a multi-line string.
Each row is trimmed of trailing spaces and joined with newlines.
Useful for snapshot testing with insta::assert_snapshot!.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TestBackend
impl !RefUnwindSafe for TestBackend
impl !Send for TestBackend
impl !Sync for TestBackend
impl Unpin for TestBackend
impl UnsafeUnpin for TestBackend
impl !UnwindSafe for TestBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more