1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Testing models headless.
//!
//! [`TestProgram`] runs a model in the real runtime on a virtual clock,
//! in an emulated terminal: send it keys, bytes, messages, resizes and
//! signals, move time on, and read the screen a terminal would show
//! ([`Vt`]), the bytes written, or the model. Every run is the same:
//! timers, the frame rate and the escape timeout follow the virtual
//! clock, and task results arrive in the order the tasks started. It is
//! the counterpart of Bubble Tea's teatest, with
//! [`assert_golden`] for golden files.
//!
//! [`TestBackend`] is the simpler, older way: a [`Backend`](crate::Backend)
//! that plays scripted input on the real clock, for
//! [`Program::run_with`](crate::Program::run_with).
//!
//! ```
//! use petitcarnets as tea;
//! use tea::testing::TestProgram;
//!
//! struct Echo(String);
//!
//! impl tea::Model for Echo {
//! type Msg = ();
//!
//! fn update(&mut self, msg: tea::Msg<()>) -> tea::Cmd<()> {
//! match msg {
//! tea::Msg::KeyPress(key) if key == "enter" => return tea::quit(),
//! tea::Msg::KeyPress(key) => self.0.push_str(&key.text),
//! _ => {}
//! }
//! tea::Cmd::none()
//! }
//!
//! fn view(&self) -> tea::View {
//! format!("> {}", self.0).into()
//! }
//! }
//!
//! let mut test = TestProgram::new(Echo(String::new()), 20, 2);
//! test.type_text("hi");
//! assert_eq!(test.screen().text(), "> hi");
//! test.press(tea::Key::new(tea::KeyCode::Enter));
//! assert_eq!(test.final_model().0, "hi");
//! ```
pub use crate;
pub use ;
pub use TestProgram;
pub use TestTerminal;
pub use ;