//! Helpers the inline test modules share. //! //! Compiled only for tests, and deliberately without a test module of its own: //! the mutation selector picks a file by the test attribute in it, and test //! helpers are not something to mutate. The modules that use these carry the //! attribute instead. use crate::{Grid, Identity}; use shop_vt::Parser; /// Feed `bytes` through a fresh Parser into `grid`. pub(crate) fn feed(grid: &mut Grid, bytes: &[u8]) { let mut p = Parser::new(); p.advance(grid, bytes); } pub(crate) fn row_str(grid: &Grid, r: u16) -> String { grid.row(r) .iter() .map(crate::Cell::c) .collect::() .trim_end() .to_string() } pub(crate) fn assert_cursor(grid: &Grid, row: u16, col: u16) { let c = grid.cursor(); assert_eq!( (c.row, c.col), (row, col), "cursor mismatch (wrap_next={})", c.wrap_next ); } pub(crate) fn identified() -> Grid { let mut g = Grid::new(80, 24); g.set_identity(Identity { name: "shop".into(), version: "1.2.3".into(), cell_px: (9, 20), fg: [0xe6, 0xde, 0xd3], bg: [0x25, 0x23, 0x1f], }); g } pub(crate) fn reply_to(g: &mut Grid, bytes: &[u8]) -> String { feed(g, bytes); String::from_utf8(g.take_pending_replies()).unwrap() } /// Everything in scrollback, as text. The round-trip property is stated /// over this rather than over rows, because the rows are exactly what a /// rewrap is allowed to change. pub(crate) fn history_text(g: &Grid) -> String { g.text_range(0, g.history_len()) }