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 / get_last_path_component.c (5c20b6b37c7a7e9c8a10b9681ca841284a234513) (2,408B) (mode 100644) [raw]
#include <stic.h>

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

TEST(empty_path_ok)
{
	const char *const path = "";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path, last);
	assert_true(path == last);
}

TEST(no_slashes_ok)
{
	const char *const path = "path_without_slashes";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path, last);
	assert_true(path == last);
}

TEST(path_does_not_end_with_slash_ok)
{
	const char *const path = "/no/slashhere";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path + 4, last);
	assert_true(path + 4 == last);
}

TEST(path_ends_with_slash_ok)
{
	const char *const path = "/slash/here/";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path + 7, last);
	assert_true(path + 7 == last);
}

TEST(path_ends_with_multiple_slashes_ok)
{
	const char *const path = "/slash/here/////";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path + 7, last);
	assert_true(path + 7 == last);
}

TEST(path_has_separators_of_multiple_slashes_ok)
{
	const char *const path = "/slashes///here";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path + 11, last);
	assert_true(path + 11 == last);
}

TEST(one_element_ok)
{
	const char *const path = "/slashes";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path + 1, last);
	assert_true(path + 1 == last);
}

TEST(root_ok)
{
	const char *const path = "/";
	const char *const last = get_last_path_component(path);
	assert_string_equal(path, last);
	assert_true(path == last);
}

TEST(rel_single_no_trailing_slash)
{
	assert_string_equal("c", get_last_path_component("c"));
	assert_string_equal("cc", get_last_path_component("cc"));
}

TEST(rel_single_trailing_slash)
{
	assert_string_equal("c/", get_last_path_component("c/"));
	assert_string_equal("cc/", get_last_path_component("cc/"));
}

TEST(rel_many_no_trailing_slash)
{
	assert_string_equal("c", get_last_path_component("a/b/c"));
	assert_string_equal("cc", get_last_path_component("a/b/cc"));
}

TEST(rel_many_trailing_slash)
{
	assert_string_equal("c/", get_last_path_component("a/b/c/"));
	assert_string_equal("cc/", get_last_path_component("a/b/cc/"));
}

/* 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