xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 37e743be56309fe42ac4154f4cd26eac1f9f4946

Extract tests/commands/normal.c
Out of tests/commands/misc.c in anticipation of adding more tests of
:normal command.
Author: xaizek
Author date (UTC): 2025-07-01 09:22
Committer name: xaizek
Committer date (UTC): 2025-07-01 09:22
Parent(s): fb4d5c983bd352d56dfc2bc2f5daca488ef5856c
Signing key: 99DC5E4DB05F6BE2
Tree: 706022d0ed88f75f8b3c51d161f70f68748fdfdc
File Lines added Lines deleted
tests/commands/misc.c 0 38
tests/commands/normal.c 70 0
File tests/commands/misc.c changed (mode: 100644) (index f4941981b..7f712a2d6)
10 10 #include "../../src/cfg/config.h" #include "../../src/cfg/config.h"
11 11 #include "../../src/compat/fs_limits.h" #include "../../src/compat/fs_limits.h"
12 12 #include "../../src/compat/os.h" #include "../../src/compat/os.h"
13 #include "../../src/engine/keys.h"
14 13 #include "../../src/lua/vlua.h" #include "../../src/lua/vlua.h"
15 14 #include "../../src/modes/menu.h" #include "../../src/modes/menu.h"
16 #include "../../src/modes/modes.h"
17 15 #include "../../src/ui/statusbar.h" #include "../../src/ui/statusbar.h"
18 16 #include "../../src/ui/ui.h" #include "../../src/ui/ui.h"
19 17 #include "../../src/utils/dynarray.h" #include "../../src/utils/dynarray.h"
 
... ... TEST(hist_next_and_prev)
283 281 cfg_resize_histories(0); cfg_resize_histories(0);
284 282 } }
285 283
286 TEST(normal_command_does_not_reset_selection)
287 {
288 modes_init();
289 opt_handlers_setup();
290
291 lwin.list_rows = 2;
292 lwin.list_pos = 0;
293 lwin.dir_entry = dynarray_cextend(NULL,
294 lwin.list_rows*sizeof(*lwin.dir_entry));
295 lwin.dir_entry[0].name = strdup("a");
296 lwin.dir_entry[0].origin = &lwin.curr_dir[0];
297 lwin.dir_entry[0].selected = 1;
298 lwin.dir_entry[1].name = strdup("b");
299 lwin.dir_entry[1].origin = &lwin.curr_dir[0];
300 lwin.dir_entry[1].selected = 0;
301 lwin.selected_files = 1;
302
303 assert_success(cmds_dispatch(":normal! t", &lwin, CIT_COMMAND));
304 assert_int_equal(0, lwin.selected_files);
305 assert_false(lwin.dir_entry[0].selected);
306 assert_false(lwin.dir_entry[1].selected);
307
308 assert_success(cmds_dispatch(":normal! vG\r", &lwin, CIT_COMMAND));
309 assert_int_equal(2, lwin.selected_files);
310 assert_true(lwin.dir_entry[0].selected);
311 assert_true(lwin.dir_entry[1].selected);
312
313 assert_success(cmds_dispatch(":normal! t", &lwin, CIT_COMMAND));
314 assert_int_equal(1, lwin.selected_files);
315 assert_true(lwin.dir_entry[0].selected);
316 assert_false(lwin.dir_entry[1].selected);
317
318 opt_handlers_teardown();
319 vle_keys_reset();
320 }
321
322 284 TEST(keepsel_preserves_selection) TEST(keepsel_preserves_selection)
323 285 { {
324 286 init_view_list(&lwin); init_view_list(&lwin);
File tests/commands/normal.c added (mode: 100644) (index 000000000..a6053dff9)
1 #include <stic.h>
2
3 #include <string.h> /* strdup() */
4
5 #include <test-utils.h>
6
7 #include "../../src/engine/keys.h"
8 #include "../../src/modes/modes.h"
9 #include "../../src/ui/ui.h"
10 #include "../../src/utils/dynarray.h"
11 #include "../../src/cmd_core.h"
12
13 SETUP()
14 {
15 view_setup(&lwin);
16 view_setup(&rwin);
17
18 curr_view = &lwin;
19 other_view = &rwin;
20
21 cmds_init();
22 modes_init();
23 opt_handlers_setup();
24 }
25
26 TEARDOWN()
27 {
28 view_teardown(&lwin);
29 view_teardown(&rwin);
30
31 curr_view = NULL;
32 other_view = NULL;
33
34 vle_cmds_reset();
35 vle_keys_reset();
36 opt_handlers_teardown();
37 }
38
39 TEST(normal_command_does_not_reset_selection)
40 {
41 lwin.list_rows = 2;
42 lwin.list_pos = 0;
43 lwin.dir_entry = dynarray_cextend(NULL,
44 lwin.list_rows*sizeof(*lwin.dir_entry));
45 lwin.dir_entry[0].name = strdup("a");
46 lwin.dir_entry[0].origin = &lwin.curr_dir[0];
47 lwin.dir_entry[0].selected = 1;
48 lwin.dir_entry[1].name = strdup("b");
49 lwin.dir_entry[1].origin = &lwin.curr_dir[0];
50 lwin.dir_entry[1].selected = 0;
51 lwin.selected_files = 1;
52
53 assert_success(cmds_dispatch(":normal! t", &lwin, CIT_COMMAND));
54 assert_int_equal(0, lwin.selected_files);
55 assert_false(lwin.dir_entry[0].selected);
56 assert_false(lwin.dir_entry[1].selected);
57
58 assert_success(cmds_dispatch(":normal! vG\r", &lwin, CIT_COMMAND));
59 assert_int_equal(2, lwin.selected_files);
60 assert_true(lwin.dir_entry[0].selected);
61 assert_true(lwin.dir_entry[1].selected);
62
63 assert_success(cmds_dispatch(":normal! t", &lwin, CIT_COMMAND));
64 assert_int_equal(1, lwin.selected_files);
65 assert_true(lwin.dir_entry[0].selected);
66 assert_false(lwin.dir_entry[1].selected);
67 }
68
69 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
70 /* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master