Lines
100 %
Functions
Branches
use super::*;
const PRESETS: [&str; 2] = ["dn", "turbo"];
fn drawn(preset: &str, width: u16) -> (Buffer, Theme) {
let theme = Theme::preset(preset).expect("the preset parses");
let mut buf = Buffer::empty(Rect::new(0, 0, width, 1));
History::new(&theme).render(buf.area, &mut buf);
(buf, theme)
}
fn cell(
buf: &Buffer,
x: u16,
) -> (
String,
Option<ratatui::style::Color>,
) {
let cell = &buf[(x, 0)];
(cell.symbol().to_string(), cell.style().fg, cell.style().bg)
#[test]
fn the_mark_is_three_cells_at_the_end_in_the_history_roles() {
for preset in PRESETS {
let (buf, theme) = drawn(preset, 10);
for (x, glyph, role) in [
(7, "▐", Role::History),
(8, "↓", Role::HistoryArrow),
(9, "▌", Role::History),
] {
let style = theme.style(role);
assert_eq!(
cell(&buf, x),
(glyph.into(), style.fg, style.bg),
"{preset} {x}"
);
assert_eq!(cell(&buf, 6).0, " ", "{preset}");
fn an_area_narrower_than_the_mark_gets_none() {
let (buf, _) = drawn("dn", 2);
assert_eq!(cell(&buf, 0).0, " ");
assert_eq!(cell(&buf, 1).0, " ");
assert!(History::area(Rect::new(4, 2, 2, 1)).is_empty());
fn the_area_of_the_mark_is_its_cells_at_the_end_of_the_field() {
let field = Rect::new(5, 3, 20, 1);
assert_eq!(History::area(field), Rect::new(22, 3, HISTORY_CELLS, 1));