Lines
100 %
Functions
Branches
use super::*;
use ratatui::style::Modifier;
use ratatui::widgets::Widget;
fn theme() -> Theme {
Theme::preset("dn").expect("the dn preset parses")
}
fn drawn(block: Block, area: Rect) -> Buffer {
let mut buf = Buffer::empty(area);
block.render(area, &mut buf);
buf
fn row(buf: &Buffer, y: u16) -> String {
(0..buf.area.width)
.map(|x| buf[(x, y)].symbol().to_string())
.collect()
#[test]
fn a_dialog_is_double_with_its_own_title_role() {
let theme = theme();
let buf = drawn(
dialog(&theme, "Help", FrameMode::Active),
Rect::new(0, 0, 12, 3),
);
assert_eq!(row(&buf, 0), "╔══ Help ══╗");
assert_eq!(buf[(0, 0)].style().fg, theme.style(Role::DialogFrame).fg);
assert_eq!(buf[(5, 0)].style().fg, theme.style(Role::DialogTitle).fg);
assert_eq!(buf[(1, 1)].style().bg, theme.style(Role::Dialog).bg);
fn a_menu_box_is_single_without_a_title_in_the_menu_colours() {
let buf = drawn(menu_box(&theme), Rect::new(0, 0, 8, 3));
assert_eq!(row(&buf, 0), "┌──────┐");
assert_eq!(row(&buf, 2), "└──────┘");
assert_eq!(buf[(0, 0)].style().fg, theme.style(Role::Menu).fg);
assert_eq!(buf[(1, 1)].style().bg, theme.style(Role::Menu).bg);
fn lettered(width: u16, height: u16) -> Buffer {
let mut buf = Buffer::empty(Rect::new(0, 0, width, height));
for y in 0..height {
for x in 0..width {
buf[(x, y)].set_char('x');
fn shadowed(buf: &Buffer, theme: &Theme) -> Vec<(u16, u16)> {
let style = theme.style(Role::Shadow);
buf.area
.positions()
.filter(|position| buf[*position].style().bg == style.bg)
.map(|position| (position.x, position.y))
fn the_shadow_is_two_columns_right_and_one_row_below() {
let mut buf = lettered(10, 8);
buf[(5, 2)].modifier = Modifier::BOLD;
shadow(&mut buf, Rect::new(1, 1, 4, 3), &theme);
assert_eq!(buf[(5, 2)].modifier, Modifier::empty());
let mut expected = Vec::from([(5, 2), (6, 2), (5, 3), (6, 3), (5, 4), (6, 4)]);
expected.extend((3..=6).map(|x| (x, 4)));
expected.sort_by_key(|&(x, y)| (y, x));
expected.dedup();
let mut found = shadowed(&buf, &theme);
found.sort_by_key(|&(x, y)| (y, x));
assert_eq!(found, expected);
assert_eq!(buf[(5, 2)].symbol(), "x");
assert_eq!(buf[(5, 2)].style().fg, theme.style(Role::Shadow).fg);
fn the_shadow_is_clipped_at_the_buffer_edge() {
let mut buf = lettered(7, 4);
shadow(&mut buf, Rect::new(1, 1, 5, 3), &theme);
assert_eq!(shadowed(&buf, &theme), [(6, 2), (6, 3)]);
fn the_shadow_leaves_kitty_placeholder_cells() {
buf[(5, 2)].set_symbol("\u{10EEEE}\u{305}");
let before = buf[(5, 2)].clone();
assert_eq!(buf[(5, 2)], before);
assert_eq!(buf[(6, 2)].style().bg, theme.style(Role::Shadow).bg);
fn a_dragging_dialog_frame_is_single_line_in_the_icon_role() {
let theme = Theme::preset("dn").expect("preset");
dialog(&theme, "Help", FrameMode::Dragging),
assert_eq!(buf[(0, 0)].symbol(), "┌");
assert_eq!(buf[(0, 0)].style().fg, theme.style(Role::DialogIcon).fg);
assert_eq!(buf[(5, 0)].style().fg, theme.style(Role::DialogIcon).fg);