File: visual.c

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (229 lines) | stat: -rw-r--r-- 6,058 bytes parent folder | download | duplicates (2)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <stic.h>

#include <unistd.h> /* chdir() */

#include <limits.h> /* INT_MIN */
#include <string.h> /* memset() */

#include <test-utils.h>

#include "../../src/cfg/config.h"
#include "../../src/compat/fs_limits.h"
#include "../../src/engine/keys.h"
#include "../../src/modes/modes.h"
#include "../../src/modes/visual.h"
#include "../../src/modes/wk.h"
#include "../../src/ui/statusbar.h"
#include "../../src/ui/ui.h"
#include "../../src/utils/fs.h"
#include "../../src/utils/str.h"
#include "../../src/filelist.h"
#include "../../src/flist_pos.h"

#include "utils.h"

static char cwd[PATH_MAX + 1];

SETUP_ONCE()
{
	assert_non_null(get_cwd(cwd, sizeof(cwd)));
	curr_view = &lwin;
	other_view = &rwin;
}

SETUP()
{
	view_setup(&lwin);
	modes_init();
	opt_handlers_setup();
}

TEARDOWN()
{
	(void)vle_keys_exec_timed_out(WK_C_c);
	view_teardown(&lwin);
	vle_keys_reset();
	opt_handlers_teardown();
}

TEST(v_after_av_drops_selection_and_doesnt_stash_it)
{
	make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), TEST_DATA_PATH,
			"existing-files", cwd);
	populate_dir_list(&lwin, /*reload=*/0);

	assert_int_equal(3, lwin.list_rows);

	/* Select first file. */
	(void)vle_keys_exec_timed_out(WK_t);
	/* Select second file. */
	(void)vle_keys_exec_timed_out(WK_j WK_t);

	/* Enter visual mode with amend at the last file. */
	(void)vle_keys_exec_timed_out(WK_j WK_a WK_v);
	/* Switch to regular visual mode. */
	(void)vle_keys_exec_timed_out(WK_v);

	assert_false(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_true(lwin.dir_entry[2].selected);

	/* Go up and then back down. */
	(void)vle_keys_exec_timed_out(WK_g WK_g);
	(void)vle_keys_exec_timed_out(WK_G);

	/* Temporarily including previously selected entries shouldn't fixate their
	 * selection. */
	assert_false(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_true(lwin.dir_entry[2].selected);

	/* Leave visual mode rejecting visual selection. */
	(void)vle_keys_exec_timed_out(WK_C_c);

	assert_false(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_false(lwin.dir_entry[2].selected);

	/* Re-select initially selected (tagged) files. */
	(void)vle_keys_exec_timed_out(WK_g WK_s);

	/* Stashed selection hasn't been changed by visual mode. */
	assert_true(lwin.dir_entry[0].selected);
	assert_true(lwin.dir_entry[1].selected);
	assert_false(lwin.dir_entry[2].selected);
}

TEST(modvis_update_after_av_and_cursor_movements)
{
	make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), TEST_DATA_PATH,
			"existing-files", cwd);
	populate_dir_list(&lwin, /*reload=*/0);

	assert_int_equal(3, lwin.list_rows);

	/* Select first file. */
	(void)vle_keys_exec_timed_out(WK_t);

	/* Enter visual mode with amend at the last file. */
	(void)vle_keys_exec_timed_out(WK_j WK_j WK_a WK_v);

	modvis_update();

	/* Initially selected (tagged) file is not dropped. */
	assert_true(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_true(lwin.dir_entry[2].selected);

	/* Interaction with selected files doesn't change visual selection. */

	fpos_set_pos(&lwin, 0);
	modvis_update();

	assert_true(lwin.dir_entry[0].selected);
	assert_true(lwin.dir_entry[1].selected);
	assert_true(lwin.dir_entry[2].selected);

	fpos_set_pos(&lwin, 2);
	modvis_update();

	assert_true(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_true(lwin.dir_entry[2].selected);

	/* Leave visual mode rejecting visual selection. */
	(void)vle_keys_exec_timed_out(WK_C_c);

	/* Selection of initially selected (tagged) files hasn't been changed by
	 * visual mode. */
	assert_true(lwin.dir_entry[0].selected);
	assert_false(lwin.dir_entry[1].selected);
	assert_false(lwin.dir_entry[2].selected);
}

TEST(lb_rb_S)
{
	/* Load file list. */
	make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), TEST_DATA_PATH,
			"existing-files", cwd);
	populate_dir_list(&lwin, /*reload=*/0);

	/* Make a selection. */
	lwin.dir_entry[0].selected = 1;

	/* More corner cases are tested in the normal mode, both modes use the same
	 * underlying implementation. */

	lwin.list_pos = 0;
	(void)vle_keys_exec_timed_out(WK_a WK_v WK_LB WK_S);
	assert_int_equal(0, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_RB WK_S);
	assert_int_equal(0, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_C_c);

	lwin.list_pos = 1;
	(void)vle_keys_exec_timed_out(WK_a WK_v WK_LB WK_S);
	assert_int_equal(0, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_RB WK_S);
	assert_int_equal(1, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_C_c);

	lwin.list_pos = 2;
	(void)vle_keys_exec_timed_out(WK_a WK_v WK_LB WK_S);
	assert_int_equal(0, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_RB WK_S);
	assert_int_equal(1, lwin.list_pos);
	(void)vle_keys_exec_timed_out(WK_C_c);
}

TEST(cl, IF(not_windows))
{
	conf_setup();
	undo_setup();

	chdir(SANDBOX_PATH);

	assert_success(make_symlink("target", "symlink"));

	create_executable("script");
	make_file("script",
			"#!/bin/sh\n"
			"sed 's/get//' < $2 > $2_out\n"
			"mv $2_out $2\n");

	update_string(&cfg.shell, "/bin/sh");
	stats_update_shell_type(cfg.shell);

	curr_stats.exec_env_type = EET_LINUX_NATIVE;
	update_string(&cfg.vi_command, "./script");

	make_abs_path(lwin.curr_dir, sizeof(lwin.curr_dir), SANDBOX_PATH, "", cwd);
	populate_dir_list(&lwin, /*reload=*/0);

	ui_sb_msg("");

	/* Move to "symlink" file. */
	(void)vle_keys_exec_timed_out(WK_j);
	/* Enter visual mode. */
	(void)vle_keys_exec_timed_out(WK_v);
	/* Change link target. */
	(void)vle_keys_exec_timed_out(WK_c WK_l);

	assert_string_equal("1 link retargeted", ui_sb_last());

	chdir(cwd);

	char target[PATH_MAX + 1];
	assert_success(get_link_target(SANDBOX_PATH "/symlink", target,
				sizeof(target)));
	assert_string_equal("tar", target);

	remove_file(SANDBOX_PATH "/symlink");
	remove_file(SANDBOX_PATH "/script");

	undo_teardown();
	conf_teardown();
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */