use pretty_assertions::assert_eq;
use super::{ships_nerd_font, TerminalEnv};
fn env(vars: &[(&str, &str)]) -> TerminalEnv {
TerminalEnv::from_vars(|name| {
vars.iter()
.find(|(key, _)| *key == name)
.map(|(_, value)| (*value).to_owned())
})
}
#[test]
fn auto_icons_follow_the_terminal_that_draws() {
let plain = env(&[("TERM", "xterm-256color")]);
let ghostty = env(&[
("TERM_PROGRAM", "ghostty"),
("TERM_PROGRAM_VERSION", "1.2.3"),
("TERM", "xterm-ghostty"),
]);
let wezterm = |version| {
env(&[
("TERM_PROGRAM", "WezTerm"),
("TERM_PROGRAM_VERSION", version),
])
};
let kitty = env(&[("TERM", "xterm-kitty")]);
let cases: &[(&str, TerminalEnv, Option<&str>, bool)] = &[
("ghostty by env", ghostty.clone(), None, true),
(
"wezterm since 2022-03-19",
wezterm("20220319-142410-0fcdea07"),
None,
true,
),
(
"wezterm before",
wezterm("20220101-133340-7edc5b5a"),
None,
false,
),
(
"wezterm without a version",
env(&[("TERM_PROGRAM", "WezTerm")]),
None,
false,
),
(
"rho-ui by env",
env(&[("TERM_PROGRAM", "rho-ui")]),
None,
true,
),
("kitty by env alone", kitty.clone(), None, false),
("kitty 0.36 by reply", kitty, Some("kitty(0.36.0)"), true),
(
"kitty 0.35 by reply",
plain.clone(),
Some("kitty(0.35.2)"),
false,
),
(
"ghostty by reply over ssh",
plain.clone(),
Some("ghostty 1.1.3"),
true,
),
(
"wezterm by reply",
plain.clone(),
Some("WezTerm 20240203-110809-5046fc22"),
true,
),
("rho-ui by reply", plain.clone(), Some("rho-ui 0.5.0"), true),
(
"the reply names another terminal",
ghostty.clone(),
Some("XTerm(390)"),
false,
),
(
"tmux answers for the terminal",
ghostty,
Some("tmux 3.4"),
false,
),
(
"inside tmux",
env(&[
("TERM_PROGRAM", "ghostty"),
("TMUX", "/tmp/tmux-1000/default,1,0"),
]),
None,
false,
),
(
"inside screen",
env(&[("TERM_PROGRAM", "ghostty"), ("STY", "1.pts-0")]),
None,
false,
),
(
"screen's TERM",
env(&[("TERM_PROGRAM", "ghostty"), ("TERM", "screen-256color")]),
None,
false,
),
("an unknown terminal", plain, None, false),
];
for (name, env, reply, expected) in cases {
assert_eq!(ships_nerd_font(env, *reply), *expected, "{name}");
}
}