1
use super::*;
2

            
3
const PRESETS: [&str; 2] = ["dn", "turbo"];
4

            
5
3
fn drawn(preset: &str, width: u16) -> (Buffer, Theme) {
6
3
    let theme = Theme::preset(preset).expect("the preset parses");
7
3
    let mut buf = Buffer::empty(Rect::new(0, 0, width, 1));
8
3
    History::new(&theme).render(buf.area, &mut buf);
9
3
    (buf, theme)
10
3
}
11

            
12
10
fn cell(
13
10
    buf: &Buffer,
14
10
    x: u16,
15
10
) -> (
16
10
    String,
17
10
    Option<ratatui::style::Color>,
18
10
    Option<ratatui::style::Color>,
19
10
) {
20
10
    let cell = &buf[(x, 0)];
21
10
    (cell.symbol().to_string(), cell.style().fg, cell.style().bg)
22
10
}
23

            
24
#[test]
25
1
fn the_mark_is_three_cells_at_the_end_in_the_history_roles() {
26
1
    for preset in PRESETS {
27
2
        let (buf, theme) = drawn(preset, 10);
28
2
        for (x, glyph, role) in [
29
2
            (7, "▐", Role::History),
30
2
            (8, "↓", Role::HistoryArrow),
31
2
            (9, "▌", Role::History),
32
2
        ] {
33
6
            let style = theme.style(role);
34
6
            assert_eq!(
35
6
                cell(&buf, x),
36
6
                (glyph.into(), style.fg, style.bg),
37
                "{preset} {x}"
38
            );
39
        }
40
2
        assert_eq!(cell(&buf, 6).0, " ", "{preset}");
41
    }
42
1
}
43

            
44
#[test]
45
1
fn an_area_narrower_than_the_mark_gets_none() {
46
1
    let (buf, _) = drawn("dn", 2);
47
1
    assert_eq!(cell(&buf, 0).0, " ");
48
1
    assert_eq!(cell(&buf, 1).0, " ");
49
1
    assert!(History::area(Rect::new(4, 2, 2, 1)).is_empty());
50
1
}
51

            
52
#[test]
53
1
fn the_area_of_the_mark_is_its_cells_at_the_end_of_the_field() {
54
1
    let field = Rect::new(5, 3, 20, 1);
55
1
    assert_eq!(History::area(field), Rect::new(22, 3, HISTORY_CELLS, 1));
56
1
}