aboutsummaryrefslogtreecommitdiffstats
path: root/tests/basic.rs
blob: 33a272dfa266d4a7581c9ddc2ad64397a3e72933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#![allow(clippy::cognitive_complexity)]

#[test]
fn object_creation() {
    let parser = vt100::Parser::default();
    assert_eq!(parser.screen().size(), (24, 80));
}

#[test]
fn process_text() {
    let mut parser = vt100::Parser::default();
    let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr";
    parser.process(input);
    assert_eq!(parser.screen().contents(), "foobar");
}

#[test]
fn set_size() {
    let mut parser = vt100::Parser::default();
    assert_eq!(parser.screen().size(), (24, 80));
    assert_eq!(parser.screen().cursor_position(), (0, 0));

    parser.set_size(34, 8);
    assert_eq!(parser.screen().size(), (34, 8));
    assert_eq!(parser.screen().cursor_position(), (0, 0));

    parser.process(b"\x1b[30;5H");
    assert_eq!(parser.screen().cursor_position(), (29, 4));

    parser.set_size(24, 80);
    assert_eq!(parser.screen().size(), (24, 80));
    assert_eq!(parser.screen().cursor_position(), (23, 4));

    parser.set_size(34, 8);
    assert_eq!(parser.screen().size(), (34, 8));
    assert_eq!(parser.screen().cursor_position(), (23, 4));

    parser.process(b"\x1b[?1049h");
    assert_eq!(parser.screen().size(), (34, 8));
    assert_eq!(parser.screen().cursor_position(), (0, 0));

    parser.set_size(24, 80);
    assert_eq!(parser.screen().size(), (24, 80));
    assert_eq!(parser.screen().cursor_position(), (0, 0));

    parser.process(b"\x1b[?1049l");
    assert_eq!(parser.screen().size(), (24, 80));
    assert_eq!(parser.screen().cursor_position(), (23, 4));

    parser.set_size(34, 8);
    parser.process(b"\x1bc01234567890123456789");
    assert_eq!(parser.screen().contents(), "01234567890123456789");

    parser.set_size(24, 80);
    assert_eq!(parser.screen().contents(), "01234567\n89012345\n6789");

    parser.set_size(34, 8);
    assert_eq!(parser.screen().contents(), "01234567\n89012345\n6789");
}

#[test]
fn cell_contents() {
    let mut parser = vt100::Parser::default();
    let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr";
    parser.process(input);
    assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f");
    assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o");
    assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o");
    assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "b");
    assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "a");
    assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "r");
    assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), "");
}

#[test]
fn cell_colors() {
    let mut parser = vt100::Parser::default();
    let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr";
    parser.process(input);

    assert_eq!(
        parser.screen().cell(0, 0).unwrap().fgcolor(),
        vt100::Color::Default
    );
    assert_eq!(
        parser.screen().cell(0, 3).unwrap().fgcolor(),
        vt100::Color::Idx(2)
    );
    assert_eq!(
        parser.screen().cell(0, 4).unwrap().fgcolor(),
        vt100::Color::Idx(2)
    );
    assert_eq!(
        parser.screen().cell(0, 4).unwrap().bgcolor(),
        vt100::Color::Idx(2)
    );
}

#[test]
fn cell_attrs() {
    let mut parser = vt100::Parser::default();
    let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr";
    parser.process(input);

    assert!(parser.screen().cell(0, 4).unwrap().italic());
}