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 ae06c3fc5509caf872f7a72842515aa3149b986a

Cover filter control keys with tests
Author: xaizek
Author date (UTC): 2026-07-28 10:45
Committer name: xaizek
Committer date (UTC): 2026-07-28 10:45
Parent(s): 300f0b626b3edbbc93c6d35d80ad5f116bbcec38
Signing key: 99DC5E4DB05F6BE2
Tree: a1df4a571082e82b21ac8cda4b276c2fa68805e4
File Lines added Lines deleted
tests/misc/normal.c 100 0
File tests/misc/normal.c changed (mode: 100644) (index a7200fe89..efe0eba6c)
19 19 #include "../../src/utils/path.h" #include "../../src/utils/path.h"
20 20 #include "../../src/utils/str.h" #include "../../src/utils/str.h"
21 21 #include "../../src/filelist.h" #include "../../src/filelist.h"
22 #include "../../src/filtering.h"
22 23 #include "../../src/flist_sel.h" #include "../../src/flist_sel.h"
23 24 #include "../../src/fops_common.h" #include "../../src/fops_common.h"
24 25 #include "../../src/registers.h" #include "../../src/registers.h"
 
26 27
27 28 #include "utils.h" #include "utils.h"
28 29
30 static void check_filters(int dot, const char local[], const char name_auto[],
31 const char name_manual[]);
32
29 33 static char cwd[PATH_MAX + 1]; static char cwd[PATH_MAX + 1];
30 34
31 35 SETUP_ONCE() SETUP_ONCE()
 
... ... TEST(selection_is_primary)
274 278 regs_reset(); regs_reset();
275 279 } }
276 280
281 TEST(saving_and_restoring_filters)
282 {
283 filters_view_reset(curr_view);
284 dot_filter_set(curr_view, /*visible=*/0);
285 set_local_filter(curr_view, "local-filter");
286 assert_success(filter_append(&curr_view->auto_filter, "auto"));
287 assert_success(replace_matcher(&curr_view->manual_filter, "manual"));
288
289 check_filters(1, "local-filter", "^auto$", "manual");
290
291 /* Remove all filters. */
292 (void)vle_keys_exec_timed_out(L"zR");
293 check_filters(0, "", "", "");
294
295 /* Restore all filters. */
296 (void)vle_keys_exec_timed_out(L"zM");
297 check_filters(1, "local-filter", "^auto$", "manual");
298
299 /* Remove only name filters. */
300 (void)vle_keys_exec_timed_out(L"zO");
301 check_filters(1, "local-filter", "", "");
302
303 /* Additionally remove local filter. */
304 (void)vle_keys_exec_timed_out(L"zr");
305 check_filters(1, "", "", "");
306
307 /* Restore all filters. */
308 (void)vle_keys_exec_timed_out(L"zM");
309 check_filters(1, "local-filter", "^auto$", "manual");
310 }
311
312 TEST(controlling_dot_filter)
313 {
314 filters_view_reset(curr_view);
315 dot_filter_set(curr_view, /*visible=*/0);
316 set_local_filter(curr_view, "local-filter");
317 assert_success(filter_append(&curr_view->auto_filter, "auto"));
318 assert_success(replace_matcher(&curr_view->manual_filter, "manual"));
319
320 check_filters(1, "local-filter", "^auto$", "manual");
321
322 /* Show dot files. */
323 (void)vle_keys_exec_timed_out(L"zo");
324 check_filters(0, "local-filter", "^auto$", "manual");
325 (void)vle_keys_exec_timed_out(L"zo");
326 check_filters(0, "local-filter", "^auto$", "manual");
327
328 /* Hide dot files. */
329 (void)vle_keys_exec_timed_out(L"zm");
330 check_filters(1, "local-filter", "^auto$", "manual");
331 (void)vle_keys_exec_timed_out(L"zm");
332 check_filters(1, "local-filter", "^auto$", "manual");
333
334 /* Toggle dot files. */
335 (void)vle_keys_exec_timed_out(L"za");
336 check_filters(0, "local-filter", "^auto$", "manual");
337 (void)vle_keys_exec_timed_out(L"za");
338 check_filters(1, "local-filter", "^auto$", "manual");
339 }
340
277 341 TEST(yy_one_file) TEST(yy_one_file)
278 342 { {
279 343 regs_init(); regs_init();
 
... ... TEST(al_rl, IF(not_windows), REPEAT(2))
542 606 regs_reset(); regs_reset();
543 607 } }
544 608
609 static void
610 check_filters(int dot, const char local[], const char name_auto[],
611 const char name_manual[])
612 {
613 if(dot)
614 {
615 assert_true(curr_view->hide_dot);
616 }
617 else
618 {
619 assert_false(curr_view->hide_dot);
620 }
621
622 assert_string_equal(local, local_filter_get(curr_view));
623
624 assert_string_equal(name_auto, curr_view->auto_filter.raw);
625 if(name_auto[0] == '\0')
626 {
627 assert_true(filter_is_empty(&curr_view->auto_filter));
628 }
629 else
630 {
631 assert_false(filter_is_empty(&curr_view->auto_filter));
632 }
633
634 assert_string_equal(name_manual, matcher_get_expr(curr_view->manual_filter));
635 if(name_manual[0] == '\0')
636 {
637 assert_true(matcher_is_empty(curr_view->manual_filter));
638 }
639 else
640 {
641 assert_false(matcher_is_empty(curr_view->manual_filter));
642 }
643 }
644
545 645 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
546 646 /* vim: set cinoptions+=t0 filetype=c : */ /* 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