1
//! The Turbo Vision message box: 40x9 centred, taller for long text.
2

            
3
use super::*;
4

            
5
const YES_NO: [Button<'static>; 2] = [
6
    Button {
7
        label: "~Y~es",
8
        default: true,
9
    },
10
    Button {
11
        label: "~N~o",
12
        default: false,
13
    },
14
];
15

            
16
const SCREEN: Rect = Rect::new(0, 0, 80, 24);
17

            
18
#[test]
19
1
fn a_short_message_is_forty_by_nine_in_the_middle() {
20
1
    let area = Dialog::message_box(10, &YES_NO, SCREEN);
21
1
    assert_eq!(area, Rect::new(20, 7, 40, 9));
22
1
}
23

            
24
#[test]
25
1
fn the_text_fills_the_rows_up_to_ninety_nine_characters() {
26
1
    assert_eq!(Dialog::message_box(99, &YES_NO, SCREEN).height, 9);
27
1
}
28

            
29
#[test]
30
1
fn long_text_grows_the_height_by_the_turbo_vision_rule() {
31
1
    let area = Dialog::message_box(100, &YES_NO, SCREEN);
32
1
    assert_eq!(area.height, 100 / 33 + 7);
33
1
    assert_eq!(area.width, 40);
34
1
    assert_eq!(area.y, (SCREEN.height - area.height) / 2);
35
1
}
36

            
37
#[test]
38
1
fn a_tiny_screen_caps_the_box() {
39
1
    let tiny = Rect::new(2, 3, 20, 6);
40
1
    assert_eq!(Dialog::message_box(500, &YES_NO, tiny), tiny);
41
1
}
42

            
43
#[test]
44
1
fn four_buttons_widen_the_box_past_forty() {
45
1
    let button = Button {
46
1
        label: "~X~",
47
1
        default: false,
48
1
    };
49
1
    let four = [button; 4];
50
1
    let area = Dialog::message_box(5, &four, SCREEN);
51
1
    assert_eq!(area.width, Dialog::min_size(&four, ButtonRow::Centred).0);
52
1
    assert!(area.width > 40);
53
1
}
54

            
55
#[test]
56
1
fn the_text_area_is_inset_three_from_the_left_and_two_rows_down() {
57
1
    let area = Dialog::message_box(10, &YES_NO, SCREEN);
58
1
    assert_eq!(
59
1
        Dialog::message_area(area),
60
1
        Rect::new(area.x + 3, area.y + 2, 35, 4)
61
    );
62
1
}
63

            
64
#[test]
65
1
fn the_buttons_are_centred_two_rows_above_the_bottom_frame() {
66
1
    let area = Dialog::message_box(10, &YES_NO, SCREEN);
67
1
    let cells = Dialog::button_areas(area, &YES_NO, ButtonRow::Centred);
68
1
    assert_eq!(cells[0].x, area.x + 9);
69
1
    assert_eq!(cells[0].y, area.y + area.height - 3);
70
1
}