1
use super::backend::{ChartBackend, chart_backend, env_speaks_kitty, term_speaks_kitty};
2

            
3
#[test]
4
1
fn backend_follows_term_and_override() {
5
    use ChartBackend::{Halfblocks, Kitty};
6
1
    let cases = [
7
1
        (None, None, Halfblocks),
8
1
        (Some("xterm-256color"), None, Halfblocks),
9
1
        (Some("xterm-kitty"), None, Kitty),
10
1
        (Some("XTERM-KITTY"), None, Kitty),
11
1
        (Some("xterm-ghostty"), None, Kitty),
12
1
        (Some("ghostty"), None, Kitty),
13
1
        (Some("xterm-kitty"), Some("halfblocks"), Halfblocks),
14
1
        (Some("xterm-256color"), Some("kitty"), Kitty),
15
1
        (None, Some("Kitty"), Kitty),
16
1
        (Some("xterm-kitty"), Some("sixel"), Kitty),
17
1
        (Some("xterm-256color"), Some(""), Halfblocks),
18
1
    ];
19
1
    for (term, over, want) in cases {
20
11
        assert_eq!(chart_backend(term, over), want, "{term:?} {over:?}");
21
    }
22
1
}
23

            
24
#[test]
25
1
fn term_detector_is_case_insensitive() {
26
1
    assert!(term_speaks_kitty("Kitty"));
27
1
    assert!(!term_speaks_kitty("screen"));
28
1
}
29

            
30
#[test]
31
1
fn env_detector_takes_the_union_of_the_rules() {
32
1
    let cases: [(&[(&str, &str)], bool); 11] = [
33
1
        (&[], false),
34
1
        (&[("TERM", "xterm-256color")], false),
35
1
        (&[("KITTY_WINDOW_ID", "1")], true),
36
1
        (&[("TERM", "xterm-kitty")], true),
37
1
        (&[("TERM", "xterm-ghostty")], true),
38
1
        (&[("TERM_PROGRAM", "kitty")], true),
39
1
        (&[("TERM_PROGRAM", "ghostty")], true),
40
1
        (&[("TERM_PROGRAM", "WezTerm")], true),
41
1
        (&[("TERM_PROGRAM", "wezterm")], true),
42
1
        (&[("TERM_PROGRAM", "Apple_Terminal")], false),
43
1
        (&[("TERM", "screen"), ("TERM_PROGRAM", "tmux")], false),
44
1
    ];
45
1
    for (vars, want) in cases {
46
35
        let lookup = |name: &str| {
47
35
            vars.iter()
48
34
                .find(|(key, _)| *key == name)
49
15
                .map(|(_, value)| (*value).to_string())
50
35
        };
51
11
        assert_eq!(env_speaks_kitty(lookup), want, "{vars:?}");
52
    }
53
1
}