1
use super::*;
2
use tvui::ColorDepth;
3

            
4
#[test]
5
1
fn chart_backends_map_to_image_backends() {
6
1
    assert_eq!(
7
1
        image_backend(ChartBackend::Kitty, 7),
8
1
        ImageBackend::Kitty { id: 7 }
9
    );
10
1
    assert_eq!(
11
1
        image_backend(ChartBackend::Halfblocks, 7),
12
1
        ImageBackend::HalfBlocks
13
    );
14
1
}
15

            
16
4
fn env() -> TerminalEnv {
17
4
    TerminalEnv {
18
4
        screen: Size::new(80, 24),
19
4
        cell_pixels: (10, 20),
20
4
        backend: ChartBackend::Halfblocks,
21
4
    }
22
4
}
23

            
24
#[test]
25
1
fn a_bad_image_names_the_chart_in_its_error() {
26
1
    let env = env();
27
1
    let err = Picture::new(b"nope".to_vec(), Size::new(4, 2), env, 1).err();
28
1
    assert!(
29
1
        err.is_some_and(|text| text.starts_with("the chart is not a PNG: ")),
30
        "error text"
31
    );
32
1
}
33

            
34
#[test]
35
1
fn a_pane_without_cells_says_it_has_no_room() {
36
1
    let err = Picture::new(b"nope".to_vec(), Size::new(0, 2), env(), 1).err();
37
1
    assert_eq!(err.as_deref(), Some("the chart pane has no room"));
38
1
}
39

            
40
#[test]
41
1
fn each_window_has_its_own_kitty_id() {
42
1
    let ids: Vec<u32> = [0, 1, 2, u32::MAX]
43
1
        .into_iter()
44
4
        .map(|window| kitty_image_id(WindowId(window)))
45
        .collect();
46
1
    let distinct: std::collections::HashSet<_> = ids.iter().collect();
47
1
    assert_eq!(distinct.len(), ids.len());
48
1
}
49

            
50
#[test]
51
1
fn a_pane_is_requested_at_its_exact_pixels_with_glyph_high_text() {
52
1
    assert_eq!(env().fit(Size::new(40, 10)), ((400, 200), 14));
53
1
}
54

            
55
#[test]
56
1
fn glyph_text_is_seventy_percent_of_the_cell_with_a_floor() {
57
1
    let sizes: Vec<u32> = [10, 15, 16, 20, 30].into_iter().map(glyph_px).collect();
58
1
    assert_eq!(sizes, [8, 11, 11, 14, 21]);
59
1
}
60

            
61
#[test]
62
1
fn an_oversized_pane_shrinks_in_both_sides_and_the_text() {
63
1
    let env = TerminalEnv {
64
1
        cell_pixels: (30, 60),
65
1
        ..env()
66
1
    };
67
1
    let ((width, height), text) = env.fit(Size::new(100, 25));
68
1
    assert_eq!((width, height, text), (2048, 1024, 28));
69
1
}
70

            
71
#[test]
72
1
fn the_look_is_the_panel_colour_of_the_theme_at_every_depth() {
73
1
    let expected = [
74
1
        (ColorDepth::Rgb, [0x00, 0x00, 0xaa]),
75
1
        (ColorDepth::Indexed256, [0x00, 0x00, 0xaf]),
76
1
        (ColorDepth::Ansi16, [0x00, 0x00, 0xaa]),
77
1
    ];
78
1
    for (depth, rgb) in expected {
79
3
        let turbo = Theme::preset("turbo").expect("preset").with_depth(depth);
80
3
        let drawn = look(20, &turbo);
81
3
        assert_eq!(drawn.text_px, 20);
82
3
        assert_eq!(drawn.background, Some(rgb), "{depth:?}");
83
    }
84
1
    let dn = Theme::preset("dn").expect("preset");
85
1
    assert_eq!(look(9, &dn).background, Some([0x55, 0x55, 0x55]));
86
1
    let dn16 = dn.clone().with_depth(ColorDepth::Ansi16);
87
1
    assert_eq!(look(9, &dn16).background, Some([0, 0, 0]));
88
1
    let dn256 = dn.with_depth(ColorDepth::Indexed256);
89
1
    assert_eq!(look(9, &dn256).background, Some([0x58, 0x58, 0x58]));
90
1
}