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 / utils / remove_last_path_component.c (9d9d924195adadaa0a4d27ce89d6ca3c6b77217b) (1,472B) (mode 100644) [raw]
#include <stic.h>

#include <test-utils.h>

#include "../../src/compat/fs_limits.h"
#include "../../src/utils/path.h"

TEST(empty_path)
{
	char path[PATH_MAX + 1] = "";
	remove_last_path_component(path);
	assert_string_equal("", path);
}

TEST(root_path)
{
	/* XXX: is this behaviour we want for root? */
	char path[PATH_MAX + 1] = "/";
	remove_last_path_component(path);
	assert_string_equal("", path);
}

TEST(dir_in_root)
{
	char path[PATH_MAX + 1] = "/bin";
	remove_last_path_component(path);
	assert_string_equal("/", path);
}

TEST(path_does_not_end_with_slash)
{
	char path[PATH_MAX + 1] = "/a/b/c";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(path_ends_with_slash)
{
	char path[PATH_MAX + 1] = "/a/b/c/";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(path_ends_with_multiple_slashes)
{
	char path[PATH_MAX + 1] = "/a/b/c///";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(can_remove_path_completely)
{
	char path[PATH_MAX + 1] = "name";

	remove_last_path_component(path);
	assert_true(path[0] == '\0');
}

TEST(can_remove_path_completely_on_windows, IF(windows))
{
	char path[PATH_MAX + 1] = "c:/a";

	remove_last_path_component(path);
	assert_false(path[0] == '\0');

	remove_last_path_component(path);
	assert_true(path[0] == '\0');
}

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