-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathnormal_mode_motion.c
207 lines (158 loc) · 4.03 KB
/
normal_mode_motion.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "libvim.h"
#include "minunit.h"
void test_setup(void)
{
vimExecute("e!");
vimKey("<esc>");
vimKey("<esc>");
vimInput("g");
vimInput("g");
}
void test_teardown(void) {}
MU_TEST(test_G_gg)
{
mu_check(vimCursorGetLine() == 1);
vimInput("G");
mu_check(vimCursorGetLine() == 3);
vimInput("g");
vimInput("g");
mu_check(vimCursorGetLine() == 1);
}
MU_TEST(test_j_k)
{
mu_check(vimCursorGetLine() == 1);
vimInput("j");
mu_check(vimCursorGetLine() == 2);
vimInput("k");
mu_check(vimCursorGetLine() == 1);
}
MU_TEST(test_2j_2k)
{
mu_check(vimCursorGetLine() == 1);
vimInput("2");
vimInput("j");
mu_check(vimCursorGetLine() == 3);
vimInput("2");
vimInput("k");
mu_check(vimCursorGetLine() == 1);
}
MU_TEST(test_forward_search)
{
// Move to very beginning
vimKey("g");
vimKey("g");
vimKey("0");
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 0);
// Search forwards to first 'line'
vimKey("/");
vimInput("line");
vimKey("<cr>");
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 18);
// Search again from here
vimKey("<esc>");
vimKey("<esc>");
vimKey("/");
vimInput("line");
vimKey("<cr>");
mu_check(vimCursorGetLine() == 2);
mu_check(vimCursorGetColumn() == 19);
}
MU_TEST(test_reverse_search)
{
// Move to second line, first byte
vimKey("j");
vimKey("0");
mu_check(vimCursorGetLine() == 2);
// Search backwards to first
vimKey("?");
vimInput("line");
vimKey("<cr>");
mu_check(vimCursorGetLine() == 1);
mu_check(vimCursorGetColumn() == 18);
// Starting from match, searching backwards again
vimKey("<esc>");
vimKey("<esc>");
vimKey("?");
vimInput("line");
vimKey("<cr>");
// Serach should loop back
mu_check(vimCursorGetLine() == 3);
mu_check(vimCursorGetColumn() == 18);
}
MU_TEST(test_forward_search_with_delete_operator)
{
// Delete, searching forward
vimInput("d");
vimKey("/");
vimInput("line");
vimKey("<cr>");
mu_check((vimGetMode() & NORMAL) == NORMAL);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "line of a test file") == 0);
};
MU_TEST(test_backward_search_with_delete_operator)
{
vimInput("$"); // Go to end of line
// Delete, searching forward
vimInput("d");
vimKey("?");
vimInput("line");
vimKey("<cr>");
mu_check((vimGetMode() & NORMAL) == NORMAL);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "This is the first e") == 0);
};
MU_TEST(test_forward_search_with_change_operator)
{
// Move to second line, first byte
// Change forwards, to first
vimInput("c");
vimKey("/");
vimInput("line");
vimKey("<cr>");
vimKey("a");
mu_check((vimGetMode() & INSERT) == INSERT);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "aline of a test file") == 0);
vimKey("<esc>");
mu_check((vimGetMode() & NORMAL) == NORMAL);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "aline of a test file") == 0);
};
MU_TEST(test_backward_search_with_change_operator)
{
// Move to last byte in first line
vimInput("$");
// Change forwards, to first
vimInput("c");
vimKey("?");
vimInput("line");
vimKey("<cr>");
vimKey("a");
mu_check((vimGetMode() & INSERT) == INSERT);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "This is the first ae") == 0);
vimKey("<esc>");
mu_check((vimGetMode() & NORMAL) == NORMAL);
mu_check(strcmp(vimBufferGetLine(curbuf, 1), "This is the first ae") == 0);
};
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(test_G_gg);
MU_RUN_TEST(test_j_k);
MU_RUN_TEST(test_2j_2k);
MU_RUN_TEST(test_forward_search);
MU_RUN_TEST(test_reverse_search);
MU_RUN_TEST(test_forward_search_with_delete_operator);
MU_RUN_TEST(test_backward_search_with_delete_operator);
MU_RUN_TEST(test_forward_search_with_change_operator);
MU_RUN_TEST(test_backward_search_with_change_operator);
}
int main(int argc, char **argv)
{
vimInit(argc, argv);
win_setwidth(5);
win_setheight(100);
vimBufferOpen("collateral/testfile.txt", 1, 0);
MU_RUN_SUITE(test_suite);
MU_REPORT();
MU_RETURN();
}