Lines
100 %
Functions
Branches
//! The Turbo Vision message box: 40x9 centred, taller for long text.
use super::*;
const YES_NO: [Button<'static>; 2] = [
Button {
label: "~Y~es",
default: true,
},
label: "~N~o",
default: false,
];
const SCREEN: Rect = Rect::new(0, 0, 80, 24);
#[test]
fn a_short_message_is_forty_by_nine_in_the_middle() {
let area = Dialog::message_box(10, &YES_NO, SCREEN);
assert_eq!(area, Rect::new(20, 7, 40, 9));
}
fn the_text_fills_the_rows_up_to_ninety_nine_characters() {
assert_eq!(Dialog::message_box(99, &YES_NO, SCREEN).height, 9);
fn long_text_grows_the_height_by_the_turbo_vision_rule() {
let area = Dialog::message_box(100, &YES_NO, SCREEN);
assert_eq!(area.height, 100 / 33 + 7);
assert_eq!(area.width, 40);
assert_eq!(area.y, (SCREEN.height - area.height) / 2);
fn a_tiny_screen_caps_the_box() {
let tiny = Rect::new(2, 3, 20, 6);
assert_eq!(Dialog::message_box(500, &YES_NO, tiny), tiny);
fn four_buttons_widen_the_box_past_forty() {
let button = Button {
label: "~X~",
};
let four = [button; 4];
let area = Dialog::message_box(5, &four, SCREEN);
assert_eq!(area.width, Dialog::min_size(&four, ButtonRow::Centred).0);
assert!(area.width > 40);
fn the_text_area_is_inset_three_from_the_left_and_two_rows_down() {
assert_eq!(
Dialog::message_area(area),
Rect::new(area.x + 3, area.y + 2, 35, 4)
);
fn the_buttons_are_centred_two_rows_above_the_bottom_frame() {
let cells = Dialog::button_areas(area, &YES_NO, ButtonRow::Centred);
assert_eq!(cells[0].x, area.x + 9);
assert_eq!(cells[0].y, area.y + area.height - 3);