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.
<root> / tests / commands / cds.c (67a17918d5840a06af0e3906787776ee489a48b1) (2,684B) (mode 100644) [raw]
#include <stic.h>

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

#include <string.h> /* strcpy() */

#include <test-utils.h>

#include "../../src/compat/fs_limits.h"
#include "../../src/ui/ui.h"
#include "../../src/utils/fs.h"
#include "../../src/cmd_core.h"

static char sandbox[PATH_MAX + 1];
static char test_data[PATH_MAX + 1];

SETUP()
{
	view_setup(&lwin);
	view_setup(&rwin);

	curr_view = &lwin;
	other_view = &rwin;

	cmds_init();

	conf_setup();
}

TEARDOWN()
{
	view_teardown(&lwin);
	view_teardown(&rwin);

	vle_cmds_reset();

	conf_teardown();
}

SETUP_ONCE()
{
	char cwd[PATH_MAX + 1];

	assert_non_null(get_cwd(cwd, sizeof(cwd)));

	make_abs_path(sandbox, sizeof(sandbox), SANDBOX_PATH, "", cwd);
	make_abs_path(test_data, sizeof(test_data), TEST_DATA_PATH, "", cwd);
}

TEST(cds_does_the_replacement)
{
	char path[PATH_MAX + 1];
	snprintf(path, sizeof(path), "%s/syntax-highlight", test_data);
	assert_success(chdir(path));
	strcpy(lwin.curr_dir, path);

	assert_success(cmds_dispatch("cds syntax-highlight rename", &lwin,
				CIT_COMMAND));

	snprintf(path, sizeof(path), "%s/rename", test_data);
	assert_string_equal(path, lwin.curr_dir);
}

TEST(cds_aborts_on_broken_)
{
	char dst[PATH_MAX + 1];
	snprintf(dst, sizeof(dst), "%s/rename", test_data);

	assert_success(chdir(dst));

	strcpy(lwin.curr_dir, dst);

	assert_failure(cmds_dispatch("cds/rename/read/t", &lwin, CIT_COMMAND));

	assert_string_equal(dst, lwin.curr_dir);
}

TEST(cds_acts_like_substitute)
{
	char path[PATH_MAX + 1];
	snprintf(path, sizeof(path), "%s/syntax-highlight", test_data);
	assert_success(chdir(path));
	strcpy(lwin.curr_dir, path);

	assert_success(cmds_dispatch("cds/SYNtax-?hi[a-z]*/rename/i", &lwin,
				CIT_COMMAND));

	snprintf(path, sizeof(path), "%s/rename", test_data);
	assert_string_equal(path, lwin.curr_dir);
}

TEST(cds_can_change_path_of_both_panes)
{
	char path[PATH_MAX + 1];
	snprintf(path, sizeof(path), "%s/syntax-highlight", test_data);
	assert_success(chdir(path));
	strcpy(lwin.curr_dir, path);

	assert_success(cmds_dispatch("cds! syntax-highlight rename", &lwin,
				CIT_COMMAND));

	snprintf(path, sizeof(path), "%s/rename", test_data);
	assert_string_equal(path, lwin.curr_dir);
	assert_string_equal(path, rwin.curr_dir);
}

TEST(cds_is_noop_when_pattern_not_found)
{
	assert_success(chdir(test_data));

	strcpy(lwin.curr_dir, test_data);
	strcpy(rwin.curr_dir, sandbox);

	assert_failure(cmds_dispatch("cds asdlfkjasdlkfj rename", &lwin,
				CIT_COMMAND));

	assert_string_equal(test_data, lwin.curr_dir);
	assert_string_equal(sandbox, rwin.curr_dir);
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 : */
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