aboutsummaryrefslogtreecommitdiffstats
path: root/vim-mode/tests.pl
blob: 90071717066df56bd5bc325b0c84bb344488eac4 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env perl

# Must be run in a 80x24 terminal unless a fixed POE is released.


use strict;
use warnings;

use lib '../testing/blib/lib';

use Test::Irssi;

# Mode constants: C(ommand), I(nsert).
sub C () { 0 }
sub I () { 1 }


sub statusbar_mode {
    my ($test, $mode) = @_;

    $test->add_pattern_match(qr/^ \[\d{2}:\d{2}\] \[\] \[1\] \[$mode\]\s+$/,
        'window_sbar', "[$mode] in vim-mode statusbar");
}
sub cursor_position {
    my ($test, $position) = @_;

    $test->test_cursor_position($position, 24, "Checking cursor position");
}

sub check {
    my ($test, $input, $mode, $position, $delay) = @_;

    if (defined $input) {
        $test->add_input_sequence($input);
        if (not defined $delay) {
            $delay = 0.1;
            $delay += 0.4 if $input =~ /\e/; # esc needs a longer delay
        }
        $test->add_delay($delay);
    }

    cursor_position($test, $position);
    if ($mode == C) {
        statusbar_mode($test, 'Command');
    } elsif ($mode == I) {
        statusbar_mode($test, 'Insert');
    } else {
        die "Wrong mode: $mode";
    }
}

my $tester = Test::Irssi->new
  (irssi_binary  => "irssi",
   irssi_homedir => "./irssi/");


$tester->run_headless(1);
$tester->generate_tap(1);

my $test = $tester->new_test('insert-command-mode');
$test->description("switching between insert and command mode");
# Make sure irssi is finished - not entirely sure why this is necessary.
$test->add_delay(2);

# We start in insert mode.
check $test, undef, I, 12 + 0;
check $test, "\e",  C, 12 + 0;
check $test, 'i',   I, 12 + 0;

# Quit irssi, necessary to terminate the test.
#$test->add_input_sequence("\n/quit\n");


# FIXME: multiple tests don't work
#$test = $tester->new_test('basic-movement');
#$test->description('basic movement');
#$test->add_delay(2);

my $test_string =
    'Test $tring. with a 4711, words , w.r#s42  etc.   and more123! ..';

check $test, $test_string, I, 12 + length $test_string;
check $test, "\e",         C, 12 + 64;

# h l
check $test, "0",    C, 12 + 0;
check $test, "l",    C, 12 + 1;
check $test, "l",    C, 12 + 2;
check $test, "l",    C, 12 + 3;
check $test, "l",    C, 12 + 4;
check $test, "l",    C, 12 + 5;
check $test, "l",    C, 12 + 6;
check $test, "l",    C, 12 + 7;
check $test, "h",    C, 12 + 6;
check $test, "h",    C, 12 + 5;
check $test, "h",    C, 12 + 4;
check $test, "h",    C, 12 + 3;
check $test, "h",    C, 12 + 2;
check $test, "10l",  C, 12 + 12;
check $test, "7l",   C, 12 + 19;
check $test, "3l",   C, 12 + 22;
check $test, "3h",   C, 12 + 19;
check $test, "50l",  C, 12 + 64;
check $test, "10l",  C, 12 + 64;
check $test, "24h",  C, 12 + 40;
check $test, "100h", C, 12 + 0;

# 0 ^ $
check $test, "I     \e", C, 12 + 4; # insert test string for ^
check $test, "0",        C, 12 + 0;
check $test, "^",        C, 12 + 5;
check $test, "3^",       C, 12 + 5;
check $test, "12^",      C, 12 + 5;
check $test, "\$",       C, 12 + 46;
check $test, "05x",      C, 12 + 0; # remove test string for ^

# <Space> <BS>
check $test, "0",      C, 12 + 0;
check $test, " ",      C, 12 + 1;
check $test, " ",      C, 12 + 2;
check $test, " ",      C, 12 + 3;
check $test, " ",      C, 12 + 4;
check $test, " ",      C, 12 + 5;
check $test, " ",      C, 12 + 6;
check $test, " ",      C, 12 + 7;
check $test, " ",      C, 12 + 8;
check $test, "5 ",     C, 12 + 13;
check $test, "2 ",     C, 12 + 15;
check $test, "10 ",    C, 12 + 25;
check $test, "30 ",    C, 12 + 55;
check $test, "20 ",    C, 12 + 64;
check $test, "10 ",    C, 12 + 64;
check $test, " ",      C, 12 + 64;
check $test, "\x7f",   C, 12 + 63;
check $test, "\x7f",   C, 12 + 62;
check $test, "\x7f",   C, 12 + 61;
check $test, "\x7f",   C, 12 + 60;
check $test, "1\x7f",  C, 12 + 59;
check $test, "3\x7f",  C, 12 + 56;
check $test, "5\x7f",  C, 12 + 51;
check $test, "10\x7f", C, 12 + 41;
check $test, "50\x7f", C, 12 + 0;
check $test, "\x7f",   C, 12 + 0;
check $test, "5\x7f",  C, 12 + 0;

# f t
check $test, "0",   C, 12 + 0;
check $test, "fe",  C, 12 + 1;
check $test, "fs",  C, 12 + 2;
check $test, "ft",  C, 12 + 3;
check $test, "f ",  C, 12 + 4;
check $test, "2f ", C, 12 + 17;
check $test, "5f,", C, 12 + 17;
check $test, "2f,", C, 12 + 32;
check $test, "tw",  C, 12 + 33;
check $test, "t ",  C, 12 + 40;
check $test, "t ",  C, 12 + 40;
check $test, "t ",  C, 12 + 40;
check $test, "2t ", C, 12 + 41;
check $test, "2t ", C, 12 + 46;
check $test, "3t ", C, 12 + 48;
check $test, "t!",  C, 12 + 60;
check $test, "t ",  C, 12 + 61;
check $test, "t.",  C, 12 + 62;
check $test, "t.",  C, 12 + 62;
check $test, "5t.", C, 12 + 62;
check $test, "\$",  C, 12 + 64;

$test->add_input_sequence("\n/quit\n");

$tester->run;