Skip to main content

Module testing

Module testing 

Source
Expand description

Test utilities for components built with this crate.

Requires feature testing.

§TestTerminal

A virtual terminal buffer that captures writes and parses ANSI escape sequences. Use it to assert on rendered output without a real terminal:

use tui::testing::{TestTerminal, assert_buffer_eq, render_component};
use tui::{Frame, Line, ViewContext};

let terminal = render_component(
    |ctx: &ViewContext| Frame::new(vec![Line::new("hello")]),
    80, 24,
);
assert_buffer_eq(&terminal, &["hello"]);

TestTerminal implements std::io::Write and tracks cursor position, SGR styles, and scrollback — including delayed (DEC-style) wrapping behavior.

§Helper functions

  • render_component(f, width, rows) — Render a closure through a Renderer into a TestTerminal.
  • render_component_with_renderer(f, renderer, width, rows) — Same, but reuse an existing renderer (useful for testing frame diffs).
  • render_lines(lines, width, rows) — Render a slice of Lines into a TestTerminal.
  • key(code) — Create a KeyEvent with no modifiers for test input.
  • sample_options() — Returns a Vec<SelectOption> with three entries (“Alpha”, “Beta”, “Gamma”).
  • assert_buffer_eq(terminal, expected) — Assert that the terminal buffer matches expected row strings.

§Cell

A single cell in the TestTerminal buffer, storing a char and its Style. Access cells through TestTerminal::buffer() for fine-grained style assertions.

Structs§

Cell
A single cell in the terminal buffer, storing both a character and its style.
TestTerminal
A virtual terminal buffer for testing terminal output. Captures all writes, tracks cursor position, and parses ANSI escape sequences including SGR (Select Graphic Rendition) codes for style tracking.

Functions§

assert_buffer_eq
Asserts a test terminal buffer matches the expected output. Each element of the expected vector represents a row. Trailing whitespace is ignored on each line.
cols
key
pad
render_component
render_component_with_renderer
render_lines
sample_options