Skip to main content

TestBackend

Struct TestBackend 

Source
pub struct TestBackend { /* private fields */ }

Implementations§

Source§

impl TestBackend

Source

pub fn new(width: u32, height: u32) -> Self

Source

pub fn render(&mut self, f: impl FnOnce(&mut Context))

Run a closure as if it were one frame, render to internal buffer

Source

pub fn render_with_events( &mut self, events: Vec<Event>, focus_index: usize, prev_focus_count: usize, f: impl FnOnce(&mut Context), )

Render with specific events (for testing keyboard/mouse interaction)

Source

pub fn run_with_events( &mut self, events: Vec<Event>, f: impl FnOnce(&mut Context), )

Source

pub fn line(&self, y: u32) -> String

Get the rendered text content of row y (trimmed trailing spaces)

Source

pub fn assert_line(&self, y: u32, expected: &str)

Assert that row y contains expected as a substring

Source

pub fn assert_line_contains(&self, y: u32, expected: &str)

Assert that row y contains expected as a substring

Source

pub fn assert_contains(&self, expected: &str)

Assert that any line in the buffer contains expected

Source

pub fn buffer(&self) -> &Buffer

Source

pub fn width(&self) -> u32

Source

pub fn height(&self) -> u32

Source

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§

Source§

impl Display for TestBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.