-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathinput.c
114 lines (86 loc) · 2.07 KB
/
input.c
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
#include "libvim.h"
#include "minunit.h"
static int unhandledEscapeCount = 0;
void onUnhandledEscape(void)
{
unhandledEscapeCount++;
}
void test_setup(void)
{
vimKey("<esc>");
vimKey("<esc>");
vimExecute("e!");
vimInput("g");
vimInput("g");
vimInput("0");
unhandledEscapeCount = 0;
}
void test_teardown(void) {}
MU_TEST(test_cmd_key_insert)
{
vimInput("o");
vimKey("<D-A>");
mu_check(strcmp(vimBufferGetLine(curbuf, 2), "") == 0);
}
MU_TEST(test_binding_inactive)
{
vimExecute("inoremap a b");
vimInput("o");
vimKey("a");
mu_check(strcmp(vimBufferGetLine(curbuf, 2), "a") == 0);
}
MU_TEST(test_arrow_keys_normal)
{
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 0);
vimKey("<Right>");
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 1);
vimKey("<Down>");
mu_check(vimCursorGetLine() == 2);
mu_check(vimCursorGetColumn() == 1);
vimKey("<Left>");
mu_check(vimCursorGetLine() == 2);
mu_check(vimCursorGetColumn() == 0);
vimKey("<Up>");
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 0);
}
MU_TEST(test_unhandled_escape)
{
// Should get unhandled escape...
vimKey("<esc>");
mu_check(unhandledEscapeCount == 1);
// ...but not if escape was handled
vimInput("i");
vimKey("<esc>");
// Should still be 1 - no additional calls made.
mu_check(unhandledEscapeCount == 1);
}
MU_TEST(test_control_bracket)
{
vimInput("i");
mu_check((vimGetMode() & INSERT) == INSERT);
vimKey("<c-[>");
mu_check((vimGetMode() & NORMAL) == NORMAL);
}
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(test_arrow_keys_normal);
MU_RUN_TEST(test_cmd_key_insert);
MU_RUN_TEST(test_binding_inactive);
MU_RUN_TEST(test_unhandled_escape);
MU_RUN_TEST(test_control_bracket);
}
int main(int argc, char **argv)
{
vimInit(argc, argv);
vimSetUnhandledEscapeCallback(&onUnhandledEscape);
win_setwidth(5);
win_setheight(100);
vimBufferOpen("collateral/testfile.txt", 1, 0);
MU_RUN_SUITE(test_suite);
MU_REPORT();
MU_RETURN();
}