Lines
100 %
Functions
Branches
use super::*;
fn theme() -> Theme {
Theme::preset("dn").expect("the dn preset parses")
}
fn drawn(items: &[(String, String)], width: u16) -> Buffer {
let area = Rect::new(0, 0, width, 1);
let mut buf = Buffer::empty(area);
StatusBar::new(&theme(), items).render(area, &mut buf);
buf
fn row(buf: &Buffer) -> String {
(0..buf.area.width)
.map(|x| buf[(x, 0)].symbol().to_string())
.collect()
fn items() -> Vec<(String, String)> {
Vec::from([
("F1".to_string(), "Help".to_string()),
("M-x".to_string(), "Exit".to_string()),
])
#[test]
fn items_are_key_then_label_two_spaces_apart() {
assert_eq!(row(&drawn(&items(), 24)), " F1 Help M-x Exit ");
fn the_key_has_its_own_role_and_the_rest_the_status_one() {
let theme = theme();
let buf = drawn(&items(), 24);
assert_eq!(buf[(1, 0)].style().fg, theme.style(Role::StatusHotkey).fg);
assert_eq!(buf[(2, 0)].style().fg, theme.style(Role::StatusHotkey).fg);
assert_eq!(buf[(4, 0)].style().fg, theme.style(Role::Status).fg);
assert_eq!(buf[(23, 0)].style().bg, theme.style(Role::Status).bg);
fn an_item_that_does_not_fit_is_left_out_whole() {
assert_eq!(row(&drawn(&items(), 12)), " F1 Help ");
assert_eq!(row(&drawn(&items(), 18)), " F1 Help M-x Exit");
fn a_later_shorter_item_shows_when_one_before_it_does_not_fit() {
let mut items = items();
items.insert(1, ("C-o".to_string(), "Suggest".to_string()));
assert_eq!(row(&drawn(&items, 20)), " F1 Help M-x Exit ");
fn no_items_leave_the_filled_row() {
let buf = drawn(&[], 5);
assert_eq!(row(&buf), " ");
assert_eq!(buf[(0, 0)].style().bg, theme().style(Role::Status).bg);
fn areas(items: &[(String, String)], width: u16) -> Vec<(usize, Rect)> {
StatusBar::item_areas(Rect::new(3, 2, width, 1), items)
fn item_areas_cover_the_drawn_key_and_label() {
let found = areas(&items(), 24);
assert_eq!(
found,
Vec::from([(0, Rect::new(4, 2, 7, 1)), (1, Rect::new(13, 2, 8, 1))])
);
let text = |rect: Rect| -> String {
(rect.x - 3..rect.right() - 3)
};
assert_eq!(text(found[0].1), "F1 Help");
assert_eq!(text(found[1].1), "M-x Exit");
fn item_areas_skip_what_the_bar_leaves_out() {
let indexes: Vec<usize> = areas(&items, 20).iter().map(|(index, _)| *index).collect();
assert_eq!(indexes, Vec::from([0, 2]));
assert!(areas(&[], 5).is_empty());