1
use super::*;
2

            
3
#[test]
4
1
fn the_last_page_starts_where_the_rows_fill_the_view() {
5
1
    assert_eq!(RowWindow::last_top(30, 8), 22);
6
1
    assert_eq!(RowWindow::last_top(5, 8), 0);
7
1
}
8

            
9
#[test]
10
1
fn fit_pulls_the_top_back_inside_the_last_page_and_records_the_view() {
11
1
    let window = RowWindow::default();
12
1
    window.set_top(25);
13
1
    assert_eq!(window.fit(30, 8), 22);
14
1
    assert_eq!(window.top(), 22);
15
1
    assert_eq!(window.rows(), 8);
16
1
    assert_eq!(window.fit(3, 8), 0);
17
1
}
18

            
19
#[test]
20
1
fn nothing_scrolls_before_the_first_draw() {
21
1
    let window = RowWindow::default();
22
1
    window.scroll_down(5);
23
1
    window.to_end();
24
1
    assert_eq!(window.top(), 0);
25
1
}
26

            
27
#[test]
28
1
fn scrolling_down_stops_at_the_last_page_and_up_at_the_first_row() {
29
1
    let window = RowWindow::default();
30
1
    let _ = window.fit(30, 8);
31
1
    window.scroll_up(3);
32
1
    assert_eq!(window.top(), 0);
33
1
    for _ in 0..5 {
34
5
        window.page_down();
35
    }
36
1
    assert_eq!(window.top(), 22);
37
1
    window.page_up();
38
1
    assert_eq!(window.top(), 14);
39
1
    window.to_end();
40
1
    assert_eq!(window.top(), 22);
41
1
    window.to_start();
42
1
    assert_eq!(window.top(), 0);
43
1
}
44

            
45
#[test]
46
1
fn a_huge_step_stays_in_range() {
47
1
    let window = RowWindow::default();
48
1
    let _ = window.fit(30, 8);
49
1
    window.scroll_down(usize::MAX);
50
1
    assert_eq!(window.top(), 22);
51
1
}
52

            
53
#[test]
54
1
fn paging_the_selection_moves_a_view_of_rows_and_stops_at_the_ends() {
55
1
    let window = RowWindow::default();
56
1
    assert_eq!(window.paged(3, 30, true), 4);
57
1
    let _ = window.fit(30, 8);
58
1
    assert_eq!(window.paged(3, 30, true), 11);
59
1
    assert_eq!(window.paged(25, 30, true), 29);
60
1
    assert_eq!(window.paged(3, 30, false), 0);
61
1
}
62

            
63
#[test]
64
1
fn reset_forgets_the_draw() {
65
1
    let window = RowWindow::default();
66
1
    let _ = window.fit(30, 8);
67
1
    window.scroll_down(5);
68
1
    window.reset();
69
1
    assert_eq!((window.top(), window.rows()), (0, 0));
70
1
    window.scroll_down(5);
71
1
    assert_eq!(window.top(), 0);
72
1
}