dte test coverage


Directory: ./
File: test/cmdline.c
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 462 462 100.0%
Functions: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #include <stdlib.h>
2 #include "test.h"
3 #include "cmdline.h"
4 #include "commands.h"
5 #include "completion.h"
6 #include "editor.h"
7 #include "mode.h"
8
9 #define EXPECT_STRING_EQ(s, cstr) \
10 EXPECT_STREQ(string_borrow_cstring(&(s)), (cstr))
11
12 1 static void test_command_mode(TestContext *ctx)
13 {
14 1 EditorState *e = ctx->userdata;
15 1 CommandLine *c = &e->cmdline;
16 1 push_input_mode(e, e->command_mode);
17 1 EXPECT_PTREQ(e->mode, e->command_mode);
18
19 1 EXPECT_TRUE(handle_input(e, 'a'));
20 1 EXPECT_EQ(c->pos, 1);
21 1 EXPECT_STRING_EQ(c->buf, "a");
22
23 1 EXPECT_TRUE(handle_input(e, 0x1F999));
24 1 EXPECT_EQ(c->pos, 5);
25 1 EXPECT_STRING_EQ(c->buf, "a\xF0\x9F\xA6\x99");
26
27 1 CommandRunner runner = cmdrunner(e, &cmd_mode_commands);
28 1 EXPECT_PTREQ(runner.e, e);
29 1 EXPECT_PTREQ(runner.cmds, &cmd_mode_commands);
30 1 EXPECT_NULL(runner.lookup_alias);
31 1 EXPECT_EQ(runner.recursion_count, 0);
32 1 EXPECT_FALSE(runner.allow_recording);
33 1 EXPECT_TRUE(runner.expand_tilde_slash);
34
35 // Delete at end-of-line should do nothing
36 1 CommandRunner *r = &runner;
37 1 EXPECT_TRUE(handle_command(r, "delete"));
38 1 EXPECT_EQ(c->pos, 5);
39 1 EXPECT_EQ(c->buf.len, 5);
40
41 1 EXPECT_TRUE(handle_command(r, "erase"));
42 1 EXPECT_EQ(c->pos, 1);
43 1 EXPECT_STRING_EQ(c->buf, "a");
44
45 1 EXPECT_TRUE(handle_command(r, "erase"));
46 1 EXPECT_EQ(c->pos, 0);
47 1 EXPECT_STRING_EQ(c->buf, "");
48
49 1 cmdline_set_text(c, "word1 word2 word3 word4");
50 1 EXPECT_TRUE(handle_command(r, "eol"));
51 1 EXPECT_EQ(c->pos, 23);
52
53 1 EXPECT_TRUE(handle_command(r, "erase-word"));
54 1 EXPECT_EQ(c->pos, 18);
55 1 EXPECT_STRING_EQ(c->buf, "word1 word2 word3 ");
56
57 1 EXPECT_TRUE(handle_command(r, "erase-word"));
58 1 EXPECT_EQ(c->pos, 12);
59 1 EXPECT_STRING_EQ(c->buf, "word1 word2 ");
60
61 1 EXPECT_TRUE(handle_command(r, "word-bwd"));
62 1 EXPECT_EQ(c->pos, 6);
63
64 1 EXPECT_TRUE(handle_command(r, "word-fwd"));
65 1 EXPECT_EQ(c->pos, 12);
66
67 1 EXPECT_TRUE(handle_command(r, "bol"));
68 1 EXPECT_EQ(c->pos, 0);
69
70 1 EXPECT_TRUE(handle_command(r, "delete-word"));
71 1 EXPECT_EQ(c->pos, 0);
72 1 EXPECT_STRING_EQ(c->buf, "word2 ");
73
74 1 EXPECT_TRUE(handle_command(r, "right"));
75 1 EXPECT_EQ(c->pos, 1);
76
77 1 EXPECT_TRUE(handle_command(r, "erase-bol"));
78 1 EXPECT_EQ(c->pos, 0);
79 1 EXPECT_STRING_EQ(c->buf, "ord2 ");
80
81 1 EXPECT_TRUE(handle_command(r, "delete"));
82 1 EXPECT_EQ(c->pos, 0);
83 1 EXPECT_STRING_EQ(c->buf, "rd2 ");
84
85 1 EXPECT_TRUE(handle_command(r, "delete-eol"));
86 1 EXPECT_EQ(c->pos, 0);
87 1 EXPECT_EQ(c->buf.len, 0);
88
89 // Left at beginning-of-line should do nothing
90 1 EXPECT_TRUE(handle_command(r, "left"));
91 1 EXPECT_EQ(c->pos, 0);
92
93 1 cmdline_set_text(c, "...");
94 1 EXPECT_EQ(c->pos, 3);
95 1 EXPECT_EQ(c->buf.len, 3);
96
97 1 EXPECT_TRUE(handle_command(r, "bol"));
98 1 EXPECT_EQ(c->pos, 0);
99 1 EXPECT_EQ(c->buf.len, 3);
100
101 1 EXPECT_TRUE(handle_command(r, "right"));
102 1 EXPECT_EQ(c->pos, 1);
103
104 1 EXPECT_TRUE(handle_command(r, "word-bwd"));
105 1 EXPECT_EQ(c->pos, 0);
106
107 1 EXPECT_TRUE(handle_command(r, "eol"));
108 1 EXPECT_EQ(c->pos, 3);
109
110 1 EXPECT_TRUE(handle_command(r, "cancel"));
111 1 EXPECT_EQ(c->pos, 0);
112 1 EXPECT_NULL(c->search_pos);
113 1 EXPECT_EQ(c->buf.len, 0);
114 1 EXPECT_PTREQ(e->mode, e->normal_mode);
115
116 1 string_free(&c->buf);
117 1 EXPECT_NULL(c->buf.buffer);
118 1 EXPECT_EQ(c->buf.alloc, 0);
119 1 }
120
121 #define ENV_VAR_PREFIX "D__p_tYmz3_"
122 #define ENV_VAR_NAME ENV_VAR_PREFIX "_VAR"
123
124 1 static void test_complete_command(TestContext *ctx)
125 {
126 1 EditorState *e = ctx->userdata;
127 1 CommandLine *c = &e->cmdline;
128 1 complete_command_next(e);
129 1 EXPECT_STRING_EQ(c->buf, "alias");
130 1 maybe_reset_completion(c);
131
132 1 cmdline_set_text(c, "bind C-invalidkey");
133 1 complete_command_next(e);
134 1 EXPECT_STRING_EQ(c->buf, "bind C-invalidkey");
135 1 reset_completion(c);
136
137 1 cmdline_set_text(c, "bind -s C-M-S-l");
138 1 complete_command_next(e);
139 1 EXPECT_STRING_EQ(c->buf, "bind -s C-M-S-l");
140 1 reset_completion(c);
141
142 1 cmdline_set_text(c, "bind -cs ");
143 1 complete_command_next(e);
144 1 EXPECT_STRING_EQ(c->buf, "bind -cs ");
145 1 reset_completion(c);
146
147 1 cmdline_set_text(c, "bind -c -T search ");
148 1 complete_command_next(e);
149 1 EXPECT_STRING_EQ(c->buf, "bind -c -T search ");
150 1 reset_completion(c);
151
152 1 cmdline_set_text(c, "bind -T ");
153 1 complete_command_next(e);
154 1 EXPECT_STRING_EQ(c->buf, "bind -T command");
155 1 reset_completion(c);
156
157 1 cmdline_set_text(c, "bind -T se");
158 1 complete_command_next(e);
159 1 EXPECT_STRING_EQ(c->buf, "bind -T search ");
160 1 reset_completion(c);
161
162 1 cmdline_set_text(c, "def-mode ");
163 1 complete_command_next(e);
164 1 EXPECT_STRING_EQ(c->buf, "def-mode ");
165 1 reset_completion(c);
166
167 1 cmdline_set_text(c, "def-mode xyz ");
168 1 complete_command_next(e);
169 1 EXPECT_STRING_EQ(c->buf, "def-mode xyz normal ");
170 1 complete_command_next(e);
171 1 EXPECT_STRING_EQ(c->buf, "def-mode xyz normal ");
172 1 reset_completion(c);
173
174 1 cmdline_set_text(c, "mode ");
175 1 complete_command_next(e);
176 1 EXPECT_STRING_EQ(c->buf, "mode command");
177 1 complete_command_next(e);
178 1 EXPECT_STRING_EQ(c->buf, "mode normal");
179 1 complete_command_next(e);
180 1 EXPECT_STRING_EQ(c->buf, "mode search");
181 1 complete_command_next(e);
182 1 EXPECT_STRING_EQ(c->buf, "mode command");
183 1 reset_completion(c);
184
185 1 cmdline_set_text(c, "wrap");
186 1 complete_command_next(e);
187 1 EXPECT_STRING_EQ(c->buf, "wrap-paragraph ");
188 1 reset_completion(c);
189
190 1 cmdline_set_text(c, "open test/data/.e");
191 1 complete_command_next(e);
192 1 EXPECT_STRING_EQ(c->buf, "open test/data/.editorconfig ");
193 1 reset_completion(c);
194
195 1 cmdline_set_text(c, "open GNUma");
196 1 complete_command_next(e);
197 1 EXPECT_STRING_EQ(c->buf, "open GNUmakefile ");
198 1 reset_completion(c);
199
200 1 cmdline_set_text(c, "wsplit -bhr test/data/.e");
201 1 complete_command_next(e);
202 1 EXPECT_STRING_EQ(c->buf, "wsplit -bhr test/data/.editorconfig ");
203 1 reset_completion(c);
204
205 1 cmdline_set_text(c, "toggle ");
206 1 complete_command_next(e);
207 1 EXPECT_STRING_EQ(c->buf, "toggle auto-indent");
208 1 reset_completion(c);
209
210 1 cmdline_set_text(c, "set expand-tab f");
211 1 complete_command_next(e);
212 1 EXPECT_STRING_EQ(c->buf, "set expand-tab false ");
213 1 reset_completion(c);
214
215 1 cmdline_set_text(c, "set case-sensitive-search a");
216 1 complete_command_next(e);
217 1 EXPECT_STRING_EQ(c->buf, "set case-sensitive-search auto ");
218 1 reset_completion(c);
219
220 1 ASSERT_EQ(setenv(ENV_VAR_NAME, "xyz", 1), 0);
221
222 1 cmdline_set_text(c, "insert $" ENV_VAR_PREFIX);
223 1 complete_command_next(e);
224 1 EXPECT_STRING_EQ(c->buf, "insert $" ENV_VAR_NAME);
225 1 reset_completion(c);
226
227 1 cmdline_set_text(c, "setenv " ENV_VAR_PREFIX);
228 1 complete_command_next(e);
229 1 EXPECT_STRING_EQ(c->buf, "setenv " ENV_VAR_NAME " ");
230 1 complete_command_next(e);
231 1 EXPECT_STRING_EQ(c->buf, "setenv " ENV_VAR_NAME " xyz ");
232 1 reset_completion(c);
233
234 1 ASSERT_EQ(unsetenv(ENV_VAR_NAME), 0);
235
236 1 cmdline_clear(c);
237 1 complete_command_prev(e);
238 1 EXPECT_STRING_EQ(c->buf, "alias");
239 1 complete_command_prev(e);
240 1 EXPECT_STRING_EQ(c->buf, "wswap");
241 1 complete_command_prev(e);
242 1 EXPECT_STRING_EQ(c->buf, "wsplit");
243 1 reset_completion(c);
244
245 1 cmdline_set_text(c, "hi default ");
246 1 complete_command_next(e);
247 1 EXPECT_STRING_EQ(c->buf, "hi default black");
248 1 complete_command_prev(e);
249 1 EXPECT_STRING_EQ(c->buf, "hi default yellow");
250 1 complete_command_next(e);
251 1 EXPECT_STRING_EQ(c->buf, "hi default black");
252 1 complete_command_next(e);
253 1 EXPECT_STRING_EQ(c->buf, "hi default blink");
254 1 reset_completion(c);
255
256 1 cmdline_set_text(c, "cursor i");
257 1 complete_command_next(e);
258 1 EXPECT_STRING_EQ(c->buf, "cursor insert ");
259 1 complete_command_next(e);
260 1 EXPECT_STRING_EQ(c->buf, "cursor insert bar");
261 1 reset_completion(c);
262
263 1 cmdline_set_text(c, "cursor default blo");
264 1 complete_command_next(e);
265 1 EXPECT_STRING_EQ(c->buf, "cursor default block ");
266 1 complete_command_next(e);
267 1 EXPECT_STRING_EQ(c->buf, "cursor default block #22AABB");
268 1 complete_command_next(e);
269 1 EXPECT_STRING_EQ(c->buf, "cursor default block default");
270 1 complete_command_next(e);
271 1 EXPECT_STRING_EQ(c->buf, "cursor default block keep");
272 1 reset_completion(c);
273
274 1 cmdline_set_text(c, "show opt");
275 1 complete_command_next(e);
276 1 EXPECT_STRING_EQ(c->buf, "show option ");
277 1 complete_command_next(e);
278 1 EXPECT_STRING_EQ(c->buf, "show option auto-indent");
279 1 reset_completion(c);
280
281 1 cmdline_set_text(c, "show builtin syntax/gitcom");
282 1 complete_command_next(e);
283 1 EXPECT_STRING_EQ(c->buf, "show builtin syntax/gitcommit ");
284 1 reset_completion(c);
285
286 1 cmdline_set_text(c, "set ws-error tr");
287 1 complete_command_next(e);
288 1 EXPECT_STRING_EQ(c->buf, "set ws-error trailing ");
289 1 reset_completion(c);
290
291 1 cmdline_set_text(c, "set ws-error special,tab-");
292 1 complete_command_next(e);
293 1 EXPECT_STRING_EQ(c->buf, "set ws-error special,tab-after-indent");
294 1 complete_command_next(e);
295 1 EXPECT_STRING_EQ(c->buf, "set ws-error special,tab-indent");
296 1 complete_command_next(e);
297 1 EXPECT_STRING_EQ(c->buf, "set ws-error special,tab-after-indent");
298 1 reset_completion(c);
299
300 1 cmdline_set_text(c, "set esc-timeout ");
301 1 complete_command_next(e);
302 1 EXPECT_STRING_EQ(c->buf, "set esc-timeout 100 ");
303 1 reset_completion(c);
304
305 1 cmdline_set_text(c, "set x y tab-b");
306 1 complete_command_next(e);
307 1 EXPECT_STRING_EQ(c->buf, "set x y tab-bar ");
308 1 complete_command_next(e);
309 1 EXPECT_STRING_EQ(c->buf, "set x y tab-bar true ");
310 1 reset_completion(c);
311
312 1 cmdline_set_text(c, "save -u test/data/");
313 1 complete_command_next(e);
314 1 EXPECT_STRING_EQ(c->buf, "save -u test/data/3lines.txt");
315 1 reset_completion(c);
316
317 1 cmdline_set_text(c, "include -b r");
318 1 complete_command_next(e);
319 1 EXPECT_STRING_EQ(c->buf, "include -b rc ");
320 1 reset_completion(c);
321
322 1 cmdline_set_text(c, "option gitcom");
323 1 complete_command_next(e);
324 1 EXPECT_STRING_EQ(c->buf, "option gitcommit ");
325 1 complete_command_next(e);
326 1 EXPECT_STRING_EQ(c->buf, "option gitcommit auto-indent");
327 1 reset_completion(c);
328
329 1 cmdline_set_text(c, "errorfmt c r ");
330 1 complete_command_next(e);
331 1 EXPECT_STRING_EQ(c->buf, "errorfmt c r _");
332 1 complete_command_next(e);
333 1 EXPECT_STRING_EQ(c->buf, "errorfmt c r column");
334 1 reset_completion(c);
335
336 1 cmdline_set_text(c, "ft javasc");
337 1 complete_command_next(e);
338 1 EXPECT_STRING_EQ(c->buf, "ft javascript ");
339 1 reset_completion(c);
340
341 1 cmdline_set_text(c, "macro rec");
342 1 complete_command_next(e);
343 1 EXPECT_STRING_EQ(c->buf, "macro record ");
344 1 reset_completion(c);
345
346 1 cmdline_set_text(c, "move-tab ");
347 1 complete_command_next(e);
348 1 EXPECT_STRING_EQ(c->buf, "move-tab left");
349 1 complete_command_next(e);
350 1 EXPECT_STRING_EQ(c->buf, "move-tab right");
351 1 reset_completion(c);
352
353 1 cmdline_set_text(c, "quit ");
354 1 complete_command_next(e);
355 1 EXPECT_STRING_EQ(c->buf, "quit 0");
356 1 complete_command_next(e);
357 1 EXPECT_STRING_EQ(c->buf, "quit 1");
358 1 reset_completion(c);
359
360 1 cmdline_set_text(c, "repeat 3 ");
361 1 complete_command_next(e);
362 1 EXPECT_STRING_EQ(c->buf, "repeat 3 alias");
363 1 reset_completion(c);
364
365 1 cmdline_set_text(c, "repeat 3 hi ");
366 1 complete_command_next(e);
367 1 EXPECT_STRING_EQ(c->buf, "repeat 3 hi activetab");
368 1 reset_completion(c);
369
370 1 cmdline_set_text(c, "left; right; word-");
371 1 complete_command_next(e);
372 1 EXPECT_STRING_EQ(c->buf, "left; right; word-bwd");
373 1 reset_completion(c);
374
375 1 cmdline_set_text(c, "replace -");
376 1 complete_command_next(e);
377 1 EXPECT_STRING_EQ(c->buf, "replace -b");
378 1 complete_command_next(e);
379 1 EXPECT_STRING_EQ(c->buf, "replace -c");
380 1 complete_command_next(e);
381 1 EXPECT_STRING_EQ(c->buf, "replace -e");
382 1 complete_command_next(e);
383 1 EXPECT_STRING_EQ(c->buf, "replace -g");
384 1 complete_command_next(e);
385 1 EXPECT_STRING_EQ(c->buf, "replace -i");
386 1 complete_command_next(e);
387 1 EXPECT_STRING_EQ(c->buf, "replace -b");
388 1 reset_completion(c);
389
390 1 cmdline_set_text(c, "replace -- -");
391 1 complete_command_next(e);
392 1 EXPECT_STRING_EQ(c->buf, "replace -- -");
393 1 reset_completion(c);
394
395 1 cmdline_set_text(c, "left -c; replace -b -");
396 1 complete_command_next(e);
397 1 EXPECT_STRING_EQ(c->buf, "left -c; replace -b -c");
398 1 reset_completion(c);
399
400 1 cmdline_set_text(c, "replace -bcei -");
401 1 complete_command_next(e);
402 1 EXPECT_STRING_EQ(c->buf, "replace -bcei -g ");
403 1 reset_completion(c);
404
405 1 cmdline_set_text(c, "replace -bcegi -");
406 1 complete_command_next(e);
407 1 EXPECT_STRING_EQ(c->buf, "replace -bcegi -");
408 1 reset_completion(c);
409
410 1 cmdline_set_text(c, "replace -i");
411 1 complete_command_next(e);
412 1 EXPECT_STRING_EQ(c->buf, "replace -i ");
413 1 reset_completion(c);
414
415 1 cmdline_set_text(c, "wswap -");
416 1 complete_command_next(e);
417 1 EXPECT_STRING_EQ(c->buf, "wswap -");
418 1 reset_completion(c);
419
420 1 cmdline_set_text(c, "exec -");
421 1 complete_command_next(e);
422 1 EXPECT_STRING_EQ(c->buf, "exec -e");
423 1 reset_completion(c);
424
425 1 cmdline_set_text(c, "exec -o");
426 1 complete_command_next(e);
427 1 EXPECT_STRING_EQ(c->buf, "exec -o ");
428 1 complete_command_next(e);
429 1 EXPECT_STRING_EQ(c->buf, "exec -o buffer");
430 1 complete_command_next(e);
431 1 EXPECT_STRING_EQ(c->buf, "exec -o echo");
432 1 complete_command_next(e);
433 1 EXPECT_STRING_EQ(c->buf, "exec -o eval");
434 1 reset_completion(c);
435
436 1 cmdline_set_text(c, "exec -- -");
437 1 complete_command_next(e);
438 1 EXPECT_STRING_EQ(c->buf, "exec -- -");
439 1 reset_completion(c);
440
441 1 cmdline_set_text(c, "exec -p ls -");
442 1 complete_command_next(e);
443 1 EXPECT_STRING_EQ(c->buf, "exec -p ls -");
444 1 reset_completion(c);
445
446 1 cmdline_set_text(c, "exec -p ls -l");
447 1 complete_command_next(e);
448 1 EXPECT_STRING_EQ(c->buf, "exec -p ls -l");
449 1 reset_completion(c);
450
451 1 cmdline_set_text(c, "exec -s -i buffer -o buffer -");
452 1 complete_command_next(e);
453 1 EXPECT_STRING_EQ(c->buf, "exec -s -i buffer -o buffer -e");
454 1 reset_completion(c);
455
456 1 cmdline_set_text(c, "exec -s -i buffer ls -");
457 1 complete_command_next(e);
458 1 EXPECT_STRING_EQ(c->buf, "exec -s -i buffer ls -");
459 1 reset_completion(c);
460
461 1 cmdline_set_text(c, "replace -cg");
462 1 complete_command_next(e);
463 1 EXPECT_STRING_EQ(c->buf, "replace -cg");
464 1 reset_completion(c);
465
466 1 cmdline_set_text(c, "left -");
467 1 complete_command_next(e);
468 1 EXPECT_STRING_EQ(c->buf, "left -c");
469 1 reset_completion(c);
470
471 1 cmdline_set_text(c, "option -");
472 1 complete_command_next(e);
473 1 EXPECT_STRING_EQ(c->buf, "option -r ");
474 1 reset_completion(c);
475
476 1 cmdline_set_text(c, "quit 1 -");
477 1 complete_command_next(e);
478 1 EXPECT_STRING_EQ(c->buf, "quit 1 -C");
479 1 reset_completion(c);
480
481 1 cmdline_set_text(c, "quit 1 2 -");
482 1 complete_command_next(e);
483 1 EXPECT_STRING_EQ(c->buf, "quit 1 2 -");
484 1 reset_completion(c);
485
486 1 const Command *wflip = find_normal_command("wflip");
487 1 EXPECT_EQ(wflip->flags[0], '\0');
488 1 EXPECT_EQ(wflip->max_args, 0);
489
490 1 cmdline_set_text(c, "wflip ");
491 1 complete_command_next(e);
492 1 EXPECT_STRING_EQ(c->buf, "wflip ");
493 1 reset_completion(c);
494
495 1 cmdline_set_text(c, "wflip -");
496 1 complete_command_next(e);
497 1 EXPECT_STRING_EQ(c->buf, "wflip -");
498 1 reset_completion(c);
499
500 1 cmdline_set_text(c, "wflip -- -");
501 1 complete_command_next(e);
502 1 EXPECT_STRING_EQ(c->buf, "wflip -- -");
503 1 reset_completion(c);
504 1 }
505
506 // This should only be run after init_headless_mode() because the completions
507 // depend on the buffer and default config being initialized
508 1 static void test_complete_command_extra(TestContext *ctx)
509 {
510 1 EditorState *e = ctx->userdata;
511 1 CommandLine *c = &e->cmdline;
512
513 1 cmdline_set_text(c, "alias reverse-li");
514 1 complete_command_next(e);
515 1 EXPECT_STRING_EQ(c->buf, "alias reverse-lines ");
516 1 complete_command_next(e);
517 1 EXPECT_STRING_EQ(c->buf, "alias reverse-lines 'filter tac' ");
518 1 reset_completion(c);
519
520 1 cmdline_set_text(c, "bind C-z");
521 1 complete_command_next(e);
522 1 EXPECT_STRING_EQ(c->buf, "bind C-z ");
523 1 complete_command_next(e);
524 1 EXPECT_STRING_EQ(c->buf, "bind C-z undo ");
525 1 reset_completion(c);
526
527 1 cmdline_set_text(c, "bind -s C-g");
528 1 complete_command_next(e);
529 1 EXPECT_STRING_EQ(c->buf, "bind -s C-g ");
530 1 complete_command_next(e);
531 1 EXPECT_STRING_EQ(c->buf, "bind -s C-g cancel ");
532 1 reset_completion(c);
533
534 1 cmdline_set_text(c, "bind -T command tab ");
535 1 complete_command_next(e);
536 1 EXPECT_STRING_EQ(c->buf, "bind -T command tab complete-next ");
537 1 reset_completion(c);
538
539 1 cmdline_set_text(c, "compile -1s bas");
540 1 complete_command_next(e);
541 1 EXPECT_STRING_EQ(c->buf, "compile -1s basic ");
542 1 reset_completion(c);
543
544 1 cmdline_set_text(c, "errorfmt bas");
545 1 complete_command_next(e);
546 1 EXPECT_STRING_EQ(c->buf, "errorfmt basic ");
547 1 reset_completion(c);
548
549 1 cmdline_set_text(c, "errorfmt xyz '^(.*)$' m");
550 1 complete_command_next(e);
551 1 EXPECT_STRING_EQ(c->buf, "errorfmt xyz '^(.*)$' message ");
552 1 reset_completion(c);
553
554 1 cmdline_set_text(c, "show bi");
555 1 complete_command_next(e);
556 1 EXPECT_STRING_EQ(c->buf, "show bind ");
557 1 complete_command_next(e);
558 1 EXPECT_STRING_EQ(c->buf, "show bind C-M-S-delete");
559 1 complete_command_prev(e);
560 1 EXPECT_STRING_EQ(c->buf, "show bind up");
561 1 reset_completion(c);
562
563 1 cmdline_set_text(c, "show errorfmt gc");
564 1 complete_command_next(e);
565 1 EXPECT_STRING_EQ(c->buf, "show errorfmt gcc ");
566 1 reset_completion(c);
567
568 1 cmdline_set_text(c, "option c expand-tab ");
569 1 complete_command_next(e);
570 1 EXPECT_STRING_EQ(c->buf, "option c expand-tab true ");
571 1 reset_completion(c);
572
573 1 static const char create_files[] =
574 "run -s mkdir -p $HOME/sub;"
575 "run -s touch $HOME/file $HOME/sub/subfile;";
576
577 1 EXPECT_TRUE(handle_normal_command(e, create_files, false));
578 1 cmdline_set_text(c, "open ~/");
579 1 complete_command_next(e);
580 1 EXPECT_STRING_EQ(c->buf, "open ~/file");
581 1 complete_command_next(e);
582 1 EXPECT_STRING_EQ(c->buf, "open ~/sub/");
583 1 reset_completion(c);
584
585 1 cmdline_set_text(c, "open ~/sub/");
586 1 complete_command_next(e);
587 1 EXPECT_STRING_EQ(c->buf, "open ~/sub/subfile ");
588 1 reset_completion(c);
589 1 }
590
591 static const TestEntry tests[] = {
592 TEST(test_command_mode),
593 TEST(test_complete_command),
594 };
595
596 static const TestEntry tests_late[] = {
597 TEST(test_complete_command_extra),
598 };
599
600 const TestGroup cmdline_tests = TEST_GROUP(tests);
601 const TestGroup cmdline_tests_late = TEST_GROUP(tests_late);
602