Lines
100 %
Functions
Branches
use super::*;
use tvui::ColorDepth;
#[test]
fn chart_backends_map_to_image_backends() {
assert_eq!(
image_backend(ChartBackend::Kitty, 7),
ImageBackend::Kitty { id: 7 }
);
image_backend(ChartBackend::Halfblocks, 7),
ImageBackend::HalfBlocks
}
fn env() -> TerminalEnv {
TerminalEnv {
screen: Size::new(80, 24),
cell_pixels: (10, 20),
backend: ChartBackend::Halfblocks,
fn a_bad_image_names_the_chart_in_its_error() {
let env = env();
let err = Picture::new(b"nope".to_vec(), Size::new(4, 2), env, 1).err();
assert!(
err.is_some_and(|text| text.starts_with("the chart is not a PNG: ")),
"error text"
fn a_pane_without_cells_says_it_has_no_room() {
let err = Picture::new(b"nope".to_vec(), Size::new(0, 2), env(), 1).err();
assert_eq!(err.as_deref(), Some("the chart pane has no room"));
fn each_window_has_its_own_kitty_id() {
let ids: Vec<u32> = [0, 1, 2, u32::MAX]
.into_iter()
.map(|window| kitty_image_id(WindowId(window)))
.collect();
let distinct: std::collections::HashSet<_> = ids.iter().collect();
assert_eq!(distinct.len(), ids.len());
fn a_pane_is_requested_at_its_exact_pixels_with_glyph_high_text() {
assert_eq!(env().fit(Size::new(40, 10)), ((400, 200), 14));
fn glyph_text_is_seventy_percent_of_the_cell_with_a_floor() {
let sizes: Vec<u32> = [10, 15, 16, 20, 30].into_iter().map(glyph_px).collect();
assert_eq!(sizes, [8, 11, 11, 14, 21]);
fn an_oversized_pane_shrinks_in_both_sides_and_the_text() {
let env = TerminalEnv {
cell_pixels: (30, 60),
..env()
};
let ((width, height), text) = env.fit(Size::new(100, 25));
assert_eq!((width, height, text), (2048, 1024, 28));
fn the_look_is_the_panel_colour_of_the_theme_at_every_depth() {
let expected = [
(ColorDepth::Rgb, [0x00, 0x00, 0xaa]),
(ColorDepth::Indexed256, [0x00, 0x00, 0xaf]),
(ColorDepth::Ansi16, [0x00, 0x00, 0xaa]),
];
for (depth, rgb) in expected {
let turbo = Theme::preset("turbo").expect("preset").with_depth(depth);
let drawn = look(20, &turbo);
assert_eq!(drawn.text_px, 20);
assert_eq!(drawn.background, Some(rgb), "{depth:?}");
let dn = Theme::preset("dn").expect("preset");
assert_eq!(look(9, &dn).background, Some([0x55, 0x55, 0x55]));
let dn16 = dn.clone().with_depth(ColorDepth::Ansi16);
assert_eq!(look(9, &dn16).background, Some([0, 0, 0]));
let dn256 = dn.with_depth(ColorDepth::Indexed256);
assert_eq!(look(9, &dn256).background, Some([0x58, 0x58, 0x58]));